diff --git a/CHANGELOG.md b/CHANGELOG.md index 959f4148..b5075e72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ That said, these are more guidelines rather than hard rules, though the project - [#1938](https://github.com/ClementTsang/bottom/pull/1938), [#1980](https://github.com/ClementTsang/bottom/pull/1980): Report average packet size and packet rate. - [#2003](https://github.com/ClementTsang/bottom/pull/2003): Configurable default sort column for temperature and disk table widgets. -- [#1979](https://github.com/ClementTsang/bottom/pull/1979): Add a global `bg_color` config option to set widget background colour. +- [#1979](https://github.com/ClementTsang/bottom/pull/1979): Add a global `bg_colour` config option to set widget background colour. - [#2039](https://github.com/ClementTsang/bottom/pull/2039): Add a config option for drawing a line separator (`table_gap`) between the column headers and data. - [#1948](https://github.com/ClementTsang/bottom/pull/1948): Add support for both an `!=` operator and `!` negation prefixes in query searches. - [#2045](https://github.com/ClementTsang/bottom/pull/2045): Add support for showing a decimal place for CPU usage diff --git a/docs/content/configuration/command-line-options.md b/docs/content/configuration/command-line-options.md index 8b7e51c6..08f9a90c 100644 --- a/docs/content/configuration/command-line-options.md +++ b/docs/content/configuration/command-line-options.md @@ -93,9 +93,9 @@ see information on these options by running `btm -h`, or run `btm --help` to dis ## Style Options -| Option | Behaviour | -| ------------------ | ---------------------------------------------------------------- | -| `--theme ` | Use a built-in color theme, use '--help' for info on the colors. | +| Option | Behaviour | +| ------------------ | ------------------------------------------------------------------ | +| `--theme ` | Use a built-in colour theme, use '--help' for info on the colours. | ## Other Options diff --git a/docs/content/configuration/config-file/styling.md b/docs/content/configuration/config-file/styling.md index 861455f7..131a95b2 100644 --- a/docs/content/configuration/config-file/styling.md +++ b/docs/content/configuration/config-file/styling.md @@ -42,6 +42,28 @@ bottom's components can also be individually styled by the user to control the c ### Colours +!!! Info + + Note that anywhere `"colour"` is used, it can be substituted for `"color"`: + + ```toml + # This is okay + [styles.widgets.widget_title] + colour = "black" + bg_colour = "white" + + [styles.cpu] + all_entry_colour = "green" + + # This is also okay + [styles.widgets.widget_title] + color = "black" + bg_color = "white" + + [styles.cpu] + all_entry_color = "green" + ``` + You can configure the colours for components with strings that are either hex colours (e.g. `"#ffffff"`), RGB colours (e.g. `"255, 255, 255"`), or named colours. Named colours are one of the following strings: @@ -69,19 +91,19 @@ Text can generally be styled using the following TOML table: ```toml [field] # The foreground colour of text. -color = "black" +colour = "black" # The background colour of text. -bg_color = "blue" +bg_colour = "blue" # Whether to make the text bold. bold = false # Inline table version -field = { color = "black", bg_color = "blue", bold = false } +field = { colour = "black", bg_colour = "blue", bold = false } ``` -All fields are optional; by default if `bg_color` is not set then there will be no background color. +All fields are optional; by default if `bg_colour` is not set then there will be no background colour. If you _just_ want to style text by setting the foreground colour, for brevity, then you can also just set the field to be the colour itself. For example: @@ -97,81 +119,81 @@ selected_text = "#fff" These can be set under `[styles.cpu]`: -| Config field | Details | Examples | -| ----------------- | ---------------------------------------------------------------- | -------------------------------------------- | -| `all_entry_color` | The colour of the "All" CPU label | `all_entry_color = "Red"` | -| `avg_entry_color` | The colour of the average CPU label and graph line | `avg_entry_color = "255, 0, 255"` | -| `cpu_core_colors` | Colour of each CPU threads' label and graph line. Read in order. | `cpu_core_colors = ["Red", "Blue", "Green"]` | +| Config field | Details | Examples | +| ------------------ | ---------------------------------------------------------------- | --------------------------------------------- | +| `all_entry_colour` | The colour of the "All" CPU label | `all_entry_colour = "Red"` | +| `avg_entry_colour` | The colour of the average CPU label and graph line | `avg_entry_colour = "255, 0, 255"` | +| `cpu_core_colours` | Colour of each CPU threads' label and graph line. Read in order. | `cpu_core_colours = ["Red", "Blue", "Green"]` | #### Temperature Graph These can be set under `[styles.temp_graph]`: -| Config field | Details | Examples | -| ------------------------- | -------------------------------------------------------------- | ---------------------------------------------------- | -| `temp_graph_color_styles` | Colour of each temperature sensor's graph line. Read in order. | `temp_graph_color_styles = ["Red", "Blue", "Green"]` | +| Config field | Details | Examples | +| -------------------------- | -------------------------------------------------------------- | ----------------------------------------------------- | +| `temp_graph_colour_styles` | Colour of each temperature sensor's graph line. Read in order. | `temp_graph_colour_styles = ["Red", "Blue", "Green"]` | #### Memory These can be set under `[styles.memory]`: -| Config field | Details | Examples | -| ------------- | ------------------------------------------------------------------------------ | --------------------------------------- | -| `ram_color` | The colour of the RAM label and graph line | `ram_color = "Red"` | -| `cache_color` | The colour of the cache label and graph line. Does not do anything on Windows. | `cache_color = "#ffffff"` | -| `swap_color` | The colour of the swap label and graph line | `swap_color = "255, 0, 255"` | -| `arc_color` | The colour of the ARC label and graph line | `arc_color = "Blue"` | -| `gpu_colors` | Colour of each GPU's memory label and graph line. Read in order. | `gpu_colors = ["Red", "Blue", "Green"]` | +| Config field | Details | Examples | +| -------------- | ------------------------------------------------------------------------------ | ---------------------------------------- | +| `ram_colour` | The colour of the RAM label and graph line | `ram_colour = "Red"` | +| `cache_colour` | The colour of the cache label and graph line. Does not do anything on Windows. | `cache_colour = "#ffffff"` | +| `swap_colour` | The colour of the swap label and graph line | `swap_colour = "255, 0, 255"` | +| `arc_colour` | The colour of the ARC label and graph line | `arc_colour = "Blue"` | +| `gpu_colours` | Colour of each GPU's memory label and graph line. Read in order. | `gpu_colours = ["Red", "Blue", "Green"]` | #### Network These can be set under `[styles.network]`: -| Config field | Details | Examples | -| ---------------- | --------------------------------------------------------- | ---------------------------- | -| `rx_color` | The colour of the RX (download) label and graph line | `rx_color = "Red"` | -| `tx_color` | The colour of the TX (upload) label and graph line | `tx_color = "#ffffff"` | -| `rx_total_color` | The colour of the total RX (download) label in basic mode | `rx_total_color = "0, 0, 0"` | -| `tx_total_color` | The colour of the total TX (upload) label in basic mode | `tx_total_color = "#000"` | +| Config field | Details | Examples | +| ----------------- | --------------------------------------------------------- | ----------------------------- | +| `rx_colour` | The colour of the RX (download) label and graph line | `rx_colour = "Red"` | +| `tx_colour` | The colour of the TX (upload) label and graph line | `tx_colour = "#ffffff"` | +| `rx_total_colour` | The colour of the total RX (download) label in basic mode | `rx_total_colour = "0, 0, 0"` | +| `tx_total_colour` | The colour of the total TX (upload) label in basic mode | `tx_total_colour = "#000"` | #### Battery These can be set under `[styles.battery]`: -| Config field | Details | Examples | -| ---------------------- | ------------------------------------------------------------------------ | ---------------------------------- | -| `high_battery_color` | The colour of the battery widget bar when the battery is over 50% | `high_battery_color = "Red"` | -| `medium_battery_color` | The colour of the battery widget bar when the battery between 10% to 50% | `medium_battery_color = "#ffffff"` | -| `low_battery_color` | The colour of the battery widget bar when the battery is under 10% | `low_battery_color = "0, 0, 0"` | +| Config field | Details | Examples | +| ----------------------- | ------------------------------------------------------------------------ | ----------------------------------- | +| `high_battery_colour` | The colour of the battery widget bar when the battery is over 50% | `high_battery_colour = "Red"` | +| `medium_battery_colour` | The colour of the battery widget bar when the battery between 10% to 50% | `medium_battery_colour = "#ffffff"` | +| `low_battery_colour` | The colour of the battery widget bar when the battery is under 10% | `low_battery_colour = "0, 0, 0"` | #### Tables These can be set under `[styles.tables]`: -| Config field | Details | Examples | -| ------------ | ------------------------------ | -------------------------------------------------------------- | -| `headers` | Text styling for table headers | `headers = { color = "red", bg_color = "black", bold = true }` | +| Config field | Details | Examples | +| ------------ | ------------------------------ | ---------------------------------------------------------------- | +| `headers` | Text styling for table headers | `headers = { colour = "red", bg_colour = "black", bold = true }` | #### Graphs These can be set under `[styles.graphs]`: -| Config field | Details | Examples | -| ------------- | -------------------------------------------- | ------------------------------------------------------------------- | -| `graph_color` | The general colour of the parts of the graph | `graph_color = "white"` | -| `legend_text` | Text styling for graph's legend text | `legend_text = { color = "black", bg_color = "blue", bold = true }` | +| Config field | Details | Examples | +| -------------- | -------------------------------------------- | --------------------------------------------------------------------- | +| `graph_colour` | The general colour of the parts of the graph | `graph_colour = "white"` | +| `legend_text` | Text styling for graph's legend text | `legend_text = { colour = "black", bg_colour = "blue", bold = true }` | #### General widget settings These can be set under `[styles.widgets]`: -| Config field | Details | Examples | -| ----------------------- | -------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- | -| `border_color` | The colour of the widgets' borders | `border_color = "white"` | -| `selected_border_color` | The colour of a widget's borders when the widget is selected | `selected_border_color = "white"` | -| `widget_title` | Text styling for a widget's title | `widget_title = { color = "black", bg_color = "blue", bold = true }` | -| `bg_color` | The background color of the widgets. | `bg_color = "black"` | -| `text` | Text styling for text in general | `text = { color = "black", bg_color = "blue", bold = true }` | -| `selected_text` | Text styling for text when representing something that is selected | `selected_text = { color = "black", bg_color = "blue", bold = true }` | -| `disabled_text` | Text styling for text when representing something that is disabled | `disabled_text = { color = "black", bg_color = "blue", bold = true }` | -| `thread_text` | Text styling for text when representing process threads. Only usable on Linux at the moment. | `thread_text = { color = "green", bg_color = "blue", bold = true }` | +| Config field | Details | Examples | +| ------------------------ | -------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | +| `border_colour` | The colour of the widgets' borders | `border_colour = "white"` | +| `selected_border_colour` | The colour of a widget's borders when the widget is selected | `selected_border_colour = "white"` | +| `widget_title` | Text styling for a widget's title | `widget_title = { colour = "black", bg_colour = "blue", bold = true }` | +| `bg_colour` | The background colour of the widgets. | `bg_colour = "black"` | +| `text` | Text styling for text in general | `text = { colour = "black", bg_colour = "blue", bold = true }` | +| `selected_text` | Text styling for text when representing something that is selected | `selected_text = { colour = "black", bg_colour = "blue", bold = true }` | +| `disabled_text` | Text styling for text when representing something that is disabled | `disabled_text = { colour = "black", bg_colour = "blue", bold = true }` | +| `thread_text` | Text styling for text when representing process threads. Only usable on Linux at the moment. | `thread_text = { colour = "green", bg_colour = "blue", bold = true }` | diff --git a/docs/content/troubleshooting.md b/docs/content/troubleshooting.md index 8ee41cd6..7d9ee8b2 100644 --- a/docs/content/troubleshooting.md +++ b/docs/content/troubleshooting.md @@ -61,22 +61,22 @@ Let's say you're installing [Iosevka](https://github.com/be5invis/Iosevka). The 4. Here, add a new `String value`, and set the `Name` to a bunch of 0's (e.g. `000` - make sure the name isn't already used), then set the `Data` to the font name (e.g. `Iosevka`). -
- Regedit menu showing how to add a new font for Command Prompt/PowerShell -
The last entry is the new entry for Iosevka
-
+
+ Regedit menu showing how to add a new font for Command Prompt/PowerShell +
The last entry is the new entry for Iosevka
+
5. Then, open the Command Prompt/PowerShell, and right-click on the top bar, and open "Properties": -
- Opening the properties menu in Command Prompt/PowerShell -
+
+ Opening the properties menu in Command Prompt/PowerShell +
6. From here, go to "Font", and set the font to your new font (so in this example, Iosevka): -
- Setting a new font in Command Prompt/PowerShell -
+
+ Setting a new font in Command Prompt/PowerShell +
## Why can't I see all my temperature sensors on Windows? @@ -122,7 +122,7 @@ It may be handy to refer to the automatically generated config files or the [sample configuration files](https://github.com/ClementTsang/bottom/tree/main/sample_configs). The config files also follow the [TOML](https://toml.io/en/) format. -Also make sure your config options are under the right table - for example, to set your temperature type, you must +Also make sure your config option settings are in the right location - for example, to set your temperature type, you must set it under the `[flags]` table: ```toml @@ -130,11 +130,12 @@ set it under the `[flags]` table: temperature_type = "f" ``` -Meanwhile, if you want to set a custom color scheme, it would be under the `[styles]` table: +Meanwhile, if you want to set a custom colour or styling scheme, it would be under the `[styles]` table - for example: ```toml [styles.tables.headers] -color="LightBlue" +colour = "LightBlue" +bold = true ``` To help validate your configuration files, there is [JSON Schema](https://json-schema.org/) support if your IDE/editor diff --git a/docs/content/usage/widgets/process.md b/docs/content/usage/widgets/process.md index 3766f5ae..c1bdff24 100644 --- a/docs/content/usage/widgets/process.md +++ b/docs/content/usage/widgets/process.md @@ -64,11 +64,11 @@ is added together when displayed. A picture of grouped mode in a process widget. -!!! info +!!! Info Note that the process state and user columns are disabled in this mode. -!!! info +!!! Info Note that if tree mode is also active, processes cannot be grouped together due to the behaviour of the two modes somewhat clashing. This also reflects with default modes like `group_processes`. @@ -103,7 +103,7 @@ A process in tree mode can also be "collapsed", hiding its children and any desc ++plus++, or ++left++ keys, or clicking on an entry. It can be expanded by using the ++minus++, ++plus++, or ++right++ keys, or by clicking on the entry again. The ++space++ key can also be used to toggle between the collapsed and expanded states. -!!! info +!!! Info Note that if tree mode is active, processes cannot be grouped together due to the behaviour of the two modes somewhat clashing. This also reflects with default modes like `group_processes`. diff --git a/sample_configs/default_config.toml b/sample_configs/default_config.toml index 46c09154..3f4d2c5f 100644 --- a/sample_configs/default_config.toml +++ b/sample_configs/default_config.toml @@ -297,50 +297,53 @@ # or overridden if the command-line flag for a built-in theme is set. #theme = "default" +# Styling options. You can control things like colour choices, text styling (bold, italic, etc), and more. +# Note that any setting that uses the word "colour" can be substituted for "color" and it will still work fine. + #[styles.cpu] -#all_entry_color = "green" -#avg_entry_color = "red" -#cpu_core_colors = ["light magenta", "light yellow", "light cyan", "light green", "light blue", "cyan", "green", "blue"] +#all_entry_colour = "green" +#avg_entry_colour = "red" +#cpu_core_colours = ["light magenta", "light yellow", "light cyan", "light green", "light blue", "cyan", "green", "blue"] #[styles.temp_graph] -#temp_graph_color_styles = ["light magenta", "light yellow", "light cyan", "light green", "light blue", "cyan", "green", "blue"] +#temp_graph_colour_styles = ["light magenta", "light yellow", "light cyan", "light green", "light blue", "cyan", "green", "blue"] #[styles.memory] -#ram_color = "light magenta" -#cache_color = "light red" -#swap_color = "light yellow" -#arc_color = "light cyan" -#gpu_colors = ["light blue", "light red", "cyan", "green", "blue", "red"] +#ram_colour = "light magenta" +#cache_colour = "light red" +#swap_colour = "light yellow" +#arc_colour = "light cyan" +#gpu_colours = ["light blue", "light red", "cyan", "green", "blue", "red"] #[styles.network] -#rx_color = "light magenta" -#tx_color = "light yellow" -#rx_total_color = "light cyan" -#tx_total_color = "light green" +#rx_colour = "light magenta" +#tx_colour = "light yellow" +#rx_total_colour = "light cyan" +#tx_total_colour = "light green" #[styles.battery] -#high_battery_color = "green" -#medium_battery_color = "yellow" -#low_battery_color = "red" +#high_battery_colour = "green" +#medium_battery_colour = "yellow" +#low_battery_colour = "red" #[styles.tables] -#headers = {color = "light blue", bold = true} +#headers = {colour = "light blue", bold = true} #[styles.graphs] -#graph_color = "gray" -#legend_text = {color = "gray"} +#graph_colour = "gray" +#legend_text = {colour = "gray"} #[styles.widgets] -#border_color = "gray" -#selected_border_color = "light blue" -#widget_title = {color = "gray"} -#text = {color = "gray"} -#selected_text = {color = "black", bg_color = "light blue"} -#disabled_text = {color = "dark gray"} +#border_colour = "gray" +#selected_border_colour = "light blue" +#widget_title = {colour = "gray"} +#text = {colour = "gray"} +#selected_text = {colour = "black", bg_colour = "light blue"} +#disabled_text = {colour = "dark gray"} # Disabled by default -#bg_color = "black" +#bg_colour = "black" # Only on Linux -#thread_text = {color = "green"} +#thread_text = {colour = "green"} # Layout - layouts follow a pattern like this: # [[row]] represents a row in the application. diff --git a/src/canvas/components/time_series/base.rs b/src/canvas/components/time_series/base.rs index 1f0a8bcc..ed57d424 100644 --- a/src/canvas/components/time_series/base.rs +++ b/src/canvas/components/time_series/base.rs @@ -71,7 +71,7 @@ pub struct TimeGraph<'a> { /// The graph style. pub graph_style: Style, - /// The background color + /// The background colour/styling. pub general_widget_style: Style, /// The border style. diff --git a/src/constants.rs b/src/constants.rs index fc4071ae..b4a5ac59 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -545,50 +545,53 @@ pub(crate) const CONFIG_TEXT: &str = r#"# This is a default config file for bott # or overridden if the command-line flag for a built-in theme is set. #theme = "default" +# Styling options. You can control things like colour choices, text styling (bold, italic, etc), and more. +# Note that any setting that uses the word "colour" can be substituted for "color" and it will still work fine. + #[styles.cpu] -#all_entry_color = "green" -#avg_entry_color = "red" -#cpu_core_colors = ["light magenta", "light yellow", "light cyan", "light green", "light blue", "cyan", "green", "blue"] +#all_entry_colour = "green" +#avg_entry_colour = "red" +#cpu_core_colours = ["light magenta", "light yellow", "light cyan", "light green", "light blue", "cyan", "green", "blue"] #[styles.temp_graph] -#temp_graph_color_styles = ["light magenta", "light yellow", "light cyan", "light green", "light blue", "cyan", "green", "blue"] +#temp_graph_colour_styles = ["light magenta", "light yellow", "light cyan", "light green", "light blue", "cyan", "green", "blue"] #[styles.memory] -#ram_color = "light magenta" -#cache_color = "light red" -#swap_color = "light yellow" -#arc_color = "light cyan" -#gpu_colors = ["light blue", "light red", "cyan", "green", "blue", "red"] +#ram_colour = "light magenta" +#cache_colour = "light red" +#swap_colour = "light yellow" +#arc_colour = "light cyan" +#gpu_colours = ["light blue", "light red", "cyan", "green", "blue", "red"] #[styles.network] -#rx_color = "light magenta" -#tx_color = "light yellow" -#rx_total_color = "light cyan" -#tx_total_color = "light green" +#rx_colour = "light magenta" +#tx_colour = "light yellow" +#rx_total_colour = "light cyan" +#tx_total_colour = "light green" #[styles.battery] -#high_battery_color = "green" -#medium_battery_color = "yellow" -#low_battery_color = "red" +#high_battery_colour = "green" +#medium_battery_colour = "yellow" +#low_battery_colour = "red" #[styles.tables] -#headers = {color = "light blue", bold = true} +#headers = {colour = "light blue", bold = true} #[styles.graphs] -#graph_color = "gray" -#legend_text = {color = "gray"} +#graph_colour = "gray" +#legend_text = {colour = "gray"} #[styles.widgets] -#border_color = "gray" -#selected_border_color = "light blue" -#widget_title = {color = "gray"} -#text = {color = "gray"} -#selected_text = {color = "black", bg_color = "light blue"} -#disabled_text = {color = "dark gray"} +#border_colour = "gray" +#selected_border_colour = "light blue" +#widget_title = {colour = "gray"} +#text = {colour = "gray"} +#selected_text = {colour = "black", bg_colour = "light blue"} +#disabled_text = {colour = "dark gray"} # Disabled by default -#bg_color = "black" +#bg_colour = "black" # Only on Linux -#thread_text = {color = "green"} +#thread_text = {colour = "green"} # Layout - layouts follow a pattern like this: # [[row]] represents a row in the application. diff --git a/src/options.rs b/src/options.rs index 5e50a245..02c50840 100644 --- a/src/options.rs +++ b/src/options.rs @@ -381,7 +381,9 @@ pub(crate) fn init_app(args: BottomArgs, config: Config) -> Result<(App, BottomL let process_default_sort = match &args.process.process_default_sort { Some(name) => Some(ProcColumn::parse_column_name(name).ok_or_else(|| { - anyhow::anyhow!("'{name}' is not a valid process column for --process_default_sort") + OptionError::arg(format!( + "'{name}' is not a valid process column for '--process_default_sort'" + )) })?), None => config.processes.as_ref().and_then(|cfg| cfg.default_sort), }; diff --git a/src/options/args.rs b/src/options/args.rs index 43f05d08..c56a7455 100644 --- a/src/options/args.rs +++ b/src/options/args.rs @@ -646,15 +646,15 @@ pub struct StyleArgs { ], hide_possible_values = true, help = indoc! { - "Use a built-in color theme, use '--help' for info on the colors. [possible values: default, default-light, gruvbox, gruvbox-light, nord, nord-light]", + "Use a built-in colour theme, use '--help' for info on the colours. [possible values: default, default-light, gruvbox, gruvbox-light, nord, nord-light]", }, long_help = indoc! { - "Use a pre-defined color theme. Currently supported themes are: + "Use a pre-defined colour theme. Currently supported themes are: - default - default-light (default but adjusted for lighter backgrounds) - - gruvbox (a bright theme with 'retro groove' colors) + - gruvbox (a bright theme with 'retro groove' colours) - gruvbox-light (gruvbox but adjusted for lighter backgrounds) - - nord (an arctic, north-bluish color palette) + - nord (an arctic, north-bluish colour palette) - nord-light (nord but adjusted for lighter backgrounds)" } )] diff --git a/src/options/config/style.rs b/src/options/config/style.rs index fd78c7ab..7e21bfa8 100644 --- a/src/options/config/style.rs +++ b/src/options/config/style.rs @@ -34,7 +34,7 @@ use crate::options::{ #[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>); +pub(crate) struct ColourStr(Cow<'static, str>); /// A style for text. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -42,15 +42,15 @@ pub(crate) struct ColorStr(Cow<'static, str>); #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] #[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub(crate) enum TextStyleConfig { - Colour(ColorStr), + Colour(ColourStr), TextStyle { /// A built-in ANSI colour, RGB hex, or RGB colour code. - #[serde(alias = "colour")] - color: Option, + #[serde(alias = "color")] + colour: Option, /// A built-in ANSI colour, RGB hex, or RGB colour code. - #[serde(alias = "bg_colour")] - bg_color: Option, + #[serde(alias = "bg_color")] + bg_colour: Option, /// Whether to make this text bolded or not. If not set, /// will default to built-in defaults. @@ -171,59 +171,59 @@ impl Styles { "gruvbox-light" => Ok(Self::gruvbox_light_palette()), "nord" => Ok(Self::nord_palette()), "nord-light" => Ok(Self::nord_light_palette()), - _ => Err( - OptionError::other(format!("'{theme}' is an invalid built-in color scheme.")) - .into(), - ), + _ => Err(OptionError::other(format!( + "'{theme}' is an invalid built-in colour scheme." + )) + .into()), } } fn set_styles_from_config(&mut self, config: &StyleConfig) -> OptionResult<()> { // CPU - set_colour!(self.avg_cpu_colour, config.cpu, avg_entry_color); - set_colour!(self.all_cpu_colour, config.cpu, all_entry_color); - set_colour_list!(self.cpu_colour_styles, config.cpu, cpu_core_colors); + set_colour!(self.avg_cpu_colour, config.cpu, avg_entry_colour); + set_colour!(self.all_cpu_colour, config.cpu, all_entry_colour); + set_colour_list!(self.cpu_colour_styles, config.cpu, cpu_core_colours); // Temperature graph set_colour_list!( self.temp_graph_colour_styles, config.temp_graph, - temp_graph_color_styles + temp_graph_colour_styles ); // Memory - set_colour!(self.ram_style, config.memory, ram_color); - set_colour!(self.swap_style, config.memory, swap_color); + set_colour!(self.ram_style, config.memory, ram_colour); + set_colour!(self.swap_style, config.memory, swap_colour); #[cfg(not(target_os = "windows"))] - set_colour!(self.cache_style, config.memory, cache_color); + set_colour!(self.cache_style, config.memory, cache_colour); #[cfg(feature = "zfs")] - set_colour!(self.arc_style, config.memory, arc_color); + set_colour!(self.arc_style, config.memory, arc_colour); #[cfg(feature = "gpu")] - set_colour_list!(self.gpu_colours, config.memory, gpu_colors); + set_colour_list!(self.gpu_colours, config.memory, gpu_colours); // Network - set_colour!(self.rx_style, config.network, rx_color); - set_colour!(self.tx_style, config.network, tx_color); - set_colour!(self.total_rx_style, config.network, rx_total_color); - set_colour!(self.total_tx_style, config.network, tx_total_color); + set_colour!(self.rx_style, config.network, rx_colour); + set_colour!(self.tx_style, config.network, tx_colour); + set_colour!(self.total_rx_style, config.network, rx_total_colour); + set_colour!(self.total_tx_style, config.network, tx_total_colour); // Battery - set_colour!(self.high_battery, config.battery, high_battery_color); - set_colour!(self.medium_battery, config.battery, medium_battery_color); - set_colour!(self.low_battery, config.battery, low_battery_color); + set_colour!(self.high_battery, config.battery, high_battery_colour); + set_colour!(self.medium_battery, config.battery, medium_battery_colour); + set_colour!(self.low_battery, config.battery, low_battery_colour); // Tables set_style!(self.table_header_style, config.tables, headers); // Widget graphs - set_colour!(self.graph_style, config.graphs, graph_color); + set_colour!(self.graph_style, config.graphs, graph_colour); set_style!(self.graph_legend_style, config.graphs, legend_text); // General widget text. - set_bg_colour!(self.general_widget_style, config.widgets, bg_color); + set_bg_colour!(self.general_widget_style, config.widgets, bg_colour); set_style!(self.widget_title_style, config.widgets, widget_title); set_style!(self.text_style, config.widgets, text); set_style!(self.selected_text_style, config.widgets, selected_text); @@ -235,11 +235,11 @@ impl Styles { } // Widget borders - set_colour!(self.border_style, config.widgets, border_color); + set_colour!(self.border_style, config.widgets, border_colour); set_colour!( self.highlighted_border_style, config.widgets, - selected_border_color + selected_border_colour ); if let Some(widgets) = &config.widgets { @@ -258,7 +258,52 @@ mod test { use tui::style::{Color, Style}; use super::Styles; - use crate::options::config::style::utils::str_to_colour; + use crate::options::config::{Config, style::utils::str_to_colour}; + + #[test] + fn color_spelling_aliases_work() { + // Parse all_styling_color.toml (which uses the "color" alias spelling throughout) + // and assert every field was actually parsed. + let toml_str = include_str!("../../../tests/valid_configs/all_styling_color.toml"); + let config = toml_edit::de::from_str::(toml_str) + .expect("config file should parse") + .styles + .expect("styles section should be present"); + + let cpu = config.cpu.as_ref().unwrap(); + assert!(cpu.all_entry_colour.is_some()); + assert!(cpu.avg_entry_colour.is_some()); + assert!(cpu.cpu_core_colours.is_some()); + + let temp = config.temp_graph.as_ref().unwrap(); + assert!(temp.temp_graph_colour_styles.is_some()); + + let mem = config.memory.as_ref().unwrap(); + assert!(mem.ram_colour.is_some()); + assert!(mem.cache_colour.is_some()); + assert!(mem.swap_colour.is_some()); + assert!(mem.arc_colour.is_some()); + assert!(mem.gpu_colours.is_some()); + + let net = config.network.as_ref().unwrap(); + assert!(net.rx_colour.is_some()); + assert!(net.tx_colour.is_some()); + assert!(net.rx_total_colour.is_some()); + assert!(net.tx_total_colour.is_some()); + + let bat = config.battery.as_ref().unwrap(); + assert!(bat.high_battery_colour.is_some()); + assert!(bat.medium_battery_colour.is_some()); + assert!(bat.low_battery_colour.is_some()); + + let graphs = config.graphs.as_ref().unwrap(); + assert!(graphs.graph_colour.is_some()); + + let widgets = config.widgets.as_ref().unwrap(); + assert!(widgets.border_colour.is_some()); + assert!(widgets.selected_border_colour.is_some()); + assert!(widgets.bg_colour.is_some()); + } #[test] fn default_selected_colour_works() { diff --git a/src/options/config/style/battery.rs b/src/options/config/style/battery.rs index aabda3b5..6010a3ef 100644 --- a/src/options/config/style/battery.rs +++ b/src/options/config/style/battery.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use super::ColorStr; +use super::ColourStr; /// Styling specific to the battery widget. #[derive(Clone, Debug, Default, Deserialize, Serialize)] @@ -8,15 +8,15 @@ use super::ColorStr; #[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")] - pub(crate) high_battery_color: Option, + #[serde(alias = "high_battery_color")] + pub(crate) high_battery_colour: Option, /// The colour of the battery widget bar when the battery between 10% to /// 50%. - #[serde(alias = "medium_battery_colour")] - pub(crate) medium_battery_color: Option, + #[serde(alias = "medium_battery_color")] + pub(crate) medium_battery_colour: Option, /// The colour of the battery widget bar when the battery is under 10%. - #[serde(alias = "low_battery_colour")] - pub(crate) low_battery_color: Option, + #[serde(alias = "low_battery_color")] + pub(crate) low_battery_colour: Option, } diff --git a/src/options/config/style/cpu.rs b/src/options/config/style/cpu.rs index 8f63b692..d739e5b6 100644 --- a/src/options/config/style/cpu.rs +++ b/src/options/config/style/cpu.rs @@ -1,8 +1,6 @@ use serde::{Deserialize, Serialize}; -use super::ColorStr; - -// TODO: Use Canadian spelling for colour with an alias for US later instead since internally I use Canadian spelling. +use super::ColourStr; /// Styling specific to the CPU widget. #[derive(Clone, Debug, Default, Deserialize, Serialize)] @@ -10,14 +8,14 @@ use super::ColorStr; #[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")] - pub(crate) all_entry_color: Option, + #[serde(alias = "all_entry_color")] + pub(crate) all_entry_colour: Option, /// The colour of the average CPU label and graph line. - #[serde(alias = "avg_entry_colour")] - pub(crate) avg_entry_color: Option, + #[serde(alias = "avg_entry_color")] + pub(crate) avg_entry_colour: Option, /// Colour of each CPU threads' label and graph line. Read in order. - #[serde(alias = "cpu_core_colours")] - pub(crate) cpu_core_colors: Option>, + #[serde(alias = "cpu_core_colors")] + pub(crate) cpu_core_colours: Option>, } diff --git a/src/options/config/style/graphs.rs b/src/options/config/style/graphs.rs index ce3c37ba..370c2877 100644 --- a/src/options/config/style/graphs.rs +++ b/src/options/config/style/graphs.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use super::{ColorStr, TextStyleConfig}; +use super::{ColourStr, TextStyleConfig}; /// General styling for graph widgets. #[derive(Clone, Debug, Default, Deserialize, Serialize)] @@ -8,8 +8,8 @@ use super::{ColorStr, TextStyleConfig}; #[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")] - pub(crate) graph_color: Option, + #[serde(alias = "graph_color")] + pub(crate) graph_colour: Option, /// Text styling for graph's legend text. pub(crate) legend_text: Option, diff --git a/src/options/config/style/memory.rs b/src/options/config/style/memory.rs index 8dc09338..35f126e1 100644 --- a/src/options/config/style/memory.rs +++ b/src/options/config/style/memory.rs @@ -1,8 +1,6 @@ use serde::{Deserialize, Serialize}; -use super::ColorStr; -// TODO: Maybe I should swap the alias and the field name since internally I use -// u. +use super::ColourStr; /// Styling specific to the memory widget. #[derive(Clone, Debug, Default, Deserialize, Serialize)] @@ -10,24 +8,24 @@ use super::ColorStr; #[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")] - pub(crate) ram_color: Option, + #[serde(alias = "ram_color")] + pub(crate) ram_colour: Option, /// The colour of the cache label and graph line. Does not do anything on /// Windows. #[cfg_attr(target_os = "windows", allow(dead_code))] - #[serde(alias = "cache_colour")] - pub(crate) cache_color: Option, + #[serde(alias = "cache_color")] + pub(crate) cache_colour: Option, /// The colour of the swap label and graph line. - #[serde(alias = "swap_colour")] - pub(crate) swap_color: Option, + #[serde(alias = "swap_color")] + pub(crate) swap_colour: Option, /// The colour of the ARC label and graph line. - #[serde(alias = "arc_colour")] - pub(crate) arc_color: Option, + #[serde(alias = "arc_color")] + pub(crate) arc_colour: Option, /// Colour of each GPU's memory label and graph line. Read in order. - #[serde(alias = "gpu_colours")] - pub(crate) gpu_colors: Option>, + #[serde(alias = "gpu_colors")] + pub(crate) gpu_colours: Option>, } diff --git a/src/options/config/style/network.rs b/src/options/config/style/network.rs index 2b6a2dd8..d48f1d25 100644 --- a/src/options/config/style/network.rs +++ b/src/options/config/style/network.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use super::ColorStr; +use super::ColourStr; /// Styling specific to the network widget. #[derive(Clone, Debug, Default, Deserialize, Serialize)] @@ -8,18 +8,18 @@ use super::ColorStr; #[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")] - pub(crate) rx_color: Option, + #[serde(alias = "rx_color")] + pub(crate) rx_colour: Option, /// The colour of the TX (upload) label and graph line. - #[serde(alias = "tx_colour")] - pub(crate) tx_color: Option, + #[serde(alias = "tx_color")] + pub(crate) tx_colour: Option, - /// he colour of the total RX (download) label in basic mode. - #[serde(alias = "rx_total_colour")] - pub(crate) rx_total_color: Option, + /// The colour of the total RX (download) label in basic mode. + #[serde(alias = "rx_total_color")] + pub(crate) rx_total_colour: Option, /// The colour of the total TX (upload) label in basic mode. - #[serde(alias = "tx_total_colour")] - pub(crate) tx_total_color: Option, + #[serde(alias = "tx_total_color")] + pub(crate) tx_total_colour: Option, } diff --git a/src/options/config/style/temp_graph.rs b/src/options/config/style/temp_graph.rs index 4280f394..5fa3d65e 100644 --- a/src/options/config/style/temp_graph.rs +++ b/src/options/config/style/temp_graph.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use super::ColorStr; +use super::ColourStr; /// Styling specific to the temperature graph widget. #[derive(Clone, Debug, Default, Deserialize, Serialize)] @@ -8,6 +8,6 @@ use super::ColorStr; #[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub(crate) struct TempGraphStyle { /// Colour of each temperature sensor's graph line. Read in order. - #[serde(alias = "temp_graph_colour_styles")] - pub(crate) temp_graph_color_styles: Option>, + #[serde(alias = "temp_graph_color_styles")] + pub(crate) temp_graph_colour_styles: Option>, } diff --git a/src/options/config/style/themes.rs b/src/options/config/style/themes.rs index ad193429..83316269 100644 --- a/src/options/config/style/themes.rs +++ b/src/options/config/style/themes.rs @@ -4,16 +4,16 @@ pub(super) mod default; pub(super) mod gruvbox; pub(super) mod nord; -/// Convert a [`tui::style::Color`] into a [`tui::style::Style`] with the color +/// Convert a [`tui::style::Color`] into a [`tui::style::Style`] with the colour /// as the foreground. -macro_rules! color { +macro_rules! colour { ($value:expr) => { tui::style::Style::new().fg($value) }; } /// Convert a hex string to a [`tui::style::Style`], where the hex string is -/// used as the foreground color. +/// used as the foreground colour. macro_rules! hex { ($value:literal) => { tui::style::Style::new().fg(crate::options::config::style::utils::try_hex_to_colour( @@ -30,6 +30,6 @@ macro_rules! hex_colour { }; } -pub(super) use color; +pub(super) use colour; pub(super) use hex; pub(super) use hex_colour; diff --git a/src/options/config/style/themes/default.rs b/src/options/config/style/themes/default.rs index cd5a30cf..21c609b1 100644 --- a/src/options/config/style/themes/default.rs +++ b/src/options/config/style/themes/default.rs @@ -3,7 +3,7 @@ use tui::{ widgets::BorderType, }; -use super::color; +use super::colour; use crate::options::config::style::Styles; impl Styles { @@ -17,107 +17,107 @@ impl Styles { const HIGHLIGHT_COLOUR: Color = Color::LightBlue; const AVG_COLOUR: Color = Color::Red; const ALL_COLOUR: Color = Color::Green; - const DEFAULT_SELECTED_TEXT_STYLE: Style = color!(Color::Black).bg(HIGHLIGHT_COLOUR); + const DEFAULT_SELECTED_TEXT_STYLE: Style = colour!(Color::Black).bg(HIGHLIGHT_COLOUR); const TEXT_COLOUR: Color = Color::Gray; let list_colours = vec![ - color!(Color::LightMagenta), - color!(Color::LightYellow), - color!(Color::LightCyan), - color!(Color::LightGreen), - color!(Color::LightBlue), - color!(Color::Cyan), - color!(Color::Green), - color!(Color::Blue), + colour!(Color::LightMagenta), + colour!(Color::LightYellow), + colour!(Color::LightCyan), + colour!(Color::LightGreen), + colour!(Color::LightBlue), + colour!(Color::Cyan), + colour!(Color::Green), + colour!(Color::Blue), ]; Self { - ram_style: color!(FIRST_COLOUR), + ram_style: colour!(FIRST_COLOUR), #[cfg(not(target_os = "windows"))] - cache_style: color!(FIFTH_COLOUR), - swap_style: color!(SECOND_COLOUR), + cache_style: colour!(FIFTH_COLOUR), + swap_style: colour!(SECOND_COLOUR), #[cfg(feature = "zfs")] - arc_style: color!(THIRD_COLOUR), + arc_style: colour!(THIRD_COLOUR), #[cfg(feature = "gpu")] gpu_colours: vec![ - color!(FOURTH_COLOUR), - color!(Color::LightBlue), - color!(Color::LightRed), - color!(Color::Cyan), - color!(Color::Green), - color!(Color::Blue), - color!(Color::Red), + colour!(FOURTH_COLOUR), + colour!(Color::LightBlue), + colour!(Color::LightRed), + colour!(Color::Cyan), + colour!(Color::Green), + colour!(Color::Blue), + colour!(Color::Red), ], - rx_style: color!(FIRST_COLOUR), - tx_style: color!(SECOND_COLOUR), - total_rx_style: color!(THIRD_COLOUR), - total_tx_style: color!(FOURTH_COLOUR), - all_cpu_colour: color!(ALL_COLOUR), - avg_cpu_colour: color!(AVG_COLOUR), + rx_style: colour!(FIRST_COLOUR), + tx_style: colour!(SECOND_COLOUR), + total_rx_style: colour!(THIRD_COLOUR), + total_tx_style: colour!(FOURTH_COLOUR), + all_cpu_colour: colour!(ALL_COLOUR), + avg_cpu_colour: colour!(AVG_COLOUR), cpu_colour_styles: list_colours.clone(), temp_graph_colour_styles: list_colours, - border_style: color!(TEXT_COLOUR), - highlighted_border_style: color!(HIGHLIGHT_COLOUR), - text_style: color!(TEXT_COLOUR), + border_style: colour!(TEXT_COLOUR), + highlighted_border_style: colour!(HIGHLIGHT_COLOUR), + text_style: colour!(TEXT_COLOUR), selected_text_style: DEFAULT_SELECTED_TEXT_STYLE, - table_header_style: color!(HIGHLIGHT_COLOUR).add_modifier(Modifier::BOLD), - widget_title_style: color!(TEXT_COLOUR), + table_header_style: colour!(HIGHLIGHT_COLOUR).add_modifier(Modifier::BOLD), + widget_title_style: colour!(TEXT_COLOUR), general_widget_style: Style::default(), - graph_style: color!(TEXT_COLOUR), - graph_legend_style: color!(TEXT_COLOUR), - high_battery: color!(Color::Green), - medium_battery: color!(Color::Yellow), - low_battery: color!(Color::Red), - invalid_query_style: color!(Color::Red), - disabled_text_style: color!(Color::DarkGray), + graph_style: colour!(TEXT_COLOUR), + graph_legend_style: colour!(TEXT_COLOUR), + high_battery: colour!(Color::Green), + medium_battery: colour!(Color::Yellow), + low_battery: colour!(Color::Red), + invalid_query_style: colour!(Color::Red), + disabled_text_style: colour!(Color::DarkGray), border_type: BorderType::Plain, #[cfg(target_os = "linux")] - thread_text_style: color!(Color::Green), + thread_text_style: colour!(Color::Green), } } pub fn default_light_palette() -> Self { let list_colours = vec![ - color!(Color::LightMagenta), - color!(Color::LightBlue), - color!(Color::LightRed), - color!(Color::Cyan), - color!(Color::Green), - color!(Color::Blue), - color!(Color::Red), + colour!(Color::LightMagenta), + colour!(Color::LightBlue), + colour!(Color::LightRed), + colour!(Color::Cyan), + colour!(Color::Green), + colour!(Color::Blue), + colour!(Color::Red), ]; Self { - ram_style: color!(Color::Blue), + ram_style: colour!(Color::Blue), #[cfg(not(target_os = "windows"))] - cache_style: color!(Color::LightRed), - swap_style: color!(Color::Red), + cache_style: colour!(Color::LightRed), + swap_style: colour!(Color::Red), #[cfg(feature = "zfs")] - arc_style: color!(Color::LightBlue), + arc_style: colour!(Color::LightBlue), #[cfg(feature = "gpu")] gpu_colours: vec![ - color!(Color::LightGreen), - color!(Color::LightCyan), - color!(Color::LightRed), - color!(Color::Cyan), - color!(Color::Green), - color!(Color::Blue), - color!(Color::Red), + colour!(Color::LightGreen), + colour!(Color::LightCyan), + colour!(Color::LightRed), + colour!(Color::Cyan), + colour!(Color::Green), + colour!(Color::Blue), + colour!(Color::Red), ], - rx_style: color!(Color::Blue), - tx_style: color!(Color::Red), - total_rx_style: color!(Color::LightBlue), - total_tx_style: color!(Color::LightRed), + rx_style: colour!(Color::Blue), + tx_style: colour!(Color::Red), + total_rx_style: colour!(Color::LightBlue), + total_tx_style: colour!(Color::LightRed), cpu_colour_styles: list_colours.clone(), temp_graph_colour_styles: list_colours, - border_style: color!(Color::Black), - text_style: color!(Color::Black), - selected_text_style: color!(Color::White).bg(Color::LightBlue), - table_header_style: color!(Color::Black).add_modifier(Modifier::BOLD), - widget_title_style: color!(Color::Black), - graph_style: color!(Color::Black), - graph_legend_style: color!(Color::Black), - disabled_text_style: color!(Color::Gray), + border_style: colour!(Color::Black), + text_style: colour!(Color::Black), + selected_text_style: colour!(Color::White).bg(Color::LightBlue), + table_header_style: colour!(Color::Black).add_modifier(Modifier::BOLD), + widget_title_style: colour!(Color::Black), + graph_style: colour!(Color::Black), + graph_legend_style: colour!(Color::Black), + disabled_text_style: colour!(Color::Gray), ..Self::default_palette() } } diff --git a/src/options/config/style/themes/gruvbox.rs b/src/options/config/style/themes/gruvbox.rs index a3e6e7e1..326a191f 100644 --- a/src/options/config/style/themes/gruvbox.rs +++ b/src/options/config/style/themes/gruvbox.rs @@ -3,7 +3,7 @@ use tui::{ widgets::BorderType, }; -use super::{color, hex}; +use super::{colour, hex}; use crate::options::config::style::{Styles, themes::hex_colour}; impl Styles { @@ -68,7 +68,7 @@ impl Styles { high_battery: hex!("#98971a"), medium_battery: hex!("#fabd2f"), low_battery: hex!("#fb4934"), - invalid_query_style: color!(Color::Red), + invalid_query_style: colour!(Color::Red), disabled_text_style: hex!("#665c54"), border_type: BorderType::Plain, #[cfg(target_os = "linux")] @@ -137,7 +137,7 @@ impl Styles { high_battery: hex!("#98971a"), medium_battery: hex!("#d79921"), low_battery: hex!("#cc241d"), - invalid_query_style: color!(Color::Red), + invalid_query_style: colour!(Color::Red), disabled_text_style: hex!("#d5c4a1"), border_type: BorderType::Plain, #[cfg(target_os = "linux")] diff --git a/src/options/config/style/themes/nord.rs b/src/options/config/style/themes/nord.rs index 789e2dae..1174d1b2 100644 --- a/src/options/config/style/themes/nord.rs +++ b/src/options/config/style/themes/nord.rs @@ -3,7 +3,7 @@ use tui::{ widgets::BorderType, }; -use super::{color, hex}; +use super::{colour, hex}; use crate::options::config::style::{Styles, themes::hex_colour}; impl Styles { @@ -56,7 +56,7 @@ impl Styles { high_battery: hex!("#a3be8c"), medium_battery: hex!("#ebcb8b"), low_battery: hex!("#bf616a"), - invalid_query_style: color!(Color::Red), + invalid_query_style: colour!(Color::Red), disabled_text_style: hex!("#4c566a"), border_type: BorderType::Plain, #[cfg(target_os = "linux")] @@ -113,7 +113,7 @@ impl Styles { high_battery: hex!("#a3be8c"), medium_battery: hex!("#ebcb8b"), low_battery: hex!("#bf616a"), - invalid_query_style: color!(Color::Red), + invalid_query_style: colour!(Color::Red), disabled_text_style: hex!("#d8dee9"), border_type: BorderType::Plain, #[cfg(target_os = "linux")] diff --git a/src/options/config/style/utils.rs b/src/options/config/style/utils.rs index 16801625..3259da60 100644 --- a/src/options/config/style/utils.rs +++ b/src/options/config/style/utils.rs @@ -6,12 +6,12 @@ use unicode_segmentation::UnicodeSegmentation; pub(super) fn try_hex_to_colour(hex: &str) -> Result { fn hex_component_to_int(hex: &str, first: &str, second: &str) -> Result { u8::from_str_radix(&concat_string!(first, second), 16) - .map_err(|_| format!("'{hex}' is an invalid hex color, could not decode.")) + .map_err(|_| format!("'{hex}' is an invalid hex colour, could not decode.")) } fn invalid_hex_format(hex: &str) -> String { format!( - "'{hex}' is an invalid hex color. It must be either a 7 character hex string of the form '#12ab3c' or a 3 character hex string of the form '#1a2'.", + "'{hex}' is an invalid hex colour. It must be either a 7 character hex string of the form '#12ab3c' or a 3 character hex string of the form '#1a2'.", ) } @@ -44,7 +44,7 @@ pub fn str_to_colour(input_val: &str) -> Result { if input_val.starts_with('#') { try_hex_to_colour(input_val) } else if input_val.contains(',') { - convert_rgb_to_color(input_val) + convert_rgb_to_colour(input_val) } else { convert_name_to_colour(input_val) } @@ -53,7 +53,7 @@ pub fn str_to_colour(input_val: &str) -> Result { } } -fn convert_rgb_to_color(rgb_str: &str) -> Result { +fn convert_rgb_to_colour(rgb_str: &str) -> Result { let rgb_list = rgb_str.split(',').collect::>(); if rgb_list.len() != 3 { return Err(format!( @@ -75,8 +75,8 @@ fn convert_rgb_to_color(rgb_str: &str) -> Result { } } -fn convert_name_to_colour(color_name: &str) -> Result { - match color_name.to_lowercase().trim() { +fn convert_name_to_colour(colour_name: &str) -> Result { + match colour_name.to_lowercase().trim() { "reset" => Ok(Color::Reset), "black" => Ok(Color::Black), "red" => Ok(Color::Red), @@ -95,9 +95,9 @@ fn convert_name_to_colour(color_name: &str) -> Result { "lightcyan" | "light cyan" => Ok(Color::LightCyan), "white" => Ok(Color::White), _ => Err(format!( - "'{color_name}' is an invalid named color. + "'{colour_name}' is an invalid named colour. -The following are supported named colors: +The following are supported named colours: +--------+-------------+---------------------+ | Reset | Magenta | Light Yellow | +--------+-------------+---------------------+ @@ -112,7 +112,7 @@ The following are supported named colors: | Blue | Light Green | | +--------+-------------+---------------------+ -Alternatively, hex colors or RGB color codes are valid.\n" +Alternatively, hex colours or RGB colour codes are valid.\n" )), } } @@ -144,12 +144,12 @@ macro_rules! set_style { ); } TextStyleConfig::TextStyle { - color, - bg_color, + colour, + bg_colour, bold, italics, } => { - if let Some(fg) = &color { + if let Some(fg) = &colour { $palette_field = $palette_field .fg(crate::options::config::style::utils::str_to_colour( &fg.0, @@ -168,7 +168,7 @@ macro_rules! set_style { })?); } - if let Some(bg) = &bg_color { + if let Some(bg) = &bg_colour { $palette_field = $palette_field .bg(crate::options::config::style::utils::str_to_colour( &bg.0, @@ -291,7 +291,7 @@ mod test { use tui::style::{Modifier, Style}; use super::*; - use crate::options::config::style::{ColorStr, TextStyleConfig}; + use crate::options::config::style::{ColourStr, TextStyleConfig}; #[test] fn general_str_to_colour() { @@ -322,7 +322,7 @@ mod test { #[test] fn valid_colour_names() { - // Standard color should work + // Standard colour should work assert_eq!(convert_name_to_colour("red"), Ok(Color::Red)); // Capitalizing should be fine. @@ -424,18 +424,18 @@ mod test { #[test] fn test_rgb_colours() { assert_eq!( - convert_rgb_to_color("0, 0, 0").unwrap(), + convert_rgb_to_colour("0, 0, 0").unwrap(), Color::Rgb(0, 0, 0) ); assert_eq!( - convert_rgb_to_color("255, 255, 255").unwrap(), + convert_rgb_to_colour("255, 255, 255").unwrap(), Color::Rgb(255, 255, 255) ); - assert!(convert_rgb_to_color("255, 256, 255").is_err()); - assert!(convert_rgb_to_color("256, 0, 256").is_err()); - assert!(convert_rgb_to_color("1, -1, 1").is_err()); - assert!(convert_rgb_to_color("1, -100000, 1").is_err()); - assert!(convert_rgb_to_color("1, -100000, 100000").is_err()); + assert!(convert_rgb_to_colour("255, 256, 255").is_err()); + assert!(convert_rgb_to_colour("256, 0, 256").is_err()); + assert!(convert_rgb_to_colour("1, -1, 1").is_err()); + assert!(convert_rgb_to_colour("1, -100000, 1").is_err()); + assert!(convert_rgb_to_colour("1, -100000, 100000").is_err()); } struct DummyConfig { @@ -443,18 +443,18 @@ mod test { } struct InnerDummyConfig { - color_a: Option, - color_b: Option, - color_c: Option, - color_d: Option, - many_colors: Option>, + color_a: Option, + color_b: Option, + color_c: Option, + color_d: Option, + many_colors: Option>, text_a: Option, text_b: Option, text_c: Option, text_d: Option, text_e: Option, - bad_color: Option, - bad_list: Option>, + bad_color: Option, + bad_list: Option>, bad_text_a: Option, bad_text_b: Option, } @@ -463,45 +463,45 @@ mod test { fn default() -> Self { Self { color_a: None, - color_b: Some(ColorStr("red".into())), - color_c: Some(ColorStr("255, 255, 255".into())), - color_d: Some(ColorStr("#000000".into())), - many_colors: Some(vec![ColorStr("red".into()), ColorStr("blue".into())]), - text_a: Some(TextStyleConfig::Colour(ColorStr("green".into()))), + color_b: Some(ColourStr("red".into())), + color_c: Some(ColourStr("255, 255, 255".into())), + color_d: Some(ColourStr("#000000".into())), + many_colors: Some(vec![ColourStr("red".into()), ColourStr("blue".into())]), + text_a: Some(TextStyleConfig::Colour(ColourStr("green".into()))), text_b: Some(TextStyleConfig::TextStyle { - color: None, - bg_color: None, + colour: None, + bg_colour: None, bold: None, italics: None, }), text_c: Some(TextStyleConfig::TextStyle { - color: Some(ColorStr("magenta".into())), - bg_color: Some(ColorStr("255, 255, 255".into())), + colour: Some(ColourStr("magenta".into())), + bg_colour: Some(ColourStr("255, 255, 255".into())), bold: Some(true), italics: Some(false), }), text_d: Some(TextStyleConfig::TextStyle { - color: Some(ColorStr("#fff".into())), - bg_color: Some(ColorStr("1, 1, 1".into())), + colour: Some(ColourStr("#fff".into())), + bg_colour: Some(ColourStr("1, 1, 1".into())), bold: Some(false), italics: Some(true), }), text_e: None, - bad_color: Some(ColorStr("asdf".into())), + bad_color: Some(ColourStr("asdf".into())), bad_list: Some(vec![ - ColorStr("red".into()), - ColorStr("asdf".into()), - ColorStr("ghi".into()), + ColourStr("red".into()), + ColourStr("asdf".into()), + ColourStr("ghi".into()), ]), bad_text_a: Some(TextStyleConfig::TextStyle { - color: Some(ColorStr("asdf".into())), - bg_color: None, + colour: Some(ColourStr("asdf".into())), + bg_colour: None, bold: None, italics: None, }), bad_text_b: Some(TextStyleConfig::TextStyle { - color: None, - bg_color: Some(ColorStr("asdf".into())), + colour: None, + bg_colour: Some(ColourStr("asdf".into())), bold: None, italics: None, }), diff --git a/src/options/config/style/widgets.rs b/src/options/config/style/widgets.rs index dcedec64..0f169a0d 100644 --- a/src/options/config/style/widgets.rs +++ b/src/options/config/style/widgets.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use super::{ColorStr, TextStyleConfig, borders::WidgetBorderType}; +use super::{ColourStr, TextStyleConfig, borders::WidgetBorderType}; /// General styling for generic widgets. #[derive(Clone, Debug, Default, Deserialize, Serialize)] @@ -8,12 +8,12 @@ use super::{ColorStr, TextStyleConfig, borders::WidgetBorderType}; #[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))] pub(crate) struct WidgetStyle { /// The colour of the widgets' borders. - #[serde(alias = "border_colour")] - pub(crate) border_color: Option, + #[serde(alias = "border_color")] + pub(crate) border_colour: Option, /// The colour of a widget's borders when the widget is selected. - #[serde(alias = "selected_border_colour")] - pub(crate) selected_border_color: Option, + #[serde(alias = "selected_border_color")] + pub(crate) selected_border_colour: Option, /// Text styling for a widget's title. pub(crate) widget_title: Option, @@ -34,6 +34,7 @@ pub(crate) struct WidgetStyle { /// Widget borders type. pub(crate) widget_border_type: Option, - /// Background color for widgets. - pub(crate) bg_color: Option, + /// Background colour for widgets. + #[serde(alias = "bg_color")] + pub(crate) bg_colour: Option, } diff --git a/src/widgets/process_table/process_data.rs b/src/widgets/process_table/process_data.rs index 0ed6ab92..61587fcf 100644 --- a/src/widgets/process_table/process_data.rs +++ b/src/widgets/process_table/process_data.rs @@ -11,6 +11,8 @@ use concat_string::concat_string; use tui::widgets::Row; use super::process_columns::ProcColumn; +#[cfg(target_os = "linux")] +use crate::collection::processes::ProcessType; use crate::{ canvas::{ Painter, @@ -215,9 +217,9 @@ pub struct ProcWidgetData { pub gpu_mem_usage: MemUsage, #[cfg(feature = "gpu")] pub gpu_usage: u32, - /// The process "type". Used to color things. + /// The process "type". Used to colour things. #[cfg(target_os = "linux")] - pub process_type: crate::collection::processes::ProcessType, + pub process_type: ProcessType, #[cfg(unix)] pub nice: i32, pub priority: i32, diff --git a/tests/integration/invalid_config_tests.rs b/tests/integration/invalid_config_tests.rs index 09ab04dd..1b061ddf 100644 --- a/tests/integration/invalid_config_tests.rs +++ b/tests/integration/invalid_config_tests.rs @@ -48,7 +48,7 @@ fn test_invalid_colour_hex() { btm_command(&["-C", "./tests/invalid_configs/invalid_colour_hex.toml"]) .assert() .failure() - .stderr(predicate::str::contains("invalid hex color")); + .stderr(predicate::str::contains("invalid hex colour")); } /// Checks for if a hex is too long @@ -57,7 +57,7 @@ fn test_invalid_colour_hex_2() { btm_command(&["-C", "./tests/invalid_configs/invalid_colour_hex_2.toml"]) .assert() .failure() - .stderr(predicate::str::contains("invalid hex color")); + .stderr(predicate::str::contains("invalid hex colour")); } /// Checks unicode hex because the way we originally did it could cause char @@ -67,7 +67,7 @@ fn test_invalid_colour_hex_3() { btm_command(&["-C", "./tests/invalid_configs/invalid_colour_hex_3.toml"]) .assert() .failure() - .stderr(predicate::str::contains("invalid hex color")); + .stderr(predicate::str::contains("invalid hex colour")); } #[test] @@ -75,7 +75,7 @@ fn test_invalid_colour_name() { btm_command(&["-C", "./tests/invalid_configs/invalid_colour_name.toml"]) .assert() .failure() - .stderr(predicate::str::contains("invalid named color")); + .stderr(predicate::str::contains("invalid named colour")); } #[test] @@ -99,7 +99,7 @@ fn test_invalid_colour_string() { btm_command(&["-C", "./tests/invalid_configs/invalid_colour_string.toml"]) .assert() .failure() - .stderr(predicate::str::contains("invalid named color")); + .stderr(predicate::str::contains("invalid named colour")); } #[test] diff --git a/tests/integration/valid_config_tests.rs b/tests/integration/valid_config_tests.rs index fb693de2..501089a0 100644 --- a/tests/integration/valid_config_tests.rs +++ b/tests/integration/valid_config_tests.rs @@ -177,7 +177,12 @@ fn test_styling_sanity_check() { #[test] fn test_styling_sanity_check_2() { - run_and_kill(&["-C", "./tests/valid_configs/styling_2.toml"]); + run_and_kill(&["-C", "./tests/valid_configs/all_styling.toml"]); +} + +#[test] +fn test_color_spelling_is_valid() { + run_and_kill(&["-C", "./tests/valid_configs/all_styling_color.toml"]); } #[test] diff --git a/tests/valid_configs/all_styling.toml b/tests/valid_configs/all_styling.toml new file mode 100644 index 00000000..75791e04 --- /dev/null +++ b/tests/valid_configs/all_styling.toml @@ -0,0 +1,66 @@ +# These are all the components that support custom theming. Note that colour support +# will depend on terminal support. +[styles] + +# Built-in themes. Valid values are: +# - "default" +# - "default-light" +# - "gruvbox" +# - "gruvbox-light" +# - "nord" +# - "nord-light". + +# This will have the lowest precedence if a custom colour palette is set, +# or overridden if the command-line flag for a built-in theme is set. +theme = "default" + +[styles.cpu] +all_entry_colour = "green" +avg_entry_colour = "red" +cpu_core_colours = ["light magenta", "light yellow", "light cyan", "light green", "light blue", "cyan", "green", "blue"] + +[styles.temp_graph] +temp_graph_colour_styles = [ + "light magenta", + "light yellow", + "light cyan", + "light green", + "light blue", + "cyan", + "green", + "blue", +] + +[styles.memory] +ram_colour = "light magenta" +cache_colour = "light red" +swap_colour = "light yellow" +arc_colour = "light cyan" +gpu_colours = ["light blue", "light red", "cyan", "green", "blue", "red"] + +[styles.network] +rx_colour = "light magenta" +tx_colour = "light yellow" +rx_total_colour = "light cyan" +tx_total_colour = "light green" + +[styles.battery] +high_battery_colour = "green" +medium_battery_colour = "yellow" +low_battery_colour = "red" + +[styles.tables] +headers = { colour = "light blue" } + +[styles.graphs] +graph_colour = "gray" +legend_text = { colour = "gray" } + +[styles.widgets] +border_colour = "gray" +selected_border_colour = "light blue" +widget_title = { colour = "gray" } +text = { colour = "gray" } +selected_text = { colour = "black", bg_colour = "light blue" } +disabled_text = { colour = "dark gray" } +bg_colour = "black" diff --git a/tests/valid_configs/styling_2.toml b/tests/valid_configs/all_styling_color.toml similarity index 75% rename from tests/valid_configs/styling_2.toml rename to tests/valid_configs/all_styling_color.toml index b2c069d6..9333fc77 100644 --- a/tests/valid_configs/styling_2.toml +++ b/tests/valid_configs/all_styling_color.toml @@ -1,4 +1,6 @@ -# These are all the components that support custom theming. Note that colour support +# Styling but we use "color" everywhere. + +# These are all the components that support custom theming. Note that color support # will depend on terminal support. [styles] @@ -10,7 +12,7 @@ # - "nord" # - "nord-light". -# This will have the lowest precedence if a custom colour palette is set, +# This will have the lowest precedence if a custom color palette is set, # or overridden if the command-line flag for a built-in theme is set. theme = "default" @@ -19,6 +21,18 @@ all_entry_color = "green" avg_entry_color = "red" cpu_core_colors = ["light magenta", "light yellow", "light cyan", "light green", "light blue", "cyan", "green", "blue"] +[styles.temp_graph] +temp_graph_color_styles = [ + "light magenta", + "light yellow", + "light cyan", + "light green", + "light blue", + "cyan", + "green", + "blue", +] + [styles.memory] ram_color = "light magenta" cache_color = "light red" @@ -51,3 +65,4 @@ widget_title = { color = "gray" } text = { color = "gray" } selected_text = { color = "black", bg_color = "light blue" } disabled_text = { color = "dark gray" } +bg_color = "black" diff --git a/tests/valid_configs/os_specific/linux.toml b/tests/valid_configs/os_specific/linux.toml index f1470cdc..8dcdda6c 100644 --- a/tests/valid_configs/os_specific/linux.toml +++ b/tests/valid_configs/os_specific/linux.toml @@ -1,4 +1,4 @@ # Remove things from this if they are no longer OS-specific. [styles.widgets] -thread_text = { color = "green" } +thread_text = { colour = "green" }