refactor: refactor some fields and code to use "colour" spelling (#2058)

<!-- Please use this template (unless you have a very good reason not
to). PRs that do not use the template may be closed. -->

## Description

_A description of the change, what it does, and why it was made. If
relevant (e.g. UI changes), **please also provide
screenshots/recordings**:_

Rename a bunch of code/struct field names to use "colour". Note this
should have no functional change to config settings as I was already
aliasing "colour" for "color" settings, this just flips it internally.

As for why, I'm Canadian, I grew up spelling it this way, sorry.

## Issue

_If applicable, what issue does this address?_

Closes: #<issue-number>

## Testing

_If relevant, please state how this was tested (including steps):_

_If this change affects the program, please also indicate which
platforms were tested:_

- [ ] _Windows_
- [ ] _macOS (specify version below)_
- [x] _Linux (specify distro below)_
- [ ] _Other (specify below)_

## Checklist

_Ensure **all** of these are met:_

- [x] _If this PR adds or changes a dependency, please justify this in
the description_
- [x] _If this is a code change, areas your change affects have been
linted using (`cargo fmt`)_
- [x] _If this is a code change, your changes pass `cargo clippy --all
-- -D warnings`_
- [x] _If this is a code change, new tests were added if relevant_
- [x] _If this is a code change, your changes pass `cargo test`_
- [x] _The change has been tested to work (see above) and doesn't appear
to break other things_
- [x] _Documentation has been updated if needed (`README.md`, help menu,
docs, configs, etc.)_
- [x] _There are no merge conflicts_
- [x] _You have reviewed your changes first_
- [x] _The pull request passes the provided CI pipeline_

## Other

_Anything else that maintainers should know about this PR:_
This commit is contained in:
Clement Tsang
2026-05-08 01:34:02 -04:00
committed by GitHub
parent abad5b6f1e
commit d08036f69a
29 changed files with 510 additions and 349 deletions
+1 -1
View File
@@ -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.
+30 -27
View File
@@ -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.
+3 -1
View File
@@ -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),
};
+4 -4
View File
@@ -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)"
}
)]
+76 -31
View File
@@ -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<ColorStr>,
#[serde(alias = "color")]
colour: Option<ColourStr>,
/// A built-in ANSI colour, RGB hex, or RGB colour code.
#[serde(alias = "bg_colour")]
bg_color: Option<ColorStr>,
#[serde(alias = "bg_color")]
bg_colour: Option<ColourStr>,
/// 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::<Config>(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() {
+7 -7
View File
@@ -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<ColorStr>,
#[serde(alias = "high_battery_color")]
pub(crate) high_battery_colour: Option<ColourStr>,
/// 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<ColorStr>,
#[serde(alias = "medium_battery_color")]
pub(crate) medium_battery_colour: Option<ColourStr>,
/// The colour of the battery widget bar when the battery is under 10%.
#[serde(alias = "low_battery_colour")]
pub(crate) low_battery_color: Option<ColorStr>,
#[serde(alias = "low_battery_color")]
pub(crate) low_battery_colour: Option<ColourStr>,
}
+7 -9
View File
@@ -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<ColorStr>,
#[serde(alias = "all_entry_color")]
pub(crate) all_entry_colour: Option<ColourStr>,
/// The colour of the average CPU label and graph line.
#[serde(alias = "avg_entry_colour")]
pub(crate) avg_entry_color: Option<ColorStr>,
#[serde(alias = "avg_entry_color")]
pub(crate) avg_entry_colour: Option<ColourStr>,
/// Colour of each CPU threads' label and graph line. Read in order.
#[serde(alias = "cpu_core_colours")]
pub(crate) cpu_core_colors: Option<Vec<ColorStr>>,
#[serde(alias = "cpu_core_colors")]
pub(crate) cpu_core_colours: Option<Vec<ColourStr>>,
}
+3 -3
View File
@@ -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<ColorStr>,
#[serde(alias = "graph_color")]
pub(crate) graph_colour: Option<ColourStr>,
/// Text styling for graph's legend text.
pub(crate) legend_text: Option<TextStyleConfig>,
+11 -13
View File
@@ -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<ColorStr>,
#[serde(alias = "ram_color")]
pub(crate) ram_colour: Option<ColourStr>,
/// 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<ColorStr>,
#[serde(alias = "cache_color")]
pub(crate) cache_colour: Option<ColourStr>,
/// The colour of the swap label and graph line.
#[serde(alias = "swap_colour")]
pub(crate) swap_color: Option<ColorStr>,
#[serde(alias = "swap_color")]
pub(crate) swap_colour: Option<ColourStr>,
/// The colour of the ARC label and graph line.
#[serde(alias = "arc_colour")]
pub(crate) arc_color: Option<ColorStr>,
#[serde(alias = "arc_color")]
pub(crate) arc_colour: Option<ColourStr>,
/// Colour of each GPU's memory label and graph line. Read in order.
#[serde(alias = "gpu_colours")]
pub(crate) gpu_colors: Option<Vec<ColorStr>>,
#[serde(alias = "gpu_colors")]
pub(crate) gpu_colours: Option<Vec<ColourStr>>,
}
+10 -10
View File
@@ -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<ColorStr>,
#[serde(alias = "rx_color")]
pub(crate) rx_colour: Option<ColourStr>,
/// The colour of the TX (upload) label and graph line.
#[serde(alias = "tx_colour")]
pub(crate) tx_color: Option<ColorStr>,
#[serde(alias = "tx_color")]
pub(crate) tx_colour: Option<ColourStr>,
/// he colour of the total RX (download) label in basic mode.
#[serde(alias = "rx_total_colour")]
pub(crate) rx_total_color: Option<ColorStr>,
/// The colour of the total RX (download) label in basic mode.
#[serde(alias = "rx_total_color")]
pub(crate) rx_total_colour: Option<ColourStr>,
/// The colour of the total TX (upload) label in basic mode.
#[serde(alias = "tx_total_colour")]
pub(crate) tx_total_color: Option<ColorStr>,
#[serde(alias = "tx_total_color")]
pub(crate) tx_total_colour: Option<ColourStr>,
}
+3 -3
View File
@@ -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<Vec<ColorStr>>,
#[serde(alias = "temp_graph_color_styles")]
pub(crate) temp_graph_colour_styles: Option<Vec<ColourStr>>,
}
+4 -4
View File
@@ -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;
+70 -70
View File
@@ -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()
}
}
+3 -3
View File
@@ -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")]
+3 -3
View File
@@ -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")]
+48 -48
View File
@@ -6,12 +6,12 @@ use unicode_segmentation::UnicodeSegmentation;
pub(super) fn try_hex_to_colour(hex: &str) -> Result<Color, String> {
fn hex_component_to_int(hex: &str, first: &str, second: &str) -> Result<u8, String> {
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<Color, String> {
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<Color, String> {
}
}
fn convert_rgb_to_color(rgb_str: &str) -> Result<Color, String> {
fn convert_rgb_to_colour(rgb_str: &str) -> Result<Color, String> {
let rgb_list = rgb_str.split(',').collect::<Vec<&str>>();
if rgb_list.len() != 3 {
return Err(format!(
@@ -75,8 +75,8 @@ fn convert_rgb_to_color(rgb_str: &str) -> Result<Color, String> {
}
}
fn convert_name_to_colour(color_name: &str) -> Result<Color, String> {
match color_name.to_lowercase().trim() {
fn convert_name_to_colour(colour_name: &str) -> Result<Color, String> {
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<Color, String> {
"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<ColorStr>,
color_b: Option<ColorStr>,
color_c: Option<ColorStr>,
color_d: Option<ColorStr>,
many_colors: Option<Vec<ColorStr>>,
color_a: Option<ColourStr>,
color_b: Option<ColourStr>,
color_c: Option<ColourStr>,
color_d: Option<ColourStr>,
many_colors: Option<Vec<ColourStr>>,
text_a: Option<TextStyleConfig>,
text_b: Option<TextStyleConfig>,
text_c: Option<TextStyleConfig>,
text_d: Option<TextStyleConfig>,
text_e: Option<TextStyleConfig>,
bad_color: Option<ColorStr>,
bad_list: Option<Vec<ColorStr>>,
bad_color: Option<ColourStr>,
bad_list: Option<Vec<ColourStr>>,
bad_text_a: Option<TextStyleConfig>,
bad_text_b: Option<TextStyleConfig>,
}
@@ -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,
}),
+8 -7
View File
@@ -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<ColorStr>,
#[serde(alias = "border_color")]
pub(crate) border_colour: Option<ColourStr>,
/// The colour of a widget's borders when the widget is selected.
#[serde(alias = "selected_border_colour")]
pub(crate) selected_border_color: Option<ColorStr>,
#[serde(alias = "selected_border_color")]
pub(crate) selected_border_colour: Option<ColourStr>,
/// Text styling for a widget's title.
pub(crate) widget_title: Option<TextStyleConfig>,
@@ -34,6 +34,7 @@ pub(crate) struct WidgetStyle {
/// Widget borders type.
pub(crate) widget_border_type: Option<WidgetBorderType>,
/// Background color for widgets.
pub(crate) bg_color: Option<ColorStr>,
/// Background colour for widgets.
#[serde(alias = "bg_color")]
pub(crate) bg_colour: Option<ColourStr>,
}
+4 -2
View File
@@ -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,