diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e9cd482..76a247ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,8 @@ That said, these are more guidelines rather than hard rules, though the project - [#2031](https://github.com/ClementTsang/bottom/pull/2031): Tweak display/hiding logic for a graph widget's legend. - [#2039](https://github.com/ClementTsang/bottom/pull/2039): Replace `hide_table_gap` with `table_gap`. - [#2061](https://github.com/ClementTsang/bottom/pull/2061): Take cgroup into account for RAM/swap usage. +- [#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]`. ### Other diff --git a/docs/content/configuration/config-file/memory-graph.md b/docs/content/configuration/config-file/memory-graph.md new file mode 100644 index 00000000..ec599da4 --- /dev/null +++ b/docs/content/configuration/config-file/memory-graph.md @@ -0,0 +1,9 @@ +# Memory Graph + +## Settings + +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. | diff --git a/docs/content/configuration/config-file/network-graph.md b/docs/content/configuration/config-file/network-graph.md new file mode 100644 index 00000000..9eec9669 --- /dev/null +++ b/docs/content/configuration/config-file/network-graph.md @@ -0,0 +1,38 @@ +# Network Graph + +## Settings + +If you want to change some of the default behaviour of the network graph widget, you can configure some things in the config file. + +| Field | Type | Functionality | +| ------------------- | ------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- | +| `show_packets` | Boolean | Displays packet rate and average packet size info. | +| `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 network widget. | +| `use_bytes` | Boolean | Displays the network widget using bytes. Defaults to bits. | +| `use_log` | Boolean | Displays the network widget with a log scale. Defaults to a non-log scale. | +| `use_binary_prefix` | Boolean | Displays the network widget with a binary prefix (e.g. kibibits) rather than a decimal prefix (e.g. kilobits). Defaults to decimal prefixes. | + +## Filtering Entries + +You can filter out what entries to show by configuring `[network_graph.interface_filter]` . +In particular, you can set a list of things to filter with by setting `list`, and configure how that list is processed with the other options. + +For example, here we are ignoring any entry with a name that matches the regex `eth0.*`, or specifically `virbr0`. + +```toml +[network_graph.interface_filter] +# Whether to ignore any matches. Defaults to true. +is_list_ignored = true + +# A list of filters to try and match. +list = ["virbr0", "eth0slab"] + +# Whether to use regex. Defaults to false. +regex = true + +# Whether to be case-sensitive. Defaults to false. +case_sensitive = false + +# Whether to require matching the whole word. Defaults to false. +whole_word = false +``` diff --git a/docs/content/configuration/config-file/network.md b/docs/content/configuration/config-file/network.md deleted file mode 100644 index 686cce5d..00000000 --- a/docs/content/configuration/config-file/network.md +++ /dev/null @@ -1,34 +0,0 @@ -# Network - -## Settings - -If you want to change some of the default behaviour of the network widget, you can configure some things in the config file. - -| Field | Type | Functionality | -| -------------- | ------- | -------------------------------------------------- | -| `show_packets` | Boolean | Displays packet rate and average packet size info. | - -## Filtering Entries - -You can filter out what entries to show by configuring `[network.interface_filter]` . -In particular, you can set a list of things to filter with by setting `list`, and configure how that list is processed with the other options. - -For example, here we are ignoring any entry with a name that matches `/dev/sda`, or specifically `/dev/nvme0n1p2`. - -```toml -[network.interface_filter] -# Whether to ignore any matches. Defaults to true. -is_list_ignored = true - -# A list of filters to try and match. -list = ["virbr0.*"] - -# Whether to use regex. Defaults to false. -regex = true - -# Whether to be case-sensitive. Defaults to false. -case_sensitive = false - -# Whether to require matching the whole word. Defaults to false. -whole_word = false -``` diff --git a/docs/content/usage/widgets/memory.md b/docs/content/usage/widgets/memory-graph.md similarity index 100% rename from docs/content/usage/widgets/memory.md rename to docs/content/usage/widgets/memory-graph.md diff --git a/docs/content/usage/widgets/network.md b/docs/content/usage/widgets/network-graph.md similarity index 100% rename from docs/content/usage/widgets/network.md rename to docs/content/usage/widgets/network-graph.md diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index ebff71f8..2e6559c1 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -162,8 +162,8 @@ nav: - "Basic Mode": usage/basic-mode.md - "Widgets": - "CPU Widget": usage/widgets/cpu.md - - "Memory Widget": usage/widgets/memory.md - - "Network Widget": usage/widgets/network.md + - "Memory Graph Widget": usage/widgets/memory-graph.md + - "Network Graph Widget": usage/widgets/network-graph.md - "Process Widget": usage/widgets/process.md - "Disk Widget": usage/widgets/disk.md - "Temperature Widget": usage/widgets/temperature-table.md @@ -176,7 +176,8 @@ nav: - configuration/config-file/index.md - "CPU Widget": configuration/config-file/cpu.md - "Disk Table Widget": configuration/config-file/disk-table.md - - "Network Widget": configuration/config-file/network.md + - "Memory Graph Widget": configuration/config-file/memory-graph.md + - "Network Graph Widget": configuration/config-file/network-graph.md - "Processes Widget": configuration/config-file/processes.md - "Temperature Table Widget": configuration/config-file/temperature-table.md - "Temperature Graph Widget": configuration/config-file/temperature-graph.md diff --git a/sample_configs/default_config.toml b/sample_configs/default_config.toml index 3f4d2c5f..f26f9d51 100644 --- a/sample_configs/default_config.toml +++ b/sample_configs/default_config.toml @@ -134,7 +134,6 @@ # Where to place the legend for the network widget. One of "none", "top-left", "top", "top-right", "left", "right", "bottom-left", "bottom", "bottom-right". #network_legend = "top-right" - # Processes widget configuration #[processes] # The columns shown by the process widget. The following columns are supported (the GPU columns are only available if the GPU feature is enabled when built): @@ -148,7 +147,6 @@ # Gather process child thread information #get_threads = false - # CPU widget configuration #[cpu] # One of "all" (default), "average"/"avg" @@ -157,7 +155,6 @@ # Whether to show a decimal place for CPU usage values. #show_decimal = false - # Disk widget configuration #[disk] @@ -206,7 +203,6 @@ # Whether to require matching the whole word. Defaults to false. #whole_word = false - # Temperature widget configuration #[temperature] @@ -233,7 +229,6 @@ # Whether to require matching the whole word. Defaults to false. #whole_word = false - # Temperature graph widget configuration #[temperature_graph] @@ -261,11 +256,10 @@ # Whether to require matching the whole word. Defaults to false. #whole_word = false - # Network widget configuration -#[network] +#[network_graph] # By default, there are no network interface filters enabled. An example use case is provided below. -#[network.interface_filter] +#[network_graph.interface_filter] # Whether to ignore any matches. Defaults to true. #is_list_ignored = true @@ -281,7 +275,6 @@ # Whether to require matching the whole word. Defaults to false. #whole_word = false - # These are all the components that support custom theming. Note that colour support # will depend on terminal support. #[styles] # Uncomment if you want to use custom styling diff --git a/schema/nightly/bottom.json b/schema/nightly/bottom.json index 9e0bbbde..7853d64e 100644 --- a/schema/nightly/bottom.json +++ b/schema/nightly/bottom.json @@ -35,10 +35,20 @@ } ] }, - "network": { + "memory_graph": { "anyOf": [ { - "$ref": "#/$defs/NetworkConfig" + "$ref": "#/$defs/MemoryGraphConfig" + }, + { + "type": "null" + } + ] + }, + "network_graph": { + "anyOf": [ + { + "$ref": "#/$defs/NetworkGraphConfig" }, { "type": "null" @@ -100,33 +110,33 @@ "description": "Styling specific to the battery widget.", "type": "object", "properties": { - "high_battery_color": { + "high_battery_colour": { "description": "The colour of the battery widget bar when the battery is over 50%.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" } ] }, - "low_battery_color": { + "low_battery_colour": { "description": "The colour of the battery widget bar when the battery is under 10%.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" } ] }, - "medium_battery_color": { + "medium_battery_colour": { "description": "The colour of the battery widget bar when the battery between 10% to\n50%.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" @@ -135,7 +145,7 @@ } } }, - "ColorStr": { + "ColourStr": { "type": "string" }, "CpuConfig": { @@ -167,36 +177,36 @@ "description": "Styling specific to the CPU widget.", "type": "object", "properties": { - "all_entry_color": { + "all_entry_colour": { "description": "The colour of the \"All\" CPU label.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" } ] }, - "avg_entry_color": { + "avg_entry_colour": { "description": "The colour of the average CPU label and graph line.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" } ] }, - "cpu_core_colors": { + "cpu_core_colours": { "description": "Colour of each CPU threads' label and graph line. Read in order.", "type": [ "array", "null" ], "items": { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" } } } @@ -597,11 +607,11 @@ "description": "General styling for graph widgets.", "type": "object", "properties": { - "graph_color": { + "graph_colour": { "description": "The general colour of the parts of the graph.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" @@ -651,58 +661,71 @@ "list" ] }, + "MemoryGraphConfig": { + "description": "Memory-related configuration file options.", + "type": "object", + "properties": { + "legend_position": { + "description": "Where to place the legend for the memory chart widget.", + "type": [ + "string", + "null" + ] + } + } + }, "MemoryStyle": { "description": "Styling specific to the memory widget.", "type": "object", "properties": { - "arc_color": { + "arc_colour": { "description": "The colour of the ARC label and graph line.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" } ] }, - "cache_color": { + "cache_colour": { "description": "The colour of the cache label and graph line. Does not do anything on\nWindows.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" } ] }, - "gpu_colors": { + "gpu_colours": { "description": "Colour of each GPU's memory label and graph line. Read in order.", "type": [ "array", "null" ], "items": { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" } }, - "ram_color": { + "ram_colour": { "description": "The colour of the RAM label and graph line.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" } ] }, - "swap_color": { + "swap_colour": { "description": "The colour of the swap label and graph line.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" @@ -711,7 +734,7 @@ } } }, - "NetworkConfig": { + "NetworkGraphConfig": { "description": "Network configuration.", "type": "object", "properties": { @@ -726,12 +749,40 @@ } ] }, + "legend_position": { + "description": "Where to place the legend for the network chart widget.", + "type": [ + "string", + "null" + ] + }, "show_packets": { "description": "Displays packet rate and average packet size info.", "type": [ "boolean", "null" ] + }, + "use_binary_prefix": { + "description": "Displays the network widget with a binary prefix (e.g. kibibits) rather than a decimal\nprefix (e.g. kilobits). Defaults to decimal prefixes.", + "type": [ + "boolean", + "null" + ] + }, + "use_bytes": { + "description": "Displays the network widget using bytes. Defaults to bits.", + "type": [ + "boolean", + "null" + ] + }, + "use_log": { + "description": "Displays the network widget with a log scale. Defaults to a non-log scale.", + "type": [ + "boolean", + "null" + ] } } }, @@ -739,44 +790,44 @@ "description": "Styling specific to the network widget.", "type": "object", "properties": { - "rx_color": { + "rx_colour": { "description": "The colour of the RX (download) label and graph line.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" } ] }, - "rx_total_color": { - "description": "he colour of the total RX (download) label in basic mode.", + "rx_total_colour": { + "description": "The colour of the total RX (download) label in basic mode.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" } ] }, - "tx_color": { + "tx_colour": { "description": "The colour of the TX (upload) label and graph line.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" } ] }, - "tx_total_color": { + "tx_total_colour": { "description": "The colour of the total TX (upload) label in basic mode.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" @@ -1123,14 +1174,14 @@ "description": "Styling specific to the temperature graph widget.", "type": "object", "properties": { - "temp_graph_color_styles": { + "temp_graph_colour_styles": { "description": "Colour of each temperature sensor's graph line. Read in order.", "type": [ "array", "null" ], "items": { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" } } } @@ -1150,16 +1201,16 @@ "description": "A style for text.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "object", "properties": { - "bg_color": { + "bg_colour": { "description": "A built-in ANSI colour, RGB hex, or RGB colour code.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" @@ -1173,11 +1224,11 @@ "null" ] }, - "color": { + "colour": { "description": "A built-in ANSI colour, RGB hex, or RGB colour code.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" @@ -1208,22 +1259,22 @@ "description": "General styling for generic widgets.", "type": "object", "properties": { - "bg_color": { - "description": "Background color for widgets.", + "bg_colour": { + "description": "Background colour for widgets.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" } ] }, - "border_color": { + "border_colour": { "description": "The colour of the widgets' borders.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" @@ -1241,11 +1292,11 @@ } ] }, - "selected_border_color": { + "selected_border_colour": { "description": "The colour of a widget's borders when the widget is selected.", "anyOf": [ { - "$ref": "#/$defs/ColorStr" + "$ref": "#/$defs/ColourStr" }, { "type": "null" diff --git a/src/app/filter.rs b/src/app/filter.rs index 05e37b3e..9318823e 100644 --- a/src/app/filter.rs +++ b/src/app/filter.rs @@ -64,10 +64,29 @@ mod test { use super::*; + /// Quick test for filtering w/ regex. + #[test] + fn filter_simple() { + let values = ["eth0slab", "virbr0", "eth0", "wlan0", "lo"]; + + let filter = Filter { + is_list_ignored: false, + list: vec![Regex::new("virbr0").unwrap(), Regex::new("eth0").unwrap()], + }; + + assert_eq!( + values + .into_iter() + .filter(|r| filter.should_keep(r)) + .collect::>(), + vec!["eth0slab", "virbr0", "eth0"] + ); + } + /// Test based on the issue in . #[test] fn filter_is_list_ignored() { - let results = [ + let values = [ "CPU socket temperature", "wifi_0", "motherboard temperature", @@ -80,7 +99,7 @@ mod test { }; assert_eq!( - results + values .into_iter() .filter(|r| ignore_true.should_keep(r)) .collect::>(), @@ -93,7 +112,7 @@ mod test { }; assert_eq!( - results + values .into_iter() .filter(|r| ignore_false.should_keep(r)) .collect::>(), @@ -109,7 +128,7 @@ mod test { }; assert_eq!( - results + values .into_iter() .filter(|r| multi_true.should_keep(r)) .collect::>(), @@ -125,7 +144,7 @@ mod test { }; assert_eq!( - results + values .into_iter() .filter(|r| multi_false.should_keep(r)) .collect::>(), diff --git a/src/constants.rs b/src/constants.rs index 5df8c7aa..e3617c5a 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -512,9 +512,9 @@ pub(crate) const CONFIG_TEXT: &str = r#"# This is a default config file for bott # Network widget configuration -#[network] +#[network_graph] # By default, there are no network interface filters enabled. An example use case is provided below. -#[network.interface_filter] +#[network_graph.interface_filter] # Whether to ignore any matches. Defaults to true. #is_list_ignored = true diff --git a/src/options.rs b/src/options.rs index 6164efe3..88cc4e06 100644 --- a/src/options.rs +++ b/src/options.rs @@ -303,9 +303,11 @@ pub(crate) fn init_app(args: BottomArgs, config: Config) -> Result<(App, BottomL let network_unit_type = get_network_unit_type(args, config); let network_scale_type = get_network_scale_type(args, config); - let network_use_binary_prefix = - is_flag_enabled!(network_use_binary_prefix, args.network, config); - let network_show_packets = is_flag_enabled_in!(show_packets, args.network, config.network); + // Use + update this again after deprecation + // let network_use_binary_prefix = is_flag_enabled!(network_use_binary_prefix, args.network, config); + let network_use_binary_prefix = get_network_use_binary_prefix(args, config); + let network_show_packets = + is_flag_enabled_in!(show_packets, args.network, config.network_graph); let proc_columns: Option> = { config.processes.as_ref().and_then(|cfg| { @@ -587,9 +589,9 @@ pub(crate) fn init_app(args: BottomArgs, config: Config) -> Result<(App, BottomL .context("Update 'temperature_graph.sensor_filter' in your config file")?, None => None, }; - let net_interface_filter = match &config.network { + let net_interface_filter = match &config.network_graph { Some(cfg) => get_ignore_list(&cfg.interface_filter) - .context("Update 'network.interface_filter' in your config file")?, + .context("Update 'network_graph.interface_filter' in your config file")?, None => None, }; @@ -781,6 +783,14 @@ macro_rules! parse_ms_option { }}; } +/// Mark a config option field as deprecated, and what to use instead. +#[inline] +fn deprecated_warning(deprecated_field: &str, new_field: &str) { + eprintln!( + "Warning: The config option '{deprecated_field}' is deprecated and will eventually be removed. Please use '{new_field}' instead.", + ); +} + /// How quickly we update data. #[inline] fn get_update_rate(args: &BottomArgs, config: &Config) -> OptionResult { @@ -1016,8 +1026,14 @@ fn get_ignore_list(ignore_list: &Option) -> OptionResult DataUnit { if args.network.network_use_bytes { return DataUnit::Byte; + } else if let Some(use_bytes) = config.network_graph.as_ref().and_then(|cfg| cfg.use_bytes) { + if use_bytes { + return DataUnit::Byte; + } } else if let Some(flags) = &config.flags { if let Some(network_use_bytes) = flags.network_use_bytes { + deprecated_warning("network_use_bytes", "network_graph.use_bytes"); + if network_use_bytes { return DataUnit::Byte; } @@ -1030,8 +1046,14 @@ fn get_network_unit_type(args: &BottomArgs, config: &Config) -> DataUnit { fn get_network_scale_type(args: &BottomArgs, config: &Config) -> AxisScaling { if args.network.network_use_log { return AxisScaling::Log; + } else if let Some(use_log) = config.network_graph.as_ref().and_then(|cfg| cfg.use_log) { + if use_log { + return AxisScaling::Log; + } } else if let Some(flags) = &config.flags { if let Some(network_use_log) = flags.network_use_log { + deprecated_warning("network_use_log", "network_graph.use_log"); + if network_use_log { return AxisScaling::Log; } @@ -1041,6 +1063,29 @@ fn get_network_scale_type(args: &BottomArgs, config: &Config) -> AxisScaling { AxisScaling::Linear } +fn get_network_use_binary_prefix(args: &BottomArgs, config: &Config) -> bool { + if args.network.network_use_binary_prefix { + return true; + } else if let Some(use_binary_prefix) = config + .network_graph + .as_ref() + .and_then(|cfg| cfg.use_binary_prefix) + { + return use_binary_prefix; + } else if let Some(flags) = &config.flags { + if let Some(network_use_binary_prefix) = flags.network_use_binary_prefix { + deprecated_warning( + "network_use_binary_prefix", + "network_graph.use_binary_prefix", + ); + + return network_use_binary_prefix; + } + } + + false +} + fn get_retention(args: &BottomArgs, config: &Config) -> OptionResult { const DEFAULT_RETENTION_MS: u64 = 600 * 1000; // Keep 10 minutes of data. @@ -1059,7 +1104,8 @@ fn get_retention(args: &BottomArgs, config: &Config) -> OptionResult { #[inline] fn parse_legend_position( - arg: Option<&String>, cfg: Option<&String>, setting: &'static str, + arg: Option<&String>, cfg: Option<&String>, deprecated_cfg: Option<(&String, &'static str)>, + setting: &'static str, ) -> OptionResult> { #[inline] fn parse_position_or_err OptionError>( @@ -1075,6 +1121,10 @@ fn parse_legend_position( parse_position_or_err(s, setting, OptionError::invalid_arg_value) } else if let Some(s) = cfg { parse_position_or_err(s, setting, OptionError::invalid_config_value) + } else if let Some((s, name)) = deprecated_cfg { + // Remove the deprecated args/code paths and copy back to the function above later. + deprecated_warning(name, setting); + parse_position_or_err(s, setting, OptionError::invalid_config_value) } else { Ok(Some(LegendPosition::default())) } @@ -1085,11 +1135,16 @@ fn get_network_legend_position( ) -> OptionResult> { parse_legend_position( args.network.network_legend.as_ref(), + config + .network_graph + .as_ref() + .and_then(|cfg| cfg.legend_position.as_ref()), config .flags .as_ref() - .and_then(|flags| flags.network_legend.as_ref()), - "network_legend", + .and_then(|flags| flags.network_legend.as_ref()) + .map(|s| (s, "network_legend")), + "network.legend_position", ) } @@ -1098,11 +1153,16 @@ fn get_memory_legend_position( ) -> OptionResult> { parse_legend_position( args.memory.memory_legend.as_ref(), + config + .memory_graph + .as_ref() + .and_then(|cfg| cfg.legend_position.as_ref()), config .flags .as_ref() - .and_then(|flags| flags.memory_legend.as_ref()), - "memory_legend", + .and_then(|flags| flags.memory_legend.as_ref()) + .map(|s| (s, "memory_legend")), + "memory.legend_position", ) } @@ -1113,6 +1173,7 @@ fn get_temperature_legend_position(config: &Config) -> OptionResult, pub(crate) temperature: Option, pub(crate) temperature_graph: Option, - pub(crate) network: Option, + #[serde(alias = "network")] + pub(crate) network_graph: Option, + pub(crate) memory_graph: Option, pub(crate) cpu: Option, } diff --git a/src/options/config/flags.rs b/src/options/config/flags.rs index 16f2ccff..e36fec7e 100644 --- a/src/options/config/flags.rs +++ b/src/options/config/flags.rs @@ -53,7 +53,9 @@ pub(crate) struct GeneralConfig { pub(crate) disable_click: Option, pub(crate) disable_keys: Option, pub(crate) no_write: Option, - pub(crate) network_legend: Option, // TODO: Migrate this to per-widget config + // FIXME: Deprecate this in the future. + pub(crate) network_legend: Option, + // FIXME: Deprecate this in the future. pub(crate) memory_legend: Option, pub(crate) process_memory_as_value: Option, pub(crate) tree: Option, @@ -70,8 +72,11 @@ pub(crate) struct GeneralConfig { pub(crate) hide_k_threads: Option, // #[cfg(feature = "zfs")] pub(crate) free_arc: Option, + // FIXME: Deprecate this in the future. pub(crate) network_use_bytes: Option, + // FIXME: Deprecate this in the future. pub(crate) network_use_log: Option, + // FIXME: Deprecate this in the future. pub(crate) network_use_binary_prefix: Option, pub(crate) disable_gpu: Option, pub(crate) enable_cache_memory: Option, diff --git a/src/options/config/memory_graph.rs b/src/options/config/memory_graph.rs new file mode 100644 index 00000000..e751aac8 --- /dev/null +++ b/src/options/config/memory_graph.rs @@ -0,0 +1,14 @@ +//! Memory graph configuration. + +use serde::Deserialize; + +/// Memory-related configuration file options. +#[derive(Clone, Debug, Default, Deserialize)] +#[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] +pub struct MemoryGraphConfig { + // TODO: We probably want to make this an enum...? If we want to also support external legends + // (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, +} diff --git a/src/options/config/network.rs b/src/options/config/network.rs deleted file mode 100644 index 465a260d..00000000 --- a/src/options/config/network.rs +++ /dev/null @@ -1,14 +0,0 @@ -use serde::Deserialize; - -use super::IgnoreList; - -/// Network configuration. -#[derive(Clone, Debug, Default, Deserialize)] -#[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] -#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] -pub(crate) struct NetworkConfig { - /// A filter over the network interface names. - pub(crate) interface_filter: Option, - /// Displays packet rate and average packet size info. - pub(crate) show_packets: Option, -} diff --git a/src/options/config/network_graph.rs b/src/options/config/network_graph.rs new file mode 100644 index 00000000..8ea02e97 --- /dev/null +++ b/src/options/config/network_graph.rs @@ -0,0 +1,30 @@ +use serde::Deserialize; + +use super::IgnoreList; + +/// Network configuration. +#[derive(Clone, Debug, Default, Deserialize)] +#[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] +pub(crate) struct NetworkGraphConfig { + /// A filter over the network interface names. + pub(crate) interface_filter: Option, + + /// Displays packet rate and average packet size info. + pub(crate) show_packets: Option, + + // TODO: We probably want to make this an enum...? If we want to also support external legends + // (e.g. table-style, list-style) then we probably need a new system outright. + /// Where to place the legend for the network chart widget. + pub(crate) legend_position: Option, + + /// Displays the network widget using bytes. Defaults to bits. + pub(crate) use_bytes: Option, + + /// Displays the network widget with a log scale. Defaults to a non-log scale. + pub(crate) use_log: Option, + + /// Displays the network widget with a binary prefix (e.g. kibibits) rather than a decimal + /// prefix (e.g. kilobits). Defaults to decimal prefixes. + pub(crate) use_binary_prefix: Option, +} diff --git a/tests/integration/valid_config_tests.rs b/tests/integration/valid_config_tests.rs index 501089a0..1dd39fee 100644 --- a/tests/integration/valid_config_tests.rs +++ b/tests/integration/valid_config_tests.rs @@ -210,3 +210,19 @@ fn test_temp_disk_sort_columns() { fn test_proc_default_sort() { run_and_kill(&["-C", "./tests/valid_configs/proc_default_sort.toml"]); } + +#[test] +fn test_newer_mem_network() { + run_and_kill(&["-C", "./tests/valid_configs/newer_mem_network.toml"]); +} + +/// This uses deprecated network and memory settings - once they are removed, this test file should be moved to invalid configs. +#[test] +fn test_deprecated_mem_network() { + run_and_kill(&["-C", "./tests/valid_configs/deprecated_mem_network.toml"]); +} + +#[test] +fn test_network_alias() { + run_and_kill(&["-C", "./tests/valid_configs/network_alias.toml"]); +} diff --git a/tests/valid_configs/deprecated_mem_network.toml b/tests/valid_configs/deprecated_mem_network.toml new file mode 100644 index 00000000..618fcd0a --- /dev/null +++ b/tests/valid_configs/deprecated_mem_network.toml @@ -0,0 +1,9 @@ +# This uses deprecated network and memory settings - once they are removed, this test file should be moved to invalid configs. + +[flags] +network_use_bytes = true +network_use_log = true +network_use_binary_prefix = true +network_legend = "left" + +memory_legend = "left" diff --git a/tests/valid_configs/filtering.toml b/tests/valid_configs/filtering.toml index 5d7416ad..1806cd00 100644 --- a/tests/valid_configs/filtering.toml +++ b/tests/valid_configs/filtering.toml @@ -21,8 +21,8 @@ regex = false case_sensitive = false whole_word = false -[network] -[network.interface_filter] +[network_graph] +[network_graph.interface_filter] is_list_ignored = true list = ["virbr0.*"] regex = true diff --git a/tests/valid_configs/network_alias.toml b/tests/valid_configs/network_alias.toml new file mode 100644 index 00000000..9a0bd9c6 --- /dev/null +++ b/tests/valid_configs/network_alias.toml @@ -0,0 +1,14 @@ +# We allow [network] as an alias since that's what it used to be called. + +[network] +use_log = false +use_bytes = false +legend_position = "right" +use_binary_prefix = false + +[network.interface_filter] +is_list_ignored = true +list = ["virbr0.*"] +regex = true +case_sensitive = false +whole_word = false diff --git a/tests/valid_configs/newer_mem_network.toml b/tests/valid_configs/newer_mem_network.toml new file mode 100644 index 00000000..8b0301ef --- /dev/null +++ b/tests/valid_configs/newer_mem_network.toml @@ -0,0 +1,10 @@ +# This uses the newer memory/network config location. + +[network_graph] +use_log = true +use_bytes = true +use_binary_prefix = true +legend_position = "left" + +[memory_graph] +legend_position = "left"