bug: fix default_cpu_entry arg not being used and missing from docs (#1543)

This commit is contained in:
Clement Tsang 2024-08-05 22:55:05 +00:00 committed by GitHub
parent 9f7e00497d
commit feb0c6912c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 41 additions and 33 deletions

View file

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Bug Fixes ### Bug Fixes
- [#1541](https://github.com/ClementTsang/bottom/pull/1541): Fix some process details not updating for macOS and Windows. - [#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 ## [0.10.1] - 2024-08-01

View file

@ -48,27 +48,28 @@ see information on these options by running `btm -h`, or run `btm --help` to dis
## CPU Options ## CPU Options
| Option | Behaviour | | Option | Behaviour |
| -------------------- | ------------------------------------------- | | --------------------- | ------------------------------------------------- |
| `--cpu_left_legend` | Puts the CPU chart legend on the left side. | | `--cpu_left_legend` | Puts the CPU chart legend on the left side. |
| `-a, --hide_avg_cpu` | Hides the average CPU usage entry. | | `--default_cpu_entry` | Sets which CPU entry type is selected by default. |
| `-a, --hide_avg_cpu` | Hides the average CPU usage entry. |
## Memory Options ## Memory Options
| Option | Behaviour | | Option | Behaviour |
| ---------------------------- | --------------------------------------------------------- | | ---------------------------- | --------------------------------------------------------- |
| `--enable_cache_memory` | Enable collecting and displaying cache and buffer memory. |
| `--memory_legend <POSITION>` | Where to place the legend for the memory chart widget. | | `--memory_legend <POSITION>` | Where to place the legend for the memory chart widget. |
| `--enable_cache_memory` | Enable collecting and displaying cache and buffer memory. |
## Network Options ## Network Options
| Option | Behaviour | | Option | Behaviour |
| ----------------------------- | ------------------------------------------------------- | | ----------------------------- | ------------------------------------------------------- |
| `--network_legend <POSITION>` | Where to place the legend for the network chart widget. | | `--network_legend <POSITION>` | 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_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. | | `--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 ## Battery Options
@ -84,9 +85,9 @@ see information on these options by running `btm -h`, or run `btm --help` to dis
## Style Options ## Style Options
| Option | Behaviour | | Option | Behaviour |
| ------------------------ | ------------------------------------------ | | ------------------ | ---------------------------------------------------------------- |
| `--theme <COLOR SCHEME>` | Use a color scheme, use `--help` for info. | | `--theme <SCHEME>` | Use a built-in color theme, use '--help' for info on the colors. |
## Other Options ## Other Options

View file

@ -50,4 +50,4 @@ each time:
| `expanded` | Boolean | Expand the default widget upon starting the app. | | `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. | | `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. | | `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. | | `average_cpu_row` | Boolean | Moves the average CPU usage entry to its own row when using basic mode. |

View file

@ -197,6 +197,9 @@ pub(crate) fn init_app(
let is_advanced_kill = !(is_flag_enabled!(disable_advanced_kill, args.process, config)); 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); 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 widget_map = HashMap::new();
let mut cpu_state_map: HashMap<u64, CpuWidgetState> = HashMap::new(); let mut cpu_state_map: HashMap<u64, CpuWidgetState> = HashMap::new();
let mut mem_state_map: HashMap<u64, MemWidgetState> = HashMap::new(); let mut mem_state_map: HashMap<u64, MemWidgetState> = HashMap::new();
@ -269,7 +272,7 @@ pub(crate) fn init_app(
network_unit_type, network_unit_type,
network_use_binary_prefix, network_use_binary_prefix,
retention_ms, retention_ms,
dedicated_average_row: get_dedicated_avg_row(args, config), dedicated_average_row: get_dedicated_avg_row(config),
}; };
let table_config = ProcTableConfig { let table_config = ProcTableConfig {
@ -324,11 +327,7 @@ pub(crate) fn init_app(
widget.widget_id, widget.widget_id,
CpuWidgetState::new( CpuWidgetState::new(
&app_config_fields, &app_config_fields,
config default_cpu_selection,
.cpu
.as_ref()
.map(|cfg| cfg.default)
.unwrap_or_default(),
default_time_value, default_time_value,
autohide_timer, autohide_timer,
&styling, &styling,
@ -678,14 +677,24 @@ fn get_show_average_cpu(args: &BottomArgs, config: &Config) -> bool {
true 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 let conf = config
.flags .flags
.as_ref() .as_ref()
.and_then(|flags| flags.average_cpu_row) .and_then(|flags| flags.average_cpu_row)
.unwrap_or(false); .unwrap_or(false);
// args.cpu.average_cpu_row || conf
conf conf
} }

View file

@ -408,18 +408,6 @@ impl ValueEnum for CpuDefault {
#[derive(Args, Clone, Debug, Default)] #[derive(Args, Clone, Debug, Default)]
#[command(next_help_heading = "CPU Options", rename_all = "snake_case")] #[command(next_help_heading = "CPU Options", rename_all = "snake_case")]
pub struct CpuArgs { pub struct CpuArgs {
#[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,
#[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"? // TODO: Maybe rename this or fix this? Should this apply to all "left legends"?
#[arg( #[arg(
short = 'l', short = 'l',
@ -428,8 +416,17 @@ pub struct CpuArgs {
help = "Puts the CPU chart legend on the left side." help = "Puts the CPU chart legend on the left side."
)] )]
pub cpu_left_legend: bool, 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, #[arg(
long,
help = "Sets which CPU entry type is selected by default.",
value_name = "ENTRY",
value_parser = value_parser!(CpuDefault),
)]
pub default_cpu_entry: Option<CpuDefault>,
#[arg(short = 'a', long, action = ArgAction::SetTrue, help = "Hides the average CPU usage entry.")]
pub hide_avg_cpu: bool,
} }
/// Memory argument/config options. /// Memory argument/config options.