From 0ea68de068c983718c80b79cde8e8f8400549b7c Mon Sep 17 00:00:00 2001 From: felipe-heredia Date: Wed, 15 May 2024 16:39:25 -0300 Subject: [PATCH 1/4] feature(agrs): :sparkles: Adds clean mode This commit introduces a clean mode to the application. When passing the argument --clean, the application hides some borders and adopts a cleaner interface with fewer borders. --- src/app.rs | 1 + src/canvas/components/data_table.rs | 1 + src/canvas/components/data_table/draw.rs | 4 +- src/canvas/components/data_table/props.rs | 3 + src/canvas/components/data_table/sortable.rs | 1 + src/canvas/components/time_graph.rs | 13 +++- src/canvas/widgets/cpu_graph.rs | 1 + src/canvas/widgets/mem_graph.rs | 1 + src/canvas/widgets/network_graph.rs | 1 + src/options.rs | 2 + src/options/args.rs | 62 ++++++++++++-------- src/options/config.rs | 1 + src/widgets/cpu_graph.rs | 1 + src/widgets/disk_table.rs | 1 + src/widgets/process_table.rs | 2 + src/widgets/temperature_table.rs | 1 + 16 files changed, 69 insertions(+), 27 deletions(-) diff --git a/src/app.rs b/src/app.rs index 11cd358b7..dd86e0b8d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -52,6 +52,7 @@ pub struct AppConfigFields { pub use_current_cpu_total: bool, pub unnormalized_cpu: bool, pub use_basic_mode: bool, + pub use_clean_mode: bool, pub default_time_value: u64, pub time_interval: u64, pub hide_time: bool, diff --git a/src/canvas/components/data_table.rs b/src/canvas/components/data_table.rs index f4e26f0cf..d04b765be 100644 --- a/src/canvas/components/data_table.rs +++ b/src/canvas/components/data_table.rs @@ -186,6 +186,7 @@ mod test { table_gap: 1, left_to_right: false, is_basic: false, + is_clean: false, show_table_scroll_position: true, show_current_entry_when_unfocused: false, }; diff --git a/src/canvas/components/data_table/draw.rs b/src/canvas/components/data_table/draw.rs index 46304f832..1dda296c5 100644 --- a/src/canvas/components/data_table/draw.rs +++ b/src/canvas/components/data_table/draw.rs @@ -75,7 +75,9 @@ where } }; - if !self.props.is_basic { + if self.props.is_clean { + Block::default().borders(Borders::NONE) + } else if !self.props.is_basic { let block = Block::default() .borders(Borders::ALL) .border_style(border_style); diff --git a/src/canvas/components/data_table/props.rs b/src/canvas/components/data_table/props.rs index 66d3a4f02..f917a1a2d 100644 --- a/src/canvas/components/data_table/props.rs +++ b/src/canvas/components/data_table/props.rs @@ -13,6 +13,9 @@ pub struct DataTableProps { /// Whether this table is a basic table. This affects the borders. pub is_basic: bool, + /// Whether this table is a clean table. This affects the borders. + pub is_clean: bool, + /// Whether to show the table scroll position. pub show_table_scroll_position: bool, diff --git a/src/canvas/components/data_table/sortable.rs b/src/canvas/components/data_table/sortable.rs index 1ece31cc5..801ff2fa3 100644 --- a/src/canvas/components/data_table/sortable.rs +++ b/src/canvas/components/data_table/sortable.rs @@ -410,6 +410,7 @@ mod test { table_gap: 1, left_to_right: false, is_basic: false, + is_clean: false, show_table_scroll_position: true, show_current_entry_when_unfocused: false, }; diff --git a/src/canvas/components/time_graph.rs b/src/canvas/components/time_graph.rs index 361b502e7..b0c18c53a 100644 --- a/src/canvas/components/time_graph.rs +++ b/src/canvas/components/time_graph.rs @@ -47,6 +47,9 @@ pub struct TimeGraph<'a> { /// Whether this graph is expanded. pub is_expanded: bool, + /// Whether this graph is clean. Without borders. + pub is_clean: bool, + /// The title style. pub title_style: Style, @@ -135,9 +138,16 @@ impl<'a> TimeGraph<'a> { // This is some ugly manual loop unswitching. Maybe unnecessary. // TODO: Optimize this step. Cut out unneeded points. let data = graph_data.iter().map(create_dataset).collect(); + + let borders = if self.is_clean { + Borders::RIGHT + } else { + Borders::ALL + }; + let block = Block::default() .title(self.generate_title(draw_loc)) - .borders(Borders::ALL) + .borders(borders) .border_style(self.border_style); f.render_widget( @@ -207,6 +217,7 @@ mod test { graph_style: Style::default().fg(Color::Red), border_style: Style::default().fg(Color::Blue), is_expanded: false, + is_clean: false, title_style: Style::default().fg(Color::Cyan), legend_position: None, legend_constraints: None, diff --git a/src/canvas/widgets/cpu_graph.rs b/src/canvas/widgets/cpu_graph.rs index 85200e982..9bc9b48e0 100644 --- a/src/canvas/widgets/cpu_graph.rs +++ b/src/canvas/widgets/cpu_graph.rs @@ -231,6 +231,7 @@ impl Painter { graph_style: self.colours.graph_style, border_style, title, + is_clean: app_state.app_config_fields.use_clean_mode, is_expanded: app_state.is_expanded, title_style: self.colours.widget_title_style, legend_position: None, diff --git a/src/canvas/widgets/mem_graph.rs b/src/canvas/widgets/mem_graph.rs index 5c814f510..45ffb104f 100644 --- a/src/canvas/widgets/mem_graph.rs +++ b/src/canvas/widgets/mem_graph.rs @@ -131,6 +131,7 @@ impl Painter { graph_style: self.colours.graph_style, border_style, title: " Memory ".into(), + is_clean: app_state.app_config_fields.use_clean_mode, is_expanded: app_state.is_expanded, title_style: self.colours.widget_title_style, legend_position: app_state.app_config_fields.memory_legend_position, diff --git a/src/canvas/widgets/network_graph.rs b/src/canvas/widgets/network_graph.rs index ec7e5fbdf..b0bce4140 100644 --- a/src/canvas/widgets/network_graph.rs +++ b/src/canvas/widgets/network_graph.rs @@ -159,6 +159,7 @@ impl Painter { y_labels: &y_labels, graph_style: self.colours.graph_style, border_style, + is_clean: app_state.app_config_fields.use_clean_mode, title: " Network ".into(), is_expanded: app_state.is_expanded, title_style: self.colours.widget_title_style, diff --git a/src/options.rs b/src/options.rs index 7cf2fbaf9..a6e9e6d67 100644 --- a/src/options.rs +++ b/src/options.rs @@ -75,6 +75,7 @@ pub fn init_app( let use_basic_mode = is_flag_enabled!(basic, matches, config); let expanded = is_flag_enabled!(expanded, matches, config); + let use_clean_mode = is_flag_enabled!(clean, matches, config); // For processes let is_grouped = is_flag_enabled!(group_processes, matches, config); @@ -141,6 +142,7 @@ pub fn init_app( use_current_cpu_total: is_flag_enabled!(current_usage, matches, config), unnormalized_cpu: is_flag_enabled!(unnormalized_cpu, matches, config), use_basic_mode, + use_clean_mode, default_time_value, time_interval: get_time_interval(matches, config, retention_ms) .context("Update 'time_delta' in your config file.")?, diff --git a/src/options/args.rs b/src/options/args.rs index a9d550bbc..efd7abda4 100644 --- a/src/options/args.rs +++ b/src/options/args.rs @@ -72,6 +72,39 @@ fn general_args(cmd: Command) -> Command { .help("Hides graphs and uses a more basic look.") .long_help("Hides graphs and uses a more basic look, largely inspired by htop's design."); + let clean = Arg::new("clean") + .long("clean") + .action(ArgAction::SetTrue) + .help("Hides borders and use a cleaner look.") + .long_help( + "Hides borders and use a cleaner look. Keeping only the separator borders visible.", + ); + + let disable_click = Arg::new("disable_click") + .long("disable_click") + .action(ArgAction::SetTrue) + .help("Disables mouse clicks.") + .long_help("Disables mouse clicks from interacting with the program."); + + let hide_table_gap = Arg::new("hide_table_gap") + .long("hide_table_gap") + .action(ArgAction::SetTrue) + .help("Hides spacing between table headers and entries.") + .long_help("Hides the spacing between table headers and entries."); + + let hide_time = Arg::new("hide_time") + .long("hide_time") + .action(ArgAction::SetTrue) + .help("Hides the time scale.") + .long_help("Completely hides the time scale from being shown."); + + + let show_table_scroll_position = Arg::new("show_table_scroll_position") + .long("show_table_scroll_position") + .action(ArgAction::SetTrue) + .help("Shows the scroll position tracker in table widgets.") + .long_help("Shows the list scroll position tracker in the widget title for table widgets."); + let config_location = Arg::new("config_location") .short('C') .long("config") @@ -155,12 +188,6 @@ fn general_args(cmd: Command) -> Command { "battery", ]); - let disable_click = Arg::new("disable_click") - .long("disable_click") - .action(ArgAction::SetTrue) - .help("Disables mouse clicks.") - .long_help("Disables mouse clicks from interacting with bottom."); - // TODO: Change this to accept a string with the type of marker. let dot_marker = Arg::new("dot_marker") .short('m') @@ -176,16 +203,6 @@ fn general_args(cmd: Command) -> Command { .help("Expand the default widget upon starting the app.") .long_help("Expand the default widget upon starting the app. This flag has no effect in basic mode (--basic)."); - let hide_table_gap = Arg::new("hide_table_gap") - .long("hide_table_gap") - .action(ArgAction::SetTrue) - .help("Hides spacing between table headers and entries."); - - let hide_time = Arg::new("hide_time") - .long("hide_time") - .action(ArgAction::SetTrue) - .help("Hides the time scale from being shown."); - let rate = Arg::new("rate") .short('r') .long("rate") @@ -210,12 +227,6 @@ fn general_args(cmd: Command) -> Command { may result in higher memory usage." ); - let show_table_scroll_position = Arg::new("show_table_scroll_position") - .long("show_table_scroll_position") - .action(ArgAction::SetTrue) - .help("Shows the scroll position tracker in table widgets.") - .long_help("Shows the list scroll position tracker in the widget title for table widgets."); - let time_delta = Arg::new("time_delta") .short('d') .long("time_delta") @@ -231,6 +242,7 @@ fn general_args(cmd: Command) -> Command { cmd.args(args![ autohide_time, basic, + clean, config_location, default_widget_count, default_time_value, @@ -540,11 +552,11 @@ pub fn build_app() -> Command { const TEMPLATE: &str = indoc! { "{name} {version} {author} - + {about} - + {usage-heading} {usage} - + {all-args}" }; const USAGE: &str = "btm [OPTIONS]"; diff --git a/src/options/config.rs b/src/options/config.rs index 5fe29fe24..39dfd6315 100644 --- a/src/options/config.rs +++ b/src/options/config.rs @@ -55,6 +55,7 @@ pub(crate) struct ConfigFlags { pub(crate) whole_word: Option, pub(crate) regex: Option, pub(crate) basic: Option, + pub(crate) clean: Option, pub(crate) default_time_value: Option, pub(crate) time_delta: Option, pub(crate) autohide_time: Option, diff --git a/src/widgets/cpu_graph.rs b/src/widgets/cpu_graph.rs index e90ce6977..aeec1c987 100644 --- a/src/widgets/cpu_graph.rs +++ b/src/widgets/cpu_graph.rs @@ -180,6 +180,7 @@ impl CpuWidgetState { table_gap: config.table_gap, left_to_right: false, is_basic: false, + is_clean: config.use_clean_mode, show_table_scroll_position: false, // TODO: Should this be possible? show_current_entry_when_unfocused: true, }; diff --git a/src/widgets/disk_table.rs b/src/widgets/disk_table.rs index 047c0a143..8044fe728 100644 --- a/src/widgets/disk_table.rs +++ b/src/widgets/disk_table.rs @@ -223,6 +223,7 @@ impl DiskTableWidget { title: Some(" Disks ".into()), table_gap: config.table_gap, left_to_right: true, + is_clean: config.use_clean_mode, is_basic: config.use_basic_mode, show_table_scroll_position: config.show_table_scroll_position, show_current_entry_when_unfocused: false, diff --git a/src/widgets/process_table.rs b/src/widgets/process_table.rs index 49087fb39..c209fad56 100644 --- a/src/widgets/process_table.rs +++ b/src/widgets/process_table.rs @@ -199,6 +199,7 @@ impl ProcWidgetState { table_gap: config.table_gap, left_to_right: true, is_basic: false, + is_clean: false, show_table_scroll_position: false, show_current_entry_when_unfocused: false, }; @@ -216,6 +217,7 @@ impl ProcWidgetState { table_gap: config.table_gap, left_to_right: true, is_basic: config.use_basic_mode, + is_clean: config.use_clean_mode, show_table_scroll_position: config.show_table_scroll_position, show_current_entry_when_unfocused: false, }; diff --git a/src/widgets/temperature_table.rs b/src/widgets/temperature_table.rs index 01a22e38b..9c8556fb2 100644 --- a/src/widgets/temperature_table.rs +++ b/src/widgets/temperature_table.rs @@ -114,6 +114,7 @@ impl TempWidgetState { table_gap: config.table_gap, left_to_right: false, is_basic: config.use_basic_mode, + is_clean: config.use_clean_mode, show_table_scroll_position: config.show_table_scroll_position, show_current_entry_when_unfocused: false, }, From 1585773b06fe1d52c2349f84d109f9a9b347d886 Mon Sep 17 00:00:00 2001 From: felipe-heredia Date: Wed, 15 May 2024 16:42:19 -0300 Subject: [PATCH 2/4] fix: remove blankline --- src/options/args.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/options/args.rs b/src/options/args.rs index efd7abda4..c8221142c 100644 --- a/src/options/args.rs +++ b/src/options/args.rs @@ -98,7 +98,6 @@ fn general_args(cmd: Command) -> Command { .help("Hides the time scale.") .long_help("Completely hides the time scale from being shown."); - let show_table_scroll_position = Arg::new("show_table_scroll_position") .long("show_table_scroll_position") .action(ArgAction::SetTrue) From b26d3e1687511e1af61cbfd117dfda14282b5c3b Mon Sep 17 00:00:00 2001 From: felipe-heredia Date: Wed, 15 May 2024 16:52:19 -0300 Subject: [PATCH 3/4] docs(agrs): Add clean command to command-line-options --- docs/content/configuration/command-line-options.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/content/configuration/command-line-options.md b/docs/content/configuration/command-line-options.md index 9d95fc966..7df9e7d88 100644 --- a/docs/content/configuration/command-line-options.md +++ b/docs/content/configuration/command-line-options.md @@ -9,6 +9,7 @@ see information on these options by running `btm -h`, or run `btm --help` to dis | --------------------------------- | ---------------------------------------------------- | | `--autohide_time` | Temporarily shows the time scale in graphs. | | `-b, --basic` | Hides graphs and uses a more basic look. | +| `--clean` | Hides borders and use a cleaner look. | | `-C, --config ` | Sets the location of the config file. | | `-t, --default_time_value