diff --git a/src/constants.rs b/src/constants.rs index d8d9a3ad2..16c4b6479 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -261,11 +261,11 @@ pub const DEFAULT_BATTERY_LAYOUT: &str = r#" // Config and flags // TODO: Eventually deprecate this, or grab from a file. -pub const CONFIG_TEXT: &str = r#"# This is a default config file for bottom. All of the settings are commented +pub const CONFIG_TEXT: &str = r#"# This is a default config file for bottom. All of the settings are commented # out by default; if you wish to change them uncomment and modify as you see # fit. -# This group of options represents a command-line option. Flags explicitly +# This group of options represents a command-line option. Flags explicitly # added when running (ie: btm -a) will override this config file if an option # is also set here. [flags] @@ -340,9 +340,9 @@ pub const CONFIG_TEXT: &str = r#"# This is a default config file for bottom. Al # How much data is stored at once in terms of time. #retention = "10m" # Where to place the legend for the memory widget. One of "none", "top-left", "top", "top-right", "left", "right", "bottom-left", "bottom", "bottom-right". -#memory_legend = "TopRight". +#memory_legend = "TopRight" # 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 = "TopRight". +#network_legend = "TopRight" # Processes widget configuration #[processes] @@ -484,34 +484,12 @@ pub const CONFIG_TOP_HEAD: &str = r##"# This is bottom's config file. "##; -pub const CONFIG_DISPLAY_OPTIONS_HEAD: &str = r#" -# These options represent settings that affect how bottom functions. -# If a setting here corresponds to command-line option, then the flag will temporarily override -# the setting. -"#; - -pub const CONFIG_COLOUR_HEAD: &str = r#" -# These options represent colour values for various parts of bottom. Note that colour support -# will ultimately depend on the terminal - for example, the Terminal for macOS does NOT like -# custom colours and it may glitch out. -"#; - -pub const CONFIG_LAYOUT_HEAD: &str = r#" -# These options represent how bottom will lay out its widgets. Layouts follow a pattern like this: -# [[row]] represents a row in the application. -# [[row.child]] represents either a widget or a column. -# [[row.child.child]] represents a widget. -# -# All widgets must have the valid type value set to one of ["cpu", "mem", "proc", "net", "temp", "disk", "empty"]. -# All layout components have a ratio value - if this is not set, then it defaults to 1. -"#; - -pub const CONFIG_FILTER_HEAD: &str = r#" -# These options represent disabled entries for the temperature and disk widgets. -"#; - #[cfg(test)] mod test { + use regex::Regex; + + use crate::options::Config; + use super::*; #[test] @@ -543,4 +521,22 @@ mod test { Borders::ALL.difference(Borders::TOP.union(Borders::BOTTOM)) ) } + + /// Checks that the default config is valid. + #[test] + fn check_default_config() { + let default_config = Regex::new(r"(?m)^#([a-zA-Z\[])") + .unwrap() + .replace_all(CONFIG_TEXT, "$1"); + + let default_config = Regex::new(r"(?m)^#(\s\s+)([a-zA-Z\[])") + .unwrap() + .replace_all(&default_config, "$2"); + + let _config: Config = + toml_edit::de::from_str(&default_config).expect("can parse default config"); + + // TODO: Check this. + // assert_eq!(config, Config::default()); + } } diff --git a/src/options/config.rs b/src/options/config.rs index 258943fa7..51fea3bf2 100644 --- a/src/options/config.rs +++ b/src/options/config.rs @@ -24,7 +24,7 @@ use self::{cpu::CpuConfig, layout::Row, process::ProcessesConfig}; derive(schemars::JsonSchema), schemars(title = "Schema for bottom's configs (nightly)") )] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub struct Config { pub(crate) flags: Option, pub(crate) styles: Option, @@ -39,6 +39,7 @@ pub struct Config { #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(untagged)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] +#[cfg_attr(test, derive(PartialEq, Eq))] pub(crate) enum StringOrNum { String(String), Num(u64), diff --git a/src/options/config/cpu.rs b/src/options/config/cpu.rs index c9ba25296..672b60167 100644 --- a/src/options/config/cpu.rs +++ b/src/options/config/cpu.rs @@ -5,6 +5,7 @@ use serde::Deserialize; #[derive(Clone, Copy, Debug, Default, Deserialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] #[serde(rename_all = "lowercase")] +#[cfg_attr(test, derive(PartialEq, Eq))] pub enum CpuDefault { #[default] All, @@ -15,7 +16,7 @@ pub enum CpuDefault { /// CPU column settings. #[derive(Clone, Debug, Default, Deserialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub struct CpuConfig { #[serde(default)] pub default: CpuDefault, diff --git a/src/options/config/disk.rs b/src/options/config/disk.rs index 13373a115..bbc113bda 100644 --- a/src/options/config/disk.rs +++ b/src/options/config/disk.rs @@ -5,7 +5,7 @@ use super::IgnoreList; /// Disk configuration. #[derive(Clone, Debug, Default, Deserialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub struct DiskConfig { /// A filter over the disk names. pub name_filter: Option, diff --git a/src/options/config/flags.rs b/src/options/config/flags.rs index 39f18eaa1..feb10f5f8 100644 --- a/src/options/config/flags.rs +++ b/src/options/config/flags.rs @@ -4,7 +4,7 @@ use super::StringOrNum; #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub(crate) struct FlagConfig { pub(crate) hide_avg_cpu: Option, pub(crate) dot_marker: Option, diff --git a/src/options/config/ignore_list.rs b/src/options/config/ignore_list.rs index 5950cbb42..3dd2a73f5 100644 --- a/src/options/config/ignore_list.rs +++ b/src/options/config/ignore_list.rs @@ -7,7 +7,7 @@ fn default_as_true() -> bool { #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub struct IgnoreList { #[serde(default = "default_as_true")] // TODO: Deprecate and/or rename, current name sounds awful. diff --git a/src/options/config/layout.rs b/src/options/config/layout.rs index d68b29587..dbf642067 100644 --- a/src/options/config/layout.rs +++ b/src/options/config/layout.rs @@ -6,7 +6,7 @@ use crate::{app::layout_manager::*, options::OptionResult}; /// of children. #[derive(Clone, Deserialize, Debug, Serialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] #[serde(rename = "row")] pub struct Row { pub ratio: Option, @@ -218,7 +218,7 @@ impl Row { #[derive(Clone, Deserialize, Debug, Serialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] #[serde(untagged)] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub enum RowChildren { Widget(FinalWidget), Col { @@ -230,7 +230,7 @@ pub enum RowChildren { /// Represents a widget. #[derive(Clone, Deserialize, Debug, Serialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub struct FinalWidget { pub ratio: Option, #[serde(rename = "type")] diff --git a/src/options/config/network.rs b/src/options/config/network.rs index 2d8bc6f96..4d98194cd 100644 --- a/src/options/config/network.rs +++ b/src/options/config/network.rs @@ -5,7 +5,7 @@ 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))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub struct NetworkConfig { /// A filter over the network interface names. pub interface_filter: Option, diff --git a/src/options/config/process.rs b/src/options/config/process.rs index 8f34fd6db..52fd4861c 100644 --- a/src/options/config/process.rs +++ b/src/options/config/process.rs @@ -5,7 +5,7 @@ use crate::widgets::ProcWidgetColumn; /// Process configuration. #[derive(Clone, Debug, Default, Deserialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub struct ProcessesConfig { /// A list of process widget columns. #[serde(default)] @@ -18,6 +18,7 @@ pub struct ProcessesConfig { feature = "generate_schema", derive(schemars::JsonSchema, strum::VariantArray) )] +#[cfg_attr(test, derive(PartialEq, Eq))] pub enum ProcColumn { Pid, Count, diff --git a/src/options/config/style.rs b/src/options/config/style.rs index 921e1cce2..d01713f52 100644 --- a/src/options/config/style.rs +++ b/src/options/config/style.rs @@ -29,13 +29,14 @@ use super::Config; #[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] +#[cfg_attr(test, derive(PartialEq, Eq))] pub(crate) struct ColorStr(Cow<'static, str>); /// A style for text. #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(untagged)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub(crate) enum TextStyleConfig { Colour(ColorStr), TextStyle { @@ -60,6 +61,7 @@ pub(crate) enum TextStyleConfig { /// Style-related configs. #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub(crate) struct StyleConfig { /// A built-in theme. /// diff --git a/src/options/config/style/battery.rs b/src/options/config/style/battery.rs index e643a6351..0d85a4f07 100644 --- a/src/options/config/style/battery.rs +++ b/src/options/config/style/battery.rs @@ -5,6 +5,7 @@ use super::ColorStr; /// Styling specific to the battery widget. #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub(crate) struct BatteryStyle { /// The colour of the battery widget bar when the battery is over 50%. #[serde(alias = "high_battery_colour")] diff --git a/src/options/config/style/cpu.rs b/src/options/config/style/cpu.rs index 01bf95cb2..2cb5415dc 100644 --- a/src/options/config/style/cpu.rs +++ b/src/options/config/style/cpu.rs @@ -5,6 +5,7 @@ use super::ColorStr; /// Styling specific to the CPU widget. #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub(crate) struct CpuStyle { /// The colour of the "All" CPU label. #[serde(alias = "all_entry_colour")] diff --git a/src/options/config/style/graphs.rs b/src/options/config/style/graphs.rs index 77603756e..ce3c37baf 100644 --- a/src/options/config/style/graphs.rs +++ b/src/options/config/style/graphs.rs @@ -5,6 +5,7 @@ use super::{ColorStr, TextStyleConfig}; /// General styling for graph widgets. #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub(crate) struct GraphStyle { /// The general colour of the parts of the graph. #[serde(alias = "graph_colour")] diff --git a/src/options/config/style/memory.rs b/src/options/config/style/memory.rs index f1c6d4197..2b0aa5d18 100644 --- a/src/options/config/style/memory.rs +++ b/src/options/config/style/memory.rs @@ -6,6 +6,7 @@ use super::ColorStr; /// Styling specific to the memory widget. #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub(crate) struct MemoryStyle { /// The colour of the RAM label and graph line. #[serde(alias = "ram_colour")] diff --git a/src/options/config/style/network.rs b/src/options/config/style/network.rs index 83ad1307f..2b6a2dd88 100644 --- a/src/options/config/style/network.rs +++ b/src/options/config/style/network.rs @@ -5,6 +5,7 @@ use super::ColorStr; /// Styling specific to the network widget. #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub(crate) struct NetworkStyle { /// The colour of the RX (download) label and graph line. #[serde(alias = "rx_colour")] diff --git a/src/options/config/style/tables.rs b/src/options/config/style/tables.rs index 834178f81..2224fdad7 100644 --- a/src/options/config/style/tables.rs +++ b/src/options/config/style/tables.rs @@ -5,6 +5,7 @@ use super::TextStyleConfig; /// General styling for table widgets. #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub(crate) struct TableStyle { /// Text styling for table headers. pub(crate) headers: Option, diff --git a/src/options/config/style/widgets.rs b/src/options/config/style/widgets.rs index 8aaa9f6a6..fb40fd698 100644 --- a/src/options/config/style/widgets.rs +++ b/src/options/config/style/widgets.rs @@ -5,6 +5,7 @@ use super::{ColorStr, TextStyleConfig}; /// General styling for generic widgets. #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub(crate) struct WidgetStyle { /// The colour of the widgets' borders. #[serde(alias = "border_colour")] diff --git a/src/options/config/temperature.rs b/src/options/config/temperature.rs index 430d6d61a..2580a2ea0 100644 --- a/src/options/config/temperature.rs +++ b/src/options/config/temperature.rs @@ -5,7 +5,7 @@ use super::IgnoreList; /// Temperature configuration. #[derive(Clone, Debug, Default, Deserialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] -#[cfg_attr(test, serde(deny_unknown_fields))] +#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub struct TempConfig { /// A filter over the sensor names. pub sensor_filter: Option,