Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 11 additions & 10 deletions docs/content/configuration/command-line-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <POSITION>` | 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 <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_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

Expand All @@ -84,9 +85,9 @@ see information on these options by running `btm -h`, or run `btm --help` to dis

## Style Options

| Option | Behaviour |
| ------------------------ | ------------------------------------------ |
| `--theme <COLOR SCHEME>` | Use a color scheme, use `--help` for info. |
| Option | Behaviour |
| ------------------ | ---------------------------------------------------------------- |
| `--theme <SCHEME>` | Use a built-in color theme, use '--help' for info on the colors. |

## Other Options

Expand Down
2 changes: 1 addition & 1 deletion docs/content/configuration/config-file/flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
| `average_cpu_row` | Boolean | Moves the average CPU usage entry to its own row when using basic mode. |
25 changes: 17 additions & 8 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64, CpuWidgetState> = HashMap::new();
let mut mem_state_map: HashMap<u64, MemWidgetState> = HashMap::new();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down
23 changes: 10 additions & 13 deletions src/options/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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"?
#[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.
Expand Down
Loading