diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f48e74a7..745183086 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug Fixes - [#1541](https://github.com/ClementTsang/bottom/pull/1541): Fix some process details not updating for macOS and Windows. +- [#1543](https://github.com/ClementTsang/bottom/pull/1543): Fix the `--default_cpu_entry` argument not being checked. ## [0.10.1] - 2024-08-01 diff --git a/docs/content/configuration/command-line-options.md b/docs/content/configuration/command-line-options.md index 033841669..7f7923153 100644 --- a/docs/content/configuration/command-line-options.md +++ b/docs/content/configuration/command-line-options.md @@ -48,27 +48,28 @@ see information on these options by running `btm -h`, or run `btm --help` to dis ## CPU Options -| Option | Behaviour | -| -------------------- | ------------------------------------------- | -| `--cpu_left_legend` | Puts the CPU chart legend on the left side. | -| `-a, --hide_avg_cpu` | Hides the average CPU usage entry. | +| Option | Behaviour | +| --------------------- | ------------------------------------------------- | +| `--cpu_left_legend` | Puts the CPU chart legend on the left side. | +| `--default_cpu_entry` | Sets which CPU entry type is selected by default. | +| `-a, --hide_avg_cpu` | Hides the average CPU usage entry. | ## Memory Options | Option | Behaviour | | ---------------------------- | --------------------------------------------------------- | -| `--enable_cache_memory` | Enable collecting and displaying cache and buffer memory. | | `--memory_legend ` | Where to place the legend for the memory chart widget. | +| `--enable_cache_memory` | Enable collecting and displaying cache and buffer memory. | ## Network Options | Option | Behaviour | | ----------------------------- | ------------------------------------------------------- | | `--network_legend ` | Where to place the legend for the network chart widget. | -| `--network_use_binary_prefix` | Displays the network widget with binary prefixes. | | `--network_use_bytes` | Displays the network widget using bytes. | +| `--network_use_binary_prefix` | Displays the network widget with binary prefixes. | | `--network_use_log` | Displays the network widget with a log scale. | -| `--use_old_network_legend` | (DEPRECATED) Uses a separated network legend. | +| `--use_old_network_legend` | (DEPRECATED) Uses a separate network legend. | ## Battery Options @@ -84,9 +85,9 @@ see information on these options by running `btm -h`, or run `btm --help` to dis ## Style Options -| Option | Behaviour | -| ------------------------ | ------------------------------------------ | -| `--theme ` | Use a color scheme, use `--help` for info. | +| Option | Behaviour | +| ------------------ | ---------------------------------------------------------------- | +| `--theme ` | Use a built-in color theme, use '--help' for info on the colors. | ## Other Options diff --git a/docs/content/configuration/config-file/flags.md b/docs/content/configuration/config-file/flags.md index 8edffda3a..18d3ee2c9 100644 --- a/docs/content/configuration/config-file/flags.md +++ b/docs/content/configuration/config-file/flags.md @@ -50,4 +50,4 @@ each time: | `expanded` | Boolean | Expand the default widget upon starting the app. | | `memory_legend` | String (one of ["none", "top-left", "top", "top-right", "left", "right", "bottom-left", "bottom", "bottom-right"]) | Where to place the legend for the memory widget. | | `network_legend` | String (one of ["none", "top-left", "top", "top-right", "left", "right", "bottom-left", "bottom", "bottom-right"]) | Where to place the legend for the network widget. | -| `average_cpu_row` | Boolean | Moves the average CPU usage entry to its own row when using basic mode. | \ No newline at end of file +| `average_cpu_row` | Boolean | Moves the average CPU usage entry to its own row when using basic mode. | diff --git a/src/options.rs b/src/options.rs index 4d95ce728..24571f1a8 100644 --- a/src/options.rs +++ b/src/options.rs @@ -197,6 +197,9 @@ pub(crate) fn init_app( let is_advanced_kill = !(is_flag_enabled!(disable_advanced_kill, args.process, config)); let process_memory_as_value = is_flag_enabled!(process_memory_as_value, args.process, config); + // For CPU + let default_cpu_selection = get_default_cpu_selection(args, config); + let mut widget_map = HashMap::new(); let mut cpu_state_map: HashMap = HashMap::new(); let mut mem_state_map: HashMap = HashMap::new(); @@ -269,7 +272,7 @@ pub(crate) fn init_app( network_unit_type, network_use_binary_prefix, retention_ms, - dedicated_average_row: get_dedicated_avg_row(args, config), + dedicated_average_row: get_dedicated_avg_row(config), }; let table_config = ProcTableConfig { @@ -324,11 +327,7 @@ pub(crate) fn init_app( widget.widget_id, CpuWidgetState::new( &app_config_fields, - config - .cpu - .as_ref() - .map(|cfg| cfg.default) - .unwrap_or_default(), + default_cpu_selection, default_time_value, autohide_timer, &styling, @@ -678,14 +677,24 @@ fn get_show_average_cpu(args: &BottomArgs, config: &Config) -> bool { true } -fn get_dedicated_avg_row(_args: &BottomArgs, config: &Config) -> bool { +// I hate this too. +fn get_default_cpu_selection(args: &BottomArgs, config: &Config) -> config::cpu::CpuDefault { + match &args.cpu.default_cpu_entry { + Some(default) => match default { + args::CpuDefault::All => config::cpu::CpuDefault::All, + args::CpuDefault::Average => config::cpu::CpuDefault::Average, + }, + None => config.cpu.as_ref().map(|c| c.default).unwrap_or_default(), + } +} + +fn get_dedicated_avg_row(config: &Config) -> bool { let conf = config .flags .as_ref() .and_then(|flags| flags.average_cpu_row) .unwrap_or(false); - // args.cpu.average_cpu_row || conf conf } diff --git a/src/options/args.rs b/src/options/args.rs index c9123e72d..acfd107d0 100644 --- a/src/options/args.rs +++ b/src/options/args.rs @@ -408,28 +408,25 @@ impl ValueEnum for CpuDefault { #[derive(Args, Clone, Debug, Default)] #[command(next_help_heading = "CPU Options", rename_all = "snake_case")] pub struct CpuArgs { + // TODO: Maybe rename this or fix this? Should this apply to all "left legends"? + #[arg( + short = 'l', + long, + action = ArgAction::SetTrue, + help = "Puts the CPU chart legend on the left side." + )] + pub cpu_left_legend: bool, + #[arg( long, help = "Sets which CPU entry type is selected by default.", value_name = "ENTRY", value_parser = value_parser!(CpuDefault), - default_value = "all" )] - pub default_cpu_entry: CpuDefault, + pub default_cpu_entry: Option, #[arg(short = 'a', long, action = ArgAction::SetTrue, help = "Hides the average CPU usage entry.")] pub hide_avg_cpu: bool, - - // TODO: Maybe rename this or fix this? Should this apply to all "left legends"? - #[arg( - short = 'l', - long, - action = ArgAction::SetTrue, - help = "Puts the CPU chart legend on the left side." - )] - pub cpu_left_legend: bool, - // #[arg(short = 'A', long, action = ArgAction::SetTrue, help = "Moves the average CPU usage entry to its own row when using basic mode.")] - // pub average_cpu_row: bool, } /// Memory argument/config options.