move cpu and memory settings over

This commit is contained in:
ClementTsang
2026-05-14 04:09:18 -04:00
parent 899914591e
commit 3b6f29a2bf
11 changed files with 122 additions and 21 deletions
+2
View File
@@ -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
@@ -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
```
@@ -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. |
@@ -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. |
+35 -7
View File
@@ -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<BottomWidgetType>)> {
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<Temperatu
fn get_show_average_cpu(args: &BottomArgs, config: &Config) -> 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")]
+9
View File
@@ -23,6 +23,15 @@ pub(crate) struct CpuConfig {
/// Whether to show a decimal place for CPU usage values.
pub(crate) show_decimal: Option<bool>,
/// Whether to hide the average CPU entry.
pub(crate) hide_avg_cpu: Option<bool>,
/// Whether to put the CPU chart legend on the left side.
pub(crate) left_legend: Option<bool>,
/// Whether to give the average CPU entry a dedicated row in basic mode.
pub(crate) average_cpu_row: Option<bool>,
}
#[cfg(test)]
+6 -8
View File
@@ -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<bool>,
pub(crate) dot_marker: Option<bool>,
pub(crate) temperature_type: Option<String>,
pub(crate) rate: Option<StringOrNum>,
pub(crate) cpu_left_legend: Option<bool>,
pub(crate) basic: Option<bool>,
pub(crate) default_time_value: Option<StringOrNum>,
pub(crate) time_delta: Option<StringOrNum>,
@@ -50,16 +48,16 @@ pub(crate) struct GeneralConfig {
pub(crate) show_table_scroll_position: Option<bool>,
pub(crate) show_table_scroll_bar: Option<bool>,
pub(crate) read_only: Option<bool>,
// #[cfg(feature = "zfs")]
pub(crate) free_arc: Option<bool>,
pub(crate) disable_gpu: Option<bool>,
// 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<bool>,
pub(crate) enable_cache_memory: Option<bool>,
pub(crate) retention: Option<StringOrNum>,
// FIXME: Deprecate these in the future.
pub(crate) hide_avg_cpu: Option<bool>,
pub(crate) cpu_left_legend: Option<bool>,
pub(crate) average_cpu_row: Option<bool>,
pub(crate) enable_cache_memory: Option<bool>,
// #[cfg(feature = "zfs")]
pub(crate) free_arc: Option<bool>,
pub(crate) network_use_bytes: Option<bool>,
pub(crate) network_use_log: Option<bool>,
pub(crate) network_use_binary_prefix: Option<bool>,
+6
View File
@@ -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<String>,
/// Whether to collect and display cache and buffer memory. Not available on Windows.
pub(crate) cache_memory: Option<bool>,
/// Whether to subtract freeable ARC from memory usage.
pub(crate) free_arc: Option<bool>,
}
+11
View File
@@ -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"]);
}
@@ -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
+10
View File
@@ -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