Skip to content

Commit f41eba0

Browse files
PerchunPakfujiapple852
authored andcommitted
feat: allow theming selected rows in hops table (#1735)
1 parent dbd7f2f commit f41eba0

8 files changed

Lines changed: 81 additions & 39 deletions

File tree

crates/trippy-tui/src/config/file.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ pub struct ConfigThemeColors {
291291
pub hops_table_header_text_color: Option<TuiColor>,
292292
pub hops_table_row_active_text_color: Option<TuiColor>,
293293
pub hops_table_row_inactive_text_color: Option<TuiColor>,
294+
pub hops_table_row_selected_bg_color: Option<TuiColor>,
295+
pub hops_table_row_selected_text_color: Option<TuiColor>,
294296
pub hops_chart_selected_color: Option<TuiColor>,
295297
pub hops_chart_unselected_color: Option<TuiColor>,
296298
pub hops_chart_axis_color: Option<TuiColor>,
@@ -331,6 +333,8 @@ impl Default for ConfigThemeColors {
331333
hops_table_header_text_color: Some(theme.hops_table_header_text),
332334
hops_table_row_active_text_color: Some(theme.hops_table_row_active_text),
333335
hops_table_row_inactive_text_color: Some(theme.hops_table_row_inactive_text),
336+
hops_table_row_selected_bg_color: Some(theme.hops_table_row_selected_bg),
337+
hops_table_row_selected_text_color: Some(theme.hops_table_row_selected_text),
334338
hops_chart_selected_color: Some(theme.hops_chart_selected),
335339
hops_chart_unselected_color: Some(theme.hops_chart_unselected),
336340
hops_chart_axis_color: Some(theme.hops_chart_axis),

crates/trippy-tui/src/config/theme.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ pub struct TuiTheme {
2929
pub hops_table_row_active_text: TuiColor,
3030
/// The color of text of inactive rows in the hops table.
3131
pub hops_table_row_inactive_text: TuiColor,
32+
/// The color of background of selected rows in the hops table.
33+
pub hops_table_row_selected_bg: TuiColor,
34+
/// The color of text of selected rows in the hops table.
35+
pub hops_table_row_selected_text: TuiColor,
3236
/// The color of the selected series in the hops chart.
3337
pub hops_chart_selected: TuiColor,
3438
/// The color of the unselected series in the hops chart.
@@ -94,6 +98,8 @@ impl Default for TuiTheme {
9498
hops_table_header_text: TuiColor::Black,
9599
hops_table_row_active_text: TuiColor::Gray,
96100
hops_table_row_inactive_text: TuiColor::DarkGray,
101+
hops_table_row_selected_bg: TuiColor::Gray,
102+
hops_table_row_selected_text: TuiColor::Black,
97103
hops_chart_selected: TuiColor::Green,
98104
hops_chart_unselected: TuiColor::Gray,
99105
hops_chart_axis: TuiColor::DarkGray,
@@ -161,6 +167,14 @@ impl From<(HashMap<TuiThemeItem, TuiColor>, ConfigThemeColors)> for TuiTheme {
161167
.get(&TuiThemeItem::HopsTableRowInactiveTextColor)
162168
.or(cfg.hops_table_row_inactive_text_color.as_ref())
163169
.unwrap_or(&Self::default().hops_table_row_inactive_text),
170+
hops_table_row_selected_bg: *color_map
171+
.get(&TuiThemeItem::HopsTableRowSelectedBgColor)
172+
.or(cfg.hops_table_row_selected_bg_color.as_ref())
173+
.unwrap_or(&Self::default().hops_table_row_selected_bg),
174+
hops_table_row_selected_text: *color_map
175+
.get(&TuiThemeItem::HopsTableRowSelectedTextColor)
176+
.or(cfg.hops_table_row_selected_text_color.as_ref())
177+
.unwrap_or(&Self::default().hops_table_row_selected_text),
164178
hops_chart_selected: *color_map
165179
.get(&TuiThemeItem::HopsChartSelectedColor)
166180
.or(cfg.hops_chart_selected_color.as_ref())
@@ -290,6 +304,10 @@ pub enum TuiThemeItem {
290304
HopsTableRowActiveTextColor,
291305
/// The color of text of inactive rows in the hops table.
292306
HopsTableRowInactiveTextColor,
307+
/// The color of background of selected rows in the hops table.
308+
HopsTableRowSelectedBgColor,
309+
/// The color of text of selected rows in the hops table.
310+
HopsTableRowSelectedTextColor,
293311
/// The color of the selected series in the hops chart.
294312
HopsChartSelectedColor,
295313
/// The color of the unselected series in the hops chart.

crates/trippy-tui/src/frontend/render/settings.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,14 @@ fn format_theme_settings(app: &TuiApp) -> Vec<SettingsItem> {
431431
"hops-table-row-inactive-text-color",
432432
theme::fmt_color(theme.hops_table_row_inactive_text),
433433
),
434+
SettingsItem::new(
435+
"hops-table-row-selected-bg-color",
436+
theme::fmt_color(theme.hops_table_row_selected_bg),
437+
),
438+
SettingsItem::new(
439+
"hops-table-row-selected-text-color",
440+
theme::fmt_color(theme.hops_table_row_selected_text),
441+
),
434442
SettingsItem::new(
435443
"hops-chart-selected-color",
436444
theme::fmt_color(theme.hops_chart_selected),

crates/trippy-tui/src/frontend/render/table.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use itertools::Itertools;
99
use ratatui::Frame;
1010
use ratatui::layout::Rect;
1111
use ratatui::prelude::Line;
12-
use ratatui::style::{Modifier, Style};
12+
use ratatui::style::Style;
1313
use ratatui::widgets::{Block, BorderType, Borders, Cell, Row, Table};
1414
use std::fmt::Write;
1515
use std::net::IpAddr;
@@ -46,7 +46,9 @@ pub fn render(f: &mut Frame<'_>, app: &mut TuiApp, rect: Rect) {
4646
let config = &app.tui_config;
4747
let widths = config.tui_columns.constraints(rect);
4848
let header = render_table_header(app.tui_config.theme, &config.tui_columns);
49-
let selected_style = Style::default().add_modifier(Modifier::REVERSED);
49+
let selected_style = Style::default()
50+
.fg(config.theme.hops_table_row_selected_text)
51+
.bg(config.theme.hops_table_row_selected_bg);
5052
let rows = app
5153
.tracer_data()
5254
.hops_for_flow(app.selected_flow)

crates/trippy-tui/src/frontend/theme.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ pub struct Theme {
2626
pub hops_table_row_active_text: Color,
2727
/// The color of text of inactive rows in the hops table.
2828
pub hops_table_row_inactive_text: Color,
29+
/// The color of background of selected rows in the hops table.
30+
pub hops_table_row_selected_bg: Color,
31+
/// The color of text of selected rows in the hops table.
32+
pub hops_table_row_selected_text: Color,
2933
/// The color of the selected series in the hops chart.
3034
pub hops_chart_selected: Color,
3135
/// The color of the unselected series in the hops chart.
@@ -91,6 +95,8 @@ impl From<TuiTheme> for Theme {
9195
hops_table_header_text: Color::from(value.hops_table_header_text),
9296
hops_table_row_active_text: Color::from(value.hops_table_row_active_text),
9397
hops_table_row_inactive_text: Color::from(value.hops_table_row_inactive_text),
98+
hops_table_row_selected_bg: Color::from(value.hops_table_row_selected_bg),
99+
hops_table_row_selected_text: Color::from(value.hops_table_row_selected_text),
94100
hops_chart_selected: Color::from(value.hops_chart_selected),
95101
hops_chart_unselected: Color::from(value.hops_chart_unselected),
96102
hops_chart_axis: Color::from(value.hops_chart_axis),
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
source: crates/trippy-tui/src/print.rs
33
---
4-
TUIthemecoloritems:bg-color,border-color,text-color,tab-text-color,hops-table-header-bg-color,hops-table-header-text-color,hops-table-row-active-text-color,hops-table-row-inactive-text-color,hops-chart-selected-color,hops-chart-unselected-color,hops-chart-axis-color,frequency-chart-bar-color,frequency-chart-text-color,flows-chart-bar-selected-color,flows-chart-bar-unselected-color,flows-chart-text-current-color,flows-chart-text-non-current-color,samples-chart-color,samples-chart-lost-color,help-dialog-bg-color,help-dialog-text-color,settings-tab-text-color,settings-dialog-bg-color,settings-table-header-text-color,settings-table-header-bg-color,settings-table-row-text-color,map-world-color,map-radius-color,map-selected-color,map-info-panel-border-color,map-info-panel-bg-color,map-info-panel-text-color,info-bar-bg-color,info-bar-text-color
4+
TUIthemecoloritems:bg-color,border-color,text-color,tab-text-color,hops-table-header-bg-color,hops-table-header-text-color,hops-table-row-active-text-color,hops-table-row-inactive-text-color,hops-table-row-selected-bg-color,hops-table-row-selected-text-color,hops-chart-selected-color,hops-chart-unselected-color,hops-chart-axis-color,frequency-chart-bar-color,frequency-chart-text-color,flows-chart-bar-selected-color,flows-chart-bar-unselected-color,flows-chart-text-current-color,flows-chart-text-non-current-color,samples-chart-color,samples-chart-lost-color,help-dialog-bg-color,help-dialog-text-color,settings-tab-text-color,settings-dialog-bg-color,settings-table-header-text-color,settings-table-header-bg-color,settings-table-row-text-color,map-world-color,map-radius-color,map-selected-color,map-info-panel-border-color,map-info-panel-bg-color,map-info-panel-text-color,info-bar-bg-color,info-bar-text-color

docs/src/content/docs/reference/theme.md

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,44 @@ sidebar:
88
The following table lists the default Tui color theme. These can be overridden with the `--tui-theme-colors` command
99
line option or in the `theme-colors` section of the configuration file.
1010

11-
| Item | Description | Default |
12-
| ------------------------------------ | --------------------------------------------------------- | ------------ |
13-
| `bg-color` | The default background color | `Black` |
14-
| `border-color` | The default color of borders | `Gray` |
15-
| `text-color` | The default color of text | `Gray` |
16-
| `tab-text-color` | The color of the text in traces tabs | `Green` |
17-
| `hops-table-header-bg-color` | The background color of the hops table header | `White` |
18-
| `hops-table-header-text-color` | The color of text in the hops table header | `Black` |
19-
| `hops-table-row-active-text-color` | The color of text of active rows in the hops table | `Gray` |
20-
| `hops-table-row-inactive-text-color` | The color of text of inactive rows in the hops table | `DarkGray` |
21-
| `hops-chart-selected-color` | The color of the selected series in the hops chart | `Green` |
22-
| `hops-chart-unselected-color` | The color of the unselected series in the hops chart | `Gray` |
23-
| `hops-chart-axis-color` | The color of the axis in the hops chart | `DarkGray` |
24-
| `frequency-chart-bar-color` | The color of bars in the frequency chart | `Green` |
25-
| `frequency-chart-text-color` | The color of text in the bars of the frequency chart | `Gray` |
26-
| `flows-chart-bar-selected-color` | The color of the selected flow bar in the flows chart | `Green` |
27-
| `flows-chart-bar-unselected-color` | The color of the unselected flow bar in the flows chart | `DarkGray` |
28-
| `flows-chart-text-current-color` | The color of the current flow text in the flows chart | `LightGreen` |
29-
| `flows-chart-text-non-current-color` | The color of the non-current flow text in the flows chart | `White` |
30-
| `samples-chart-color` | The color of the samples chart | `Yellow` |
31-
| `samples-chart-lost-color` | The color of the samples chart for lost probes | `Red` |
32-
| `help-dialog-bg-color` | The background color of the help dialog | `Blue` |
33-
| `help-dialog-text-color` | The color of the text in the help dialog | `Gray` |
34-
| `settings-dialog-bg-color` | The background color of the settings dialog | `blue` |
35-
| `settings-tab-text-color` | The color of the text in settings dialog tabs | `green` |
36-
| `settings-table-header-text-color` | The color of text in the settings table header | `black` |
37-
| `settings-table-header-bg-color` | The background color of the settings table header | `white` |
38-
| `settings-table-row-text-color` | The color of text of rows in the settings table | `gray` |
39-
| `map-world-color` | The color of the map world diagram | `white` |
40-
| `map-radius-color` | The color of the map accuracy radius circle | `yellow` |
41-
| `map-selected-color` | The color of the map selected item box | `green` |
42-
| `map-info-panel-border-color` | The color of border of the map info panel | `gray` |
43-
| `map-info-panel-bg-color` | The background color of the map info panel | `black` |
44-
| `map-info-panel-text-color` | The color of text in the map info panel | `gray` |
45-
| `info-bar-bg-color` | The background color of the information bar | `white` |
46-
| `info-bar-text-color` | The color of text in the information bar | `black` |
11+
| Item | Description | Default |
12+
| ------------------------------------ | ---------------------------------------------------------- | ------------ |
13+
| `bg-color` | The default background color | `Black` |
14+
| `border-color` | The default color of borders | `Gray` |
15+
| `text-color` | The default color of text | `Gray` |
16+
| `tab-text-color` | The color of the text in traces tabs | `Green` |
17+
| `hops-table-header-bg-color` | The background color of the hops table header | `White` |
18+
| `hops-table-header-text-color` | The color of text in the hops table header | `Black` |
19+
| `hops-table-row-active-text-color` | The color of text of active rows in the hops table | `Gray` |
20+
| `hops-table-row-inactive-text-color` | The color of text of inactive rows in the hops table | `DarkGray` |
21+
| `hops-table-row-selected-bg-color` | The color of background of selected rows in the hops table | `Gray` |
22+
| `hops-table-row-selected-text-color` | The color of text of selected rows in the hops table | `Black` |
23+
| `hops-chart-selected-color` | The color of the selected series in the hops chart | `Green` |
24+
| `hops-chart-unselected-color` | The color of the unselected series in the hops chart | `Gray` |
25+
| `hops-chart-axis-color` | The color of the axis in the hops chart | `DarkGray` |
26+
| `frequency-chart-bar-color` | The color of bars in the frequency chart | `Green` |
27+
| `frequency-chart-text-color` | The color of text in the bars of the frequency chart | `Gray` |
28+
| `flows-chart-bar-selected-color` | The color of the selected flow bar in the flows chart | `Green` |
29+
| `flows-chart-bar-unselected-color` | The color of the unselected flow bar in the flows chart | `DarkGray` |
30+
| `flows-chart-text-current-color` | The color of the current flow text in the flows chart | `LightGreen` |
31+
| `flows-chart-text-non-current-color` | The color of the non-current flow text in the flows chart | `White` |
32+
| `samples-chart-color` | The color of the samples chart | `Yellow` |
33+
| `samples-chart-lost-color` | The color of the samples chart for lost probes | `Red` |
34+
| `help-dialog-bg-color` | The background color of the help dialog | `Blue` |
35+
| `help-dialog-text-color` | The color of the text in the help dialog | `Gray` |
36+
| `settings-dialog-bg-color` | The background color of the settings dialog | `blue` |
37+
| `settings-tab-text-color` | The color of the text in settings dialog tabs | `green` |
38+
| `settings-table-header-text-color` | The color of text in the settings table header | `black` |
39+
| `settings-table-header-bg-color` | The background color of the settings table header | `white` |
40+
| `settings-table-row-text-color` | The color of text of rows in the settings table | `gray` |
41+
| `map-world-color` | The color of the map world diagram | `white` |
42+
| `map-radius-color` | The color of the map accuracy radius circle | `yellow` |
43+
| `map-selected-color` | The color of the map selected item box | `green` |
44+
| `map-info-panel-border-color` | The color of border of the map info panel | `gray` |
45+
| `map-info-panel-bg-color` | The background color of the map info panel | `black` |
46+
| `map-info-panel-text-color` | The color of text in the map info panel | `gray` |
47+
| `info-bar-bg-color` | The background color of the information bar | `white` |
48+
| `info-bar-text-color` | The color of text in the information bar | `black` |
4749

4850
The supported [ANSI colors](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors) are:
4951

trippy-config-sample.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ hops-table-header-bg-color = "white"
358358
hops-table-header-text-color = "black"
359359
hops-table-row-active-text-color = "gray"
360360
hops-table-row-inactive-text-color = "darkgray"
361+
hops-table-row-selected-bg-color = "gray"
362+
hops-table-row-selected-text-color = "black"
361363
hops-chart-selected-color = "green"
362364
hops-chart-unselected-color = "gray"
363365
hops-chart-axis-color = "darkgray"

0 commit comments

Comments
 (0)