From 3b6f29a2bf0a4b7e7bec60240cfa7ea1f7726f57 Mon Sep 17 00:00:00 2001 From: ClementTsang Date: Thu, 14 May 2026 04:09:18 -0400 Subject: [PATCH] move cpu and memory settings over --- CHANGELOG.md | 2 + docs/content/configuration/config-file/cpu.md | 27 ++++++++++++ .../configuration/config-file/flags.md | 6 +-- .../configuration/config-file/memory-graph.md | 8 ++-- src/options.rs | 42 +++++++++++++++---- src/options/config/cpu.rs | 9 ++++ src/options/config/flags.rs | 14 +++---- src/options/config/memory_graph.rs | 6 +++ tests/integration/valid_config_tests.rs | 11 +++++ .../valid_configs/deprecated/cpu_memory.toml | 8 ++++ tests/valid_configs/newer_cpu_memory.toml | 10 +++++ 11 files changed, 122 insertions(+), 21 deletions(-) create mode 100644 tests/valid_configs/deprecated/cpu_memory.toml create mode 100644 tests/valid_configs/newer_cpu_memory.toml diff --git a/CHANGELOG.md b/CHANGELOG.md index bcbd916d..61b099c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,8 @@ That said, these are more guidelines rather than hard rules, though the project - [#2062](https://github.com/ClementTsang/bottom/pull/2062): Rename `[network]` to `[network_graph]` in the config file; `[network]` remains valid as an alias. - [#2062](https://github.com/ClementTsang/bottom/pull/2062): Move network and memory graph config file options from `[flags]` to be under `[network_graph]` and `[memory_graph]`. - [#2063](https://github.com/ClementTsang/bottom/pull/2063): Move process config file options from `[flags]` to be under `[processes]`. +- [](): Move CPU config file options from `[flags]` to be under `[cpu]`. +- [](): Move memory config file options from `[flags]` to be under `[memory_graph]`. ### Other diff --git a/docs/content/configuration/config-file/cpu.md b/docs/content/configuration/config-file/cpu.md index 10223c36..46f8629d 100644 --- a/docs/content/configuration/config-file/cpu.md +++ b/docs/content/configuration/config-file/cpu.md @@ -18,3 +18,30 @@ You can configure whether CPU usage values are shown with a decimal place by set [cpu] show_decimal = true ``` + +## Hide Average CPU + +You can hide the average CPU entry by setting `cpu.hide_avg_cpu`. Defaults to `false`. + +```toml +[cpu] +hide_avg_cpu = true +``` + +## Left Legend + +You can place the CPU chart legend on the left side by setting `cpu.left_legend`. Defaults to `false`. + +```toml +[cpu] +left_legend = true +``` + +## Average CPU Row + +In basic mode, you can give the average CPU entry a dedicated row by setting `cpu.average_cpu_row`. Defaults to `false`. + +```toml +[cpu] +average_cpu_row = true +``` diff --git a/docs/content/configuration/config-file/flags.md b/docs/content/configuration/config-file/flags.md index 94b191ec..96dd139c 100644 --- a/docs/content/configuration/config-file/flags.md +++ b/docs/content/configuration/config-file/flags.md @@ -35,7 +35,7 @@ each time: | `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. | -| `enable_cache_memory` | Boolean | Enable cache and buffer memory stats (not available on Windows). | +| `enable_cache_memory` | Boolean | DEPRECATED - use `memory_graph.cache_memory` instead. | | `process_memory_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. | @@ -52,11 +52,11 @@ 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 | DEPRECATED - use `cpu.average_cpu_row` instead. | | `tree_collapse` | Boolean | Collapse process tree by default. | | `autohide_time` | Boolean | Temporarily shows the time scale in graphs. | | `table_gap` | String (one of ["none", "space", "line"]) | Controls the gap between table headers and data rows. Defaults to "space". | | `disable_keys` | Boolean | Disables keyboard shortcuts, including the ones that stop bottom. | | `no_write` | Boolean | Disables writing to the config file. | | `hide_k_threads` | Boolean | Hide kernel threads from being shown. | -| `free_arc` | Boolean | Subtract freeable ARC from memory usage. | +| `free_arc` | Boolean | DEPRECATED - use `memory_graph.free_arc` instead. | diff --git a/docs/content/configuration/config-file/memory-graph.md b/docs/content/configuration/config-file/memory-graph.md index ec599da4..03f3349f 100644 --- a/docs/content/configuration/config-file/memory-graph.md +++ b/docs/content/configuration/config-file/memory-graph.md @@ -4,6 +4,8 @@ If you want to change some of the default behaviour of the memory graph widget, you can configure some things in the config file. -| Field | Type | Functionality | -| ----------------- | ------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------- | -| `legend_position` | 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. | +| Field | Type | Functionality | +| ----------------- | ------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------- | +| `legend_position` | 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. | +| `cache_memory` | Boolean | Whether to collect and display cache and buffer memory. Not available on Windows. | +| `free_arc` | Boolean | Whether to subtract freeable ARC from memory usage. | diff --git a/src/options.rs b/src/options.rs index 11312bdd..7022c7b9 100644 --- a/src/options.rs +++ b/src/options.rs @@ -276,7 +276,12 @@ pub(crate) fn init_app(args: BottomArgs, config: Config) -> Result<(App, BottomL let use_basic_mode = is_flag_enabled!(basic, args.general, config); let expanded = is_flag_enabled!(expanded, args.general, config); #[cfg(feature = "zfs")] - let free_arc = is_flag_enabled!(free_arc, args.memory, config); + let free_arc = enabled_option_with_deprecated!( + args.memory.free_arc, + config, + memory_graph.free_arc, + flags.free_arc, + ); // For processes let is_grouped = enabled_option_with_deprecated!( @@ -402,7 +407,12 @@ pub(crate) fn init_app(args: BottomArgs, config: Config) -> Result<(App, BottomL show_average_cpu: get_show_average_cpu(args, config), show_cpu_decimal: config_or!(config, cpu.show_decimal, false), use_dot: is_flag_enabled!(dot_marker, args.general, config), - cpu_left_legend: is_flag_enabled!(cpu_left_legend, args.cpu, config), + cpu_left_legend: enabled_option_with_deprecated!( + args.cpu.cpu_left_legend, + config, + cpu.left_legend, + flags.cpu_left_legend, + ), use_current_cpu_total: enabled_option_with_deprecated!( args.process.current_usage, config, @@ -445,7 +455,12 @@ pub(crate) fn init_app(args: BottomArgs, config: Config) -> Result<(App, BottomL network_use_binary_prefix, network_show_packets, retention_ms, - dedicated_average_row: config_or!(config, flags.average_cpu_row, false), + dedicated_average_row: enabled_option_with_deprecated!( + false, + config, + cpu.average_cpu_row, + flags.average_cpu_row, + ), default_tree_collapse: is_default_tree_collapsed, #[cfg(feature = "zfs")] free_arc, @@ -716,7 +731,12 @@ pub(crate) fn init_app(args: BottomArgs, config: Config) -> Result<(App, BottomL fn get_widget_layout( args: &BottomArgs, config: &Config, ) -> OptionResult<(BottomLayout, u64, Option)> { - let cpu_left_legend = is_flag_enabled!(cpu_left_legend, args.cpu, config); + let cpu_left_legend = enabled_option_with_deprecated!( + args.cpu.cpu_left_legend, + config, + cpu.left_legend, + flags.cpu_left_legend, + ); let (default_widget_type, mut default_widget_count) = get_default_widget_and_count(args, config)?; @@ -903,9 +923,12 @@ fn get_temperature(args: &BottomArgs, config: &Config) -> OptionResult bool { if args.cpu.hide_avg_cpu { return false; + } else if let Some(cpu) = &config.cpu { + return !cpu.hide_avg_cpu.unwrap_or(false); } else if let Some(flags) = &config.flags { - if let Some(avg_cpu) = flags.hide_avg_cpu { - return !avg_cpu; + if let Some(hide) = flags.hide_avg_cpu { + deprecated_warning("hide_avg_cpu", "cpu.hide_avg_cpu"); + return !hide; } } @@ -1057,7 +1080,12 @@ fn get_enable_gpu(_: &BottomArgs, _: &Config) -> bool { #[cfg(not(target_os = "windows"))] fn get_enable_cache_memory(args: &BottomArgs, config: &Config) -> bool { - is_flag_enabled!(enable_cache_memory, args.memory, config) + enabled_option_with_deprecated!( + args.memory.enable_cache_memory, + config, + memory_graph.cache_memory, + flags.enable_cache_memory, + ) } #[cfg(target_os = "windows")] diff --git a/src/options/config/cpu.rs b/src/options/config/cpu.rs index 58995281..2e3db649 100644 --- a/src/options/config/cpu.rs +++ b/src/options/config/cpu.rs @@ -23,6 +23,15 @@ pub(crate) struct CpuConfig { /// Whether to show a decimal place for CPU usage values. pub(crate) show_decimal: Option, + + /// Whether to hide the average CPU entry. + pub(crate) hide_avg_cpu: Option, + + /// Whether to put the CPU chart legend on the left side. + pub(crate) left_legend: Option, + + /// Whether to give the average CPU entry a dedicated row in basic mode. + pub(crate) average_cpu_row: Option, } #[cfg(test)] diff --git a/src/options/config/flags.rs b/src/options/config/flags.rs index 8ccbfc01..cafaf54c 100644 --- a/src/options/config/flags.rs +++ b/src/options/config/flags.rs @@ -27,11 +27,9 @@ impl TableGap { #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] #[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub(crate) struct GeneralConfig { - pub(crate) hide_avg_cpu: Option, pub(crate) dot_marker: Option, pub(crate) temperature_type: Option, pub(crate) rate: Option, - pub(crate) cpu_left_legend: Option, pub(crate) basic: Option, pub(crate) default_time_value: Option, pub(crate) time_delta: Option, @@ -50,16 +48,16 @@ pub(crate) struct GeneralConfig { pub(crate) show_table_scroll_position: Option, pub(crate) show_table_scroll_bar: Option, pub(crate) read_only: Option, - // #[cfg(feature = "zfs")] - pub(crate) free_arc: Option, pub(crate) disable_gpu: Option, - // FIXME: This makes no sense outside of basic mode, add a basic mode config section. - // FIXME: This also should be moved to CPU-specific... same with all the other entries. - pub(crate) average_cpu_row: Option, - pub(crate) enable_cache_memory: Option, pub(crate) retention: Option, // FIXME: Deprecate these in the future. + pub(crate) hide_avg_cpu: Option, + pub(crate) cpu_left_legend: Option, + pub(crate) average_cpu_row: Option, + pub(crate) enable_cache_memory: Option, + // #[cfg(feature = "zfs")] + pub(crate) free_arc: Option, pub(crate) network_use_bytes: Option, pub(crate) network_use_log: Option, pub(crate) network_use_binary_prefix: Option, diff --git a/src/options/config/memory_graph.rs b/src/options/config/memory_graph.rs index e751aac8..ccae194f 100644 --- a/src/options/config/memory_graph.rs +++ b/src/options/config/memory_graph.rs @@ -11,4 +11,10 @@ pub struct MemoryGraphConfig { // (e.g. table-style, list-style) then we probably need a new system outright. /// Where to place the legend for the memory chart widget. pub(crate) legend_position: Option, + + /// Whether to collect and display cache and buffer memory. Not available on Windows. + pub(crate) cache_memory: Option, + + /// Whether to subtract freeable ARC from memory usage. + pub(crate) free_arc: Option, } diff --git a/tests/integration/valid_config_tests.rs b/tests/integration/valid_config_tests.rs index 3edd848b..e1932794 100644 --- a/tests/integration/valid_config_tests.rs +++ b/tests/integration/valid_config_tests.rs @@ -237,3 +237,14 @@ fn test_deprecated_processes() { fn test_network_alias() { run_and_kill(&["-C", "./tests/valid_configs/network_alias.toml"]); } + +#[test] +fn test_newer_cpu_memory() { + run_and_kill(&["-C", "./tests/valid_configs/newer_cpu_memory.toml"]); +} + +/// This uses deprecated CPU and memory settings - once they are removed, this test file should be moved to invalid configs. +#[test] +fn test_deprecated_cpu_memory() { + run_and_kill(&["-C", "./tests/valid_configs/deprecated/cpu_memory.toml"]); +} diff --git a/tests/valid_configs/deprecated/cpu_memory.toml b/tests/valid_configs/deprecated/cpu_memory.toml new file mode 100644 index 00000000..c4630f93 --- /dev/null +++ b/tests/valid_configs/deprecated/cpu_memory.toml @@ -0,0 +1,8 @@ +# This uses deprecated CPU and memory settings - once they are removed, this test file should be moved to invalid configs. + +[flags] +hide_avg_cpu = true +cpu_left_legend = true +average_cpu_row = true +enable_cache_memory = true +free_arc = true diff --git a/tests/valid_configs/newer_cpu_memory.toml b/tests/valid_configs/newer_cpu_memory.toml new file mode 100644 index 00000000..86af52a2 --- /dev/null +++ b/tests/valid_configs/newer_cpu_memory.toml @@ -0,0 +1,10 @@ +# This uses the newer CPU and memory config location. + +[cpu] +hide_avg_cpu = true +left_legend = true +average_cpu_row = true + +[memory_graph] +cache_memory = true +free_arc = true