From 60d0117c85e2e2f3d3072f767832a74093c496c1 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Mon, 28 Dec 2020 14:34:32 -0500 Subject: [PATCH] feature: Add process_command to default to the process command (#379) Adds a `process_command` flag and config option to default to showing the full command in the process widget on startup. --- CHANGELOG.md | 4 ++- README.md | 52 ++++++++++++++++----------------- sample_configs/demo_config.toml | 1 - src/app/states.rs | 4 +-- src/clap.rs | 33 +++++++++++++-------- src/constants.rs | 4 +++ src/options.rs | 16 ++++++++++ 7 files changed, 72 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e236ee1c..5db3e343 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Features -- [#333](https://github.com/ClementTsang/bottom/pull/333): Adds an "out of" indicator that can be enabled using `--show_table_scroll_position` to help keep track of scrolled position. +- [#333](https://github.com/ClementTsang/bottom/pull/333): Adds an "out of" indicator that can be enabled using `--show_table_scroll_position` (and its corresponding config option) to help keep track of scrolled position. + +- [#379](https://github.com/ClementTsang/bottom/pull/379): Adds `--process_command` flag and corresponding config option to default to showing a process' command. ## Changes diff --git a/README.md b/README.md index a14d5b47..30081644 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,7 @@ Use `btm --help` for more information. -S, --case_sensitive Enables case sensitivity by default. -c, --celsius Sets the temperature type to Celsius. --color Use a color scheme, use --help for supported values. + --process_command Show processes as their commands by default. -C, --config Sets the location of the config file. -u, --current_usage Sets process CPU% to be based on current CPU%. -t, --default_time_value Default time value for graphs in ms. @@ -531,32 +532,31 @@ The following options can be set under `[flags]` to achieve the same effect as p These are the following supported flag config values, which correspond to the flag of the same name described in [Flags](#flags): -| Field | Type | -| ---------------------------- | ------------------------------------------------------------------------------------- | -| `hide_avg_cpu` | Boolean | -| `dot_marker` | Boolean | -| `left_legend` | Boolean | -| `current_usage` | Boolean | -| `group_processes` | Boolean | -| `case_sensitive` | Boolean | -| `whole_word` | Boolean | -| `regex` | Boolean | -| `show_disabled_data` | Boolean | -| `basic` | Boolean | -| `hide_table_count` | Boolean | -| `use_old_network_legend` | Boolean | -| `battery` | Boolean | -| `rate` | Unsigned Int (represents milliseconds) | -| `default_time_value` | Unsigned Int (represents milliseconds) | -| `time_delta` | Unsigned Int (represents milliseconds) | -| `temperature_type` | String (one of ["k", "f", "c", "kelvin", "fahrenheit", "celsius"]) | -| `default_widget_type` | String (one of ["cpu", "proc", "net", "temp", "mem", "disk"], same as layout options) | -| `default_widget_count` | Unsigned Int (represents which `default_widget_type`) | -| `disable_click` | Boolean | -| `color` | String (one of ["default", "default-light", "gruvbox", "gruvbox-light"]) | -| `mem_as_value` | Boolean | -| `tree` | Boolean | -| `show_table_scroll_position` | Boolean | +| Field | Type | Functionality | +| ---------------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------- | +| `hide_avg_cpu` | Boolean | Hides the average CPU usage. | +| `dot_marker` | Boolean | Uses a dot marker for graphs. | +| `left_legend` | Boolean | Puts the CPU chart legend to the left side. | +| `current_usage` | Boolean | Sets process CPU% to be based on current CPU%. | +| `group_processes` | Boolean | Groups processes with the same name by default. | +| `case_sensitive` | Boolean | Enables case sensitivity by default. | +| `whole_word` | Boolean | Enables whole-word matching by default. | +| `regex` | Boolean | Enables regex by default. | +| `basic` | Boolean | Hides graphs and uses a more basic look. | +| `use_old_network_legend` | Boolean | DEPRECATED - uses the older network legend. | +| `battery` | Boolean | Shows the battery widget. | +| `rate` | Unsigned Int (represents milliseconds) | Sets a refresh rate in ms. | +| `default_time_value` | Unsigned Int (represents milliseconds) | Default time value for graphs in ms. | +| `time_delta` | Unsigned Int (represents milliseconds) | The amount in ms changed upon zooming. | +| `temperature_type` | String (one of ["k", "f", "c", "kelvin", "fahrenheit", "celsius"]) | Sets the temperature unit type. | +| `default_widget_type` | String (one of ["cpu", "proc", "net", "temp", "mem", "disk"], same as layout options) | Sets the default widget type, use --help for more info. | +| `default_widget_count` | Unsigned Int (represents which `default_widget_type`) | Sets the n'th selected widget type as the default. | +| `disable_click` | Boolean | Disables mouse clicks. | +| `color` | String (one of ["default", "default-light", "gruvbox", "gruvbox-light"]) | Use a color scheme, use --help for supported values. | +| `mem_as_value` | Boolean | Defaults to showing process memory usage by value. | +| `tree` | Boolean | Defaults to showing the process widget in tree mode. | +| `show_table_scroll_position` | Boolean | Shows the scroll position tracker in table widgets. | +| `process_command` | Boolean | Show processes as their commands by default. | #### Theming diff --git a/sample_configs/demo_config.toml b/sample_configs/demo_config.toml index f3e035d4..f7fcb6b0 100644 --- a/sample_configs/demo_config.toml +++ b/sample_configs/demo_config.toml @@ -11,7 +11,6 @@ group_processes = false case_sensitive = false whole_word = false regex = true -show_disabled_data = true default_widget_type = "cpu" default_widget_count = 1 diff --git a/src/app/states.rs b/src/app/states.rs index fe32a50d..d30adcc4 100644 --- a/src/app/states.rs +++ b/src/app/states.rs @@ -409,7 +409,7 @@ pub struct ProcWidgetState { impl ProcWidgetState { pub fn init( is_case_sensitive: bool, is_match_whole_word: bool, is_use_regex: bool, is_grouped: bool, - show_memory_as_values: bool, is_tree_mode: bool, + show_memory_as_values: bool, is_tree_mode: bool, is_using_command: bool, ) -> Self { let mut process_search_state = ProcessSearchState::default(); @@ -450,7 +450,7 @@ impl ProcWidgetState { scroll_state: AppScrollWidgetState::default(), process_sorting_type, is_process_sort_descending, - is_using_command: false, + is_using_command, current_column_index: 0, is_sort_open: false, columns, diff --git a/src/clap.rs b/src/clap.rs index 93d3acb8..323f0e5e 100644 --- a/src/clap.rs +++ b/src/clap.rs @@ -81,6 +81,15 @@ custom layouts.\n\n", "\ When searching for a process, enables case sensitivity by default.\n\n", ); + let current_usage = Arg::with_name("current_usage") + .short("u") + .long("current_usage") + .help("Sets process CPU% to be based on current CPU%.") + .long_help( + "\ +Sets process CPU% usage to be based on the current system CPU% usage +rather than total CPU usage.\n\n", + ); // TODO: [DEBUG] Add a proper debugging solution. // let debug = Arg::with_name("debug") // .long("debug") @@ -106,7 +115,7 @@ Disables mouse clicks from interacting with the program.\n\n", Uses a dot marker for graphs as opposed to the default braille marker.\n\n", ); - let group = Arg::with_name("group") + let group = Arg::with_name("group") // FIXME: Rename this to something like "group_process", would be "breaking" though. .short("g") .long("group") .help("Groups processes with the same name by default.") @@ -136,12 +145,13 @@ Hides the spacing between table headers and entries.\n\n", "\ Completely hides the time scaling from being shown.\n\n", ); - let show_table_scroll_position = Arg::with_name("show_table_scroll_position") - .long("show_table_scroll_position") - .help("Shows the scroll position tracker in table widgets") + let process_command = Arg::with_name("process_command") + .long("process_command") + .help("Show processes as their commands by default.") .long_help( "\ - Shows the list scroll position tracker in the widget title for table widgets.\n\n", + Show processes as their commands by default in the process widget. + ", ); let left_legend = Arg::with_name("left_legend") .short("l") @@ -166,14 +176,12 @@ Puts the CPU chart legend to the left side rather than the right side.\n\n", "\ When searching for a process, enables regex by default.\n\n", ); - let current_usage = Arg::with_name("current_usage") - .short("u") - .long("current_usage") - .help("Sets process CPU% to be based on current CPU%.") + let show_table_scroll_position = Arg::with_name("show_table_scroll_position") + .long("show_table_scroll_position") + .help("Shows the scroll position tracker in table widgets.") .long_help( "\ -Sets process CPU% usage to be based on the current system CPU% usage -rather than total CPU usage.\n\n", + Shows the list scroll position tracker in the widget title for table widgets.\n\n", ); let use_old_network_legend = Arg::with_name("use_old_network_legend") .long("use_old_network_legend") @@ -277,7 +285,7 @@ use CPU (3) as the default instead. .long("default_widget_type") .takes_value(true) .value_name("WIDGET TYPE") - .help("Sets which widget type to use as the default widget.") + .help("Sets the default widget type, use --help for more info.") .long_help( "\ Sets which widget type to use as the default widget. @@ -361,6 +369,7 @@ Defaults to showing the process widget in tree mode.\n\n", .arg(basic) .arg(battery) .arg(case_sensitive) + .arg(process_command) .arg(config_location) .arg(color) // .arg(debug) diff --git a/src/constants.rs b/src/constants.rs index 0a6de6b1..8f44e427 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -398,6 +398,10 @@ pub const OLD_CONFIG_TEXT: &str = r##"# This is a default config file for bottom #mem_as_value = false # Show tree mode by default in the processes widget. #tree = false +# Shows an indicator in table widgets tracking where in the list you are. +#show_table_scroll_position = false +# Show processes as their commands by default in the process widget. +#process_command = false # These are all the components that support custom theming. Note that colour support # will depend on terminal support. diff --git a/src/options.rs b/src/options.rs index 9a8de130..8301094a 100644 --- a/src/options.rs +++ b/src/options.rs @@ -150,6 +150,9 @@ pub struct ConfigFlags { #[builder(default, setter(strip_option))] show_table_scroll_position: Option, + + #[builder(default, setter(strip_option))] + pub process_command: Option, } #[derive(Clone, Default, Debug, Deserialize, Serialize)] @@ -254,6 +257,7 @@ pub fn build_app( let show_memory_as_values = get_mem_as_value(matches, config); let is_default_tree = get_is_default_tree(matches, config); + let is_default_command = get_is_default_process_command(matches, config); for row in &widget_layout.rows { for col in &row.children { @@ -322,6 +326,7 @@ pub fn build_app( is_grouped, show_memory_as_values, is_default_tree, + is_default_command, ), ); } @@ -987,3 +992,14 @@ fn get_show_table_scroll_position(matches: &clap::ArgMatches<'static>, config: & } false } + +fn get_is_default_process_command(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { + if matches.is_present("process_command") { + return true; + } else if let Some(flags) = &config.flags { + if let Some(process_command) = flags.process_command { + return process_command; + } + } + false +}