summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClementTsang <34804052+ClementTsang@users.noreply.github.com>2024-01-23 01:59:18 -0500
committerClementTsang <34804052+ClementTsang@users.noreply.github.com>2024-02-19 20:08:53 -0500
commit555ef9fd642afbb615706365c43c49ffb6d003fe (patch)
tree7c26b4eb9182b0f55968ab322d7b398684709698
parent51b0740dd118131a89f6205b610e6760b34574d4 (diff)
refactor: move around a bunch of config code, start grouping changes
TODO: Update built-in configs! TODO: Update docs; add section for config file
-rw-r--r--src/canvas/styling.rs7
-rw-r--r--src/constants.rs256
-rw-r--r--src/options.rs12
-rw-r--r--src/options/config.rs90
-rw-r--r--src/options/config/battery.rs6
-rw-r--r--src/options/config/cpu.rs6
-rw-r--r--src/options/config/general.rs21
-rw-r--r--src/options/config/gpu.rs6
-rw-r--r--src/options/config/ignore_list.rs21
-rw-r--r--src/options/config/memory.rs7
-rw-r--r--src/options/config/network.rs9
-rw-r--r--src/options/config/process.rs (renamed from src/options/config/process_columns.rs)30
-rw-r--r--src/options/config/style.rs9
-rw-r--r--src/options/config/style/colours.rs (renamed from src/options/colours.rs)4
-rw-r--r--src/options/config/style/palettes.rs255
-rw-r--r--src/options/config/temperature.rs6
16 files changed, 415 insertions, 330 deletions
diff --git a/src/canvas/styling.rs b/src/canvas/styling.rs
index 88273352..47aa1846 100644
--- a/src/canvas/styling.rs
+++ b/src/canvas/styling.rs
@@ -6,7 +6,10 @@ use tui::style::{Color, Style};
use super::ColourScheme;
pub use crate::options::Config;
-use crate::{constants::*, options::colours::ConfigColours, utils::error};
+use crate::{
+ options::config::{colours::ColourConfig, palettes::*},
+ utils::error,
+};
pub struct CanvasStyling {
pub currently_selected_text_colour: Color,
@@ -154,7 +157,7 @@ impl CanvasStyling {
Ok(canvas_colours)
}
- pub fn set_colours_from_palette(&mut self, colours: &ConfigColours) -> anyhow::Result<()> {
+ pub fn set_colours_from_palette(&mut self, colours: &ColourConfig) -> anyhow::Result<()> {
// CPU
try_set_colour!(self.avg_colour_style, colours, avg_cpu_color);
try_set_colour!(self.all_colour_style, colours, all_cpu_color);
diff --git a/src/constants.rs b/src/constants.rs
index eb185779..2c8742d9 100644
--- a/src/constants.rs
+++ b/src/constants.rs
@@ -1,7 +1,5 @@
use tui::widgets::Borders;
-use crate::options::ConfigColours;
-
// Default widget ID
pub const DEFAULT_WIDGET_ID: u64 = 56709;
@@ -23,260 +21,6 @@ pub const TIME_LABEL_HEIGHT_LIMIT: u16 = 7;
// Side borders
pub const SIDE_BORDERS: Borders = Borders::LEFT.union(Borders::RIGHT);
-// Colour profiles
-// TODO: Generate these with a macro or something...
-pub fn default_light_mode_colour_palette() -> ConfigColours {
- ConfigColours {
- text_color: Some("black".into()),
- border_color: Some("black".into()),
- table_header_color: Some("black".into()),
- widget_title_color: Some("black".into()),
- selected_text_color: Some("white".into()),
- graph_color: Some("black".into()),
- disabled_text_color: Some("gray".into()),
- ram_color: Some("blue".into()),
- #[cfg(not(target_os = "windows"))]
- cache_color: Some("LightRed".into()),
- swap_color: Some("red".into()),
- arc_color: Some("LightBlue".into()),
- gpu_core_colors: Some(vec![
- "LightGreen".into(),
- "LightCyan".into(),
- "LightRed".into(),
- "Cyan".into(),
- "Green".into(),
- "Blue".into(),
- "Red".into(),
- ]),
- rx_color: Some("blue".into()),
- tx_color: Some("red".into()),
- rx_total_color: Some("LightBlue".into()),
- tx_total_color: Some("LightRed".into()),
- cpu_core_colors: Some(vec![
- "LightMagenta".into(),
- "LightBlue".into(),
- "LightRed".into(),
- "Cyan".into(),
- "Green".into(),
- "Blue".into(),
- "Red".into(),
- ]),
- ..ConfigColours::default()
- }
-}
-
-pub fn gruvbox_colour_palette() -> ConfigColours {
- ConfigColours {
- table_header_color: Some("#83a598".into()),
- all_cpu_color: Some("#8ec07c".into()),
- avg_cpu_color: Some("#fb4934".into()),
- cpu_core_colors: Some(vec![
- "#cc241d".into(),
- "#98971a".into(),
- "#d79921".into(),
- "#458588".into(),
- "#b16286".into(),
- "#689d6a".into(),
- "#fe8019".into(),
- "#b8bb26".into(),
- "#fabd2f".into(),
- "#83a598".into(),
- "#d3869b".into(),
- "#d65d0e".into(),
- "#9d0006".into(),
- "#79740e".into(),
- "#b57614".into(),
- "#076678".into(),
- "#8f3f71".into(),
- "#427b58".into(),
- "#d65d03".into(),
- "#af3a03".into(),
- ]),
- ram_color: Some("#8ec07c".into()),
- #[cfg(not(target_os = "windows"))]
- cache_color: Some("#b16286".into()),
- swap_color: Some("#fabd2f".into()),
- arc_color: Some("#689d6a".into()),
- gpu_core_colors: Some(vec![
- "#d79921".into(),
- "#458588".into(),
- "#b16286".into(),
- "#fe8019".into(),
- "#b8bb26".into(),
- "#cc241d".into(),
- "#98971a".into(),
- ]),
- rx_color: Some("#8ec07c".into()),
- tx_color: Some("#fabd2f".into()),
- rx_total_color: Some("#689d6a".into()),
- tx_total_color: Some("#d79921".into()),
- border_color: Some("#ebdbb2".into()),
- highlighted_border_color: Some("#fe8019".into()),
- disabled_text_color: Some("#665c54".into()),
- text_color: Some("#ebdbb2".into()),
- selected_text_color: Some("#1d2021".into()),
- selected_bg_color: Some("#ebdbb2".into()),
- widget_title_color: Some("#ebdbb2".into()),
- graph_color: Some("#ebdbb2".into()),
- high_battery_color: Some("#98971a".into()),
- medium_battery_color: Some("#fabd2f".into()),
- low_battery_color: Some("#fb4934".into()),
- }
-}
-
-pub fn gruvbox_light_colour_palette() -> ConfigColours {
- ConfigColours {
- table_header_color: Some("#076678".into()),
- all_cpu_color: Some("#8ec07c".into()),
- avg_cpu_color: Some("#fb4934".into()),
- cpu_core_colors: Some(vec![
- "#cc241d".into(),
- "#98971a".into(),
- "#d79921".into(),
- "#458588".into(),
- "#b16286".into(),
- "#689d6a".into(),
- "#fe8019".into(),
- "#b8bb26".into(),
- "#fabd2f".into(),
- "#83a598".into(),
- "#d3869b".into(),
- "#d65d0e".into(),
- "#9d0006".into(),
- "#79740e".into(),
- "#b57614".into(),
- "#076678".into(),
- "#8f3f71".into(),
- "#427b58".into(),
- "#d65d03".into(),
- "#af3a03".into(),
- ]),
- ram_color: Some("#427b58".into()),
- #[cfg(not(target_os = "windows"))]
- cache_color: Some("#d79921".into()),
- swap_color: Some("#cc241d".into()),
- arc_color: Some("#689d6a".into()),
- gpu_core_colors: Some(vec![
- "#9d0006".into(),
- "#98971a".into(),
- "#d79921".into(),
- "#458588".into(),
- "#b16286".into(),
- "#fe8019".into(),
- "#b8bb26".into(),
- ]),
- rx_color: Some("#427b58".into()),
- tx_color: Some("#cc241d".into()),
- rx_total_color: Some("#689d6a".into()),
- tx_total_color: Some("#9d0006".into()),
- border_color: Some("#3c3836".into()),
- highlighted_border_color: Some("#af3a03".into()),
- disabled_text_color: Some("#d5c4a1".into()),
- text_color: Some("#3c3836".into()),
- selected_text_color: Some("#ebdbb2".into()),
- selected_bg_color: Some("#3c3836".into()),
- widget_title_color: Some("#3c3836".into()),
- graph_color: Some("#3c3836".into()),
- high_battery_color: Some("#98971a".into()),
- medium_battery_color: Some("#d79921".into()),
- low_battery_color: Some("#cc241d".into()),
- }
-}
-
-pub fn nord_colour_palette() -> ConfigColours {
- ConfigColours {
- table_header_color: Some("#81a1c1".into()),
- all_cpu_color: Some("#88c0d0".into()),
- avg_cpu_color: Some("#8fbcbb".into()),
- cpu_core_colors: Some(vec![
- "#5e81ac".into(),
- "#81a1c1".into(),
- "#d8dee9".into(),
- "#b48ead".into(),
- "#a3be8c".into(),
- "#ebcb8b".into(),
- "#d08770".into(),
- "#bf616a".into(),
- ]),
- ram_color: Some("#88c0d0".into()),
- #[cfg(not(target_os = "windows"))]
- cache_color: Some("#d8dee9".into()),
- swap_color: Some("#d08770".into()),
- arc_color: Some("#5e81ac".into()),
- gpu_core_colors: Some(vec![
- "#8fbcbb".into(),
- "#81a1c1".into(),
- "#d8dee9".into(),
- "#b48ead".into(),
- "#a3be8c".into(),
- "#ebcb8b".into(),
- "#bf616a".into(),
- ]),
- rx_color: Some("#88c0d0".into()),
- tx_color: Some("#d08770".into()),
- rx_total_color: Some("#5e81ac".into()),
- tx_total_color: Some("#8fbcbb".into()),
- border_color: Some("#88c0d0".into()),
- highlighted_border_color: Some("#5e81ac".into()),
- disabled_text_color: Some("#4c566a".into()),
- text_color: Some("#e5e9f0".into()),
- selected_text_color: Some("#2e3440".into()),
- selected_bg_color: Some("#88c0d0".into()),
- widget_title_color: Some("#e5e9f0".into()),
- graph_color: Some("#e5e9f0".into()),
- high_battery_color: Some("#a3be8c".into()),
- medium_battery_color: Some("#ebcb8b".into()),
- low_battery_color: Some("#bf616a".into()),
- }
-}
-
-pub fn nord_light_colour_palette() -> ConfigColours {
- ConfigColours {
- table_header_color: Some("#5e81ac".into()),
- all_cpu_color: Some("#81a1c1".into()),
- avg_cpu_color: Some("#8fbcbb".into()),
- cpu_core_colors: Some(vec![
- "#5e81ac".into(),
- "#88c0d0".into(),
- "#4c566a".into(),
- "#b48ead".into(),
- "#a3be8c".into(),
- "#ebcb8b".into(),
- "#d08770".into(),
- "#bf616a".into(),
- ]),
- ram_color: Some("#81a1c1".into()),
- #[cfg(not(target_os = "windows"))]
- cache_color: Some("#4c566a".into()),
- swap_color: Some("#d08770".into()),
- arc_color: Some("#5e81ac".into()),
- gpu_core_colors: Some(vec![
- "#8fbcbb".into(),
- "#88c0d0".into(),
- "#4c566a".into(),
- "#b48ead".into(),
- "#a3be8c".into(),
- "#ebcb8b".into(),
- "#bf616a".into(),
- ]),
- rx_color: Some("#81a1c1".into()),
- tx_color: Some("#d08770".into()),
- rx_total_color: Some("#5e81ac".into()),
- tx_total_color: Some("#8fbcbb".into()),
- border_color: Some("#2e3440".into()),
- highlighted_border_color: Some("#5e81ac".into()),
- disabled_text_color: Some("#d8dee9".into()),
- text_color: Some("#2e3440".into()),
- selected_text_color: Some("#f5f5f5".into()),
- selected_bg_color: Some("#5e81ac".into()),
- widget_title_color: Some("#2e3440".into()),
- graph_color: Some("#2e3440".into()),
- high_battery_color: Some("#a3be8c".into()),
- medium_battery_color: Some("#ebcb8b".into()),
- low_battery_color: Some("#bf616a".into()),
- }
-}
-
// Help text
pub const HELP_CONTENTS_TEXT: [&str; 10] = [
"Either scroll or press the number key to go to the corresponding help menu section:",
diff --git a/src/options.rs b/src/options.rs
index 902c5c87..4ce31b65 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -3,7 +3,6 @@
// TODO: Break this apart or do something a bit smarter.
pub mod args;
-pub mod colours;
pub mod config;
use std::{
@@ -14,7 +13,6 @@ use std::{
use anyhow::{Context, Result};
use clap::ArgMatches;
-pub use colours::ConfigColours;
use hashbrown::{HashMap, HashSet};
use indexmap::IndexSet;
use regex::Regex;
@@ -112,14 +110,14 @@ pub fn init_app(
let network_use_binary_prefix = is_flag_enabled!(network_use_binary_prefix, matches, config);
let proc_columns: Option<IndexSet<ProcWidgetColumn>> = {
- let columns = config.processes.as_ref().map(|cfg| cfg.columns.clone());
+ let columns = config.processes.columns.as_ref();
match columns {
Some(columns) => {
if columns.is_empty() {
None
} else {
- Some(IndexSet::from_iter(columns))
+ Some(IndexSet::from_iter(columns.clone()))
}
}
None => None,
@@ -208,11 +206,7 @@ pub fn init_app(
widget.widget_id,
CpuWidgetState::new(
&app_config_fields,
- config
- .cpu
- .as_ref()
- .map(|cfg| cfg.default)
- .unwrap_or_default(),
+ config.cpu.default,
default_time_value,
autohide_timer,
styling,
diff --git a/src/options/config.rs b/src/options/config.rs
index d787c0ec..df767ad7 100644
--- a/src/options/config.rs
+++ b/src/options/config.rs
@@ -1,41 +1,55 @@
+pub mod battery;
pub mod cpu;
-mod ignore_list;
+pub mod general;
+pub mod gpu;
pub mod layout;
-pub mod process_columns;
+pub mod memory;
+pub mod network;
+pub mod process;
+mod style;
+pub mod temperature;
-use serde::{Deserialize, Serialize};
+use serde::Deserialize;
+pub use style::*;
-pub use self::ignore_list::IgnoreList;
-use self::{cpu::CpuConfig, layout::Row, process_columns::ProcessConfig};
+use self::{colours::ColourConfig, cpu::CpuConfig, layout::Row, process::ProcessConfig};
-use super::ConfigColours;
-
-// #[derive(Debug, Deserialize)]
-// pub struct NewConfig {
-// pub(crate) disk_filter: Option<IgnoreList>,
-// pub(crate) mount_filter: Option<IgnoreList>,
-// pub(crate) temp_filter: Option<IgnoreList>,
-// pub(crate) net_filter: Option<IgnoreList>,
-// #[serde(default)]
-// pub(crate) processes: ProcessConfig,
-// #[serde(default)]
-// pub(crate) cpu: CpuConfig,
-// }
-
-#[derive(Clone, Debug, Default, Deserialize)]
+#[derive(Debug, Default, Deserialize)]
pub struct Config {
- pub(crate) flags: Option<ConfigFlags>,
- pub(crate) colors: Option<ConfigColours>,
+ // #[serde(default)]
+ // pub(crate) general_options: GeneralOptions,
+ // #[serde(default)]
+ // pub(crate) process_options: ProcessOptions,
+ // #[serde(default)]
+ // pub(crate) temperature_options: TemperatureOptions,
+ // #[serde(default)]
+ // pub(crate) cpu_options: CpuOptions,
+ // #[serde(default)]
+ // pub(crate) memory_options: MemoryOptions,
+ // #[serde(default)]
+ // pub(crate) network_options: NetworkOptions,
+ // #[serde(default)]
+ // pub(crate) battery_options: BatteryOptions,
+ // #[serde(default)]
+ // pub(crate) gpu_options: GpuOptions,
+ // #[serde(default)]
+ // pub(crate) style_options: StyleOptions,
+ pub flags: Option<ConfigFlags>,
+
+ // TODO: Merge these into above!
+ pub(crate) colors: Option<ColourConfig>,
pub(crate) row: Option<Vec<Row>>,
pub(crate) disk_filter: Option<IgnoreList>,
pub(crate) mount_filter: Option<IgnoreList>,
pub(crate) temp_filter: Option<IgnoreList>,
pub(crate) net_filter: Option<IgnoreList>,
- pub(crate) processes: Option<ProcessConfig>,
- pub(crate) cpu: Option<CpuConfig>,
+ #[serde(default)]
+ pub(crate) processes: ProcessConfig,
+ #[serde(default)]
+ pub(crate) cpu: CpuConfig,
}
-#[derive(Clone, Debug, Deserialize, Serialize)]
+#[derive(Clone, Debug, Deserialize)]
#[serde(untagged)]
pub(crate) enum StringOrNum {
String(String),
@@ -54,8 +68,28 @@ impl From<u64> for StringOrNum {
}
}
-#[derive(Clone, Debug, Default, Deserialize, Serialize)]
-pub(crate) struct ConfigFlags {
+/// Workaround as per https://github.com/serde-rs/serde/issues/1030
+fn default_as_true() -> bool {
+ true
+}
+
+#[derive(Clone, Debug, Default, Deserialize)]
+pub struct IgnoreList {
+ #[serde(default = "default_as_true")]
+ // TODO: Deprecate and/or rename, current name sounds awful.
+ // Maybe to something like "deny_entries"? Currently it defaults to a denylist anyways, so maybe "allow_entries"?
+ pub is_list_ignored: bool,
+ pub list: Vec<String>,
+ #[serde(default)]
+ pub regex: bool,
+ #[serde(default)]
+ pub case_sensitive: bool,
+ #[serde(default)]
+ pub whole_word: bool,
+}
+
+#[derive(Clone, Debug, Default, Deserialize)]
+pub struct ConfigFlags {
pub(crate) hide_avg_cpu: Option<bool>,
pub(crate) dot_marker: Option<bool>,
pub(crate) temperature_type: Option<String>,
@@ -79,8 +113,6 @@ pub(crate) struct ConfigFlags {
pub(crate) hide_table_gap: Option<bool>,
pub(crate) battery: Option<bool>,
pub(crate) disable_click: Option<bool>,
- pub(crate) no_write: Option<bool>,
- /// For built-in colour palettes.
pub(crate) color: Option<String>,
pub(crate) mem_as_value: Option<bool>,
pub(crate) tree: Option<bool>,
diff --git a/src/options/config/battery.rs b/src/options/config/battery.rs
new file mode 100644
index 00000000..4f778cff
--- /dev/null
+++ b/src/options/config/battery.rs
@@ -0,0 +1,6 @@
+use serde::Deserialize;
+
+#[derive(Clone, Debug, Default, Deserialize)]
+pub(crate) struct BatteryOptions {
+ pub(crate) battery: Option<bool>,
+}
diff --git a/src/options/config/cpu.rs b/src/options/config/cpu.rs
index ce027305..07be9632 100644
--- a/src/options/config/cpu.rs
+++ b/src/options/config/cpu.rs
@@ -11,10 +11,12 @@ pub enum CpuDefault {
}
/// Process column settings.
+
#[derive(Clone, Debug, Default, Deserialize)]
-pub struct CpuConfig {
+pub(crate) struct CpuConfig {
+ pub(crate) hide_avg_cpu: Option<bool>,
#[serde(default)]
- pub default: CpuDefault,
+ pub(crate) default: CpuDefault,
}
#[cfg(test)]
diff --git a/src/options/config/general.rs b/src/options/config/general.rs
new file mode 100644
index 00000000..5d3da95a
--- /dev/null
+++ b/src/options/config/general.rs
@@ -0,0 +1,21 @@
+use serde::Deserialize;
+
+use super::StringOrNum;
+
+#[derive(Clone, Debug, Default, Deserialize)]
+pub(crate) struct GeneralConfig {
+ pub(crate) autohide_time: Option<bool>,
+ pub(crate) basic: Option<bool>,
+ pub(crate) default_time_value: Option<StringOrNum>,
+ pub(crate) default_widget_type: Option<String>,
+ pub(crate) disable_click: Option<bool>,
+ pub(crate) dot_marker: Option<bool>, // TODO: Support other markers!
+ pub(crate) expanded: Option<bool>,
+ pub(crate) hide_table_gap: Option<bool>,
+ pub(crate) hide_time: Option<bool>, // TODO: Combine with autohide_time
+ pub(crate) left_legend: Option<bool>,
+ pub(crate) rate: Option<StringOrNum>,
+ pub(crate) retention: Option<StringOrNum>,
+ pub(crate) show_table_scroll_position: Option<bool>,
+ pub(crate) time_delta: Option<StringOrNum>,
+}
diff --git a/src/options/config/gpu.rs b/src/options/config/gpu.rs
new file mode 100644
index 00000000..50f9c50c
--- /dev/null
+++ b/src/options/config/gpu.rs
@@ -0,0 +1,6 @@
+use serde::Deserialize;
+
+#[derive(Clone, Debug, Default, Deserialize)]
+pub(crate) struct GpuOptions {
+ pub(crate) enable_gpu: Option<bool>, // TODO: Enable by default instead?
+}
diff --git a/src/options/config/ignore_list.rs b/src/options/config/ignore_list.rs
deleted file mode 100644
index d70224c1..00000000
--- a/src/options/config/ignore_list.rs
+++ /dev/null
@@ -1,21 +0,0 @@
-use serde::{Deserialize, Serialize};
-
-/// Workaround as per https://github.com/serde-rs/serde/issues/1030
-fn default_as_true() -> bool {
- true
-}
-
-#[derive(Clone, Debug, Default, Deserialize, Serialize)]
-pub struct IgnoreList {
- #[serde(default = "default_as_true")]
- // TODO: Deprecate and/or rename, current name sounds awful.
- // Maybe to something like "deny_entries"? Currently it defaults to a denylist anyways, so maybe "allow_entries"?
- pub is_list_ignored: bool,
- pub list: Vec<String>,
- #[serde(default)]
- pub regex: bool,
- #[serde(default)]
- pub case_sensitive: bool,
- #[serde(default)]
- pub whole_word: bool,
-}
diff --git a/src/options/config/memory.rs b/src/options/config/memory.rs
new file mode 100644
index 00000000..4e180122
--- /dev/null
+++ b/src/options/config/memory.rs
@@ -0,0 +1,7 @@
+use serde::Deserialize;
+
+#[derive(Clone, Debug, Default, Deserialize)]
+pub(crate) struct MemoryConfig {
+ pub(crate) mem_as_value: Option<bool>,
+ pub(crate) enable_cache_memory: Option<bool>,
+}
diff --git a/src/options/config/network.rs b/src/options/config/network.rs
new file mode 100644
index 00000000..48345469
--- /dev/null
+++ b/src/options/config/network.rs
@@ -0,0 +1,9 @@
+use serde::Deserialize;
+
+#[derive(Clone, Debug, Default, Deserialize)]
+pub(crate) struct NetworkConfig {
+ pub(crate) network_use_bytes: Option<bool>,
+ pub(crate) network_use_log: Option<bool>,
+ pub(crate) network_use_binary_prefix: Option<bool>,
+ pub(crate) use_old_network_legend: Option<bool>,
+}
diff --git a/src/options/config/process_columns.rs b/src/options/config/process.rs
index ea65bf27..0e13f920 100644
--- a/src/options/config/process_columns.rs
+++ b/src/options/config/process.rs
@@ -4,9 +4,17 @@ use crate::widgets::ProcWidgetColumn;
/// Process column settings.
#[derive(Clone, Debug, Default, Deserialize)]
-pub struct ProcessConfig {
- #[serde(default)]
- pub columns: Vec<ProcWidgetColumn>,
+pub(crate) struct ProcessConfig {
+ pub(crate) case_sensitive: Option<bool>,
+ pub(crate) current_usage: Option<bool>,
+ pub(crate) disable_advanced_kill: Option<bool>,
+ pub(crate) group_processes: Option<bool>,
+ pub(crate) process_command: Option<bool>,
+ pub(crate) regex: Option<bool>,
+ pub(crate) tree: Option<bool>,
+ pub(crate) unnormalized_cpu: Option<bool>,
+ pub(crate) whole_word: Option<bool>,
+ pub(crate) columns: Option<Vec<ProcWidgetColumn>>,
}
#[cfg(test)]
@@ -18,7 +26,7 @@ mod test {
fn empty_column_setting() {
let config = "";
let generated: ProcessConfig = toml_edit::de::from_str(config).unwrap();
- assert!(generated.columns.is_empty());
+ assert!(generated.columns.is_none());
}
#[test]
@@ -29,7 +37,7 @@ mod test {
let generated: ProcessConfig = toml_edit::de::from_str(config).unwrap();
assert_eq!(
- generated.columns,
+ generated.columns.unwrap(),
vec![
ProcWidgetColumn::Cpu,
ProcWidgetColumn::PidOrCount,
@@ -56,18 +64,22 @@ mod test {
fn process_column_settings_3() {
let config = r#"columns = ["Twrite", "T.Write"]"#;
let generated: ProcessConfig = toml_edit::de::from_str(config).unwrap();
- assert_eq!(generated.columns, vec![ProcWidgetColumn::TotalWrite; 2]);
+ let columns = generated.columns.unwrap();
+ assert_eq!(columns, vec![ProcWidgetColumn::TotalWrite; 2]);
let config = r#"columns = ["Tread", "T.read"]"#;
let generated: ProcessConfig = toml_edit::de::from_str(config).unwrap();
- assert_eq!(generated.columns, vec![ProcWidgetColumn::TotalRead; 2]);
+ let columns = generated.columns.unwrap();
+ assert_eq!(columns, vec![ProcWidgetColumn::TotalRead; 2]);
let config = r#"columns = ["read", "rps", "r/s"]"#;
let generated: ProcessConfig = toml_edit::de::from_str(config).unwrap();
- assert_eq!(generated.columns, vec![ProcWidgetColumn::ReadPerSecond; 3]);
+ let columns = generated.columns.unwrap();
+ assert_eq!(columns, vec![ProcWidgetColumn::ReadPerSecond; 3]);
let config = r#"columns = ["write", "wps", "w/s"]"#;
let generated: ProcessConfig = toml_edit::de::from_str(config).unwrap();
- assert_eq!(generated.columns, vec![ProcWidgetColumn::WritePerSecond; 3]);
+ let columns = generated.columns.unwrap();
+ assert_eq!(columns, vec![ProcWidgetColumn::WritePerSecond; 3]);
}
}
diff --git a/src/options/config/style.rs b/src/options/config/style.rs
new file mode 100644
index 00000000..e0c10d8a
--- /dev/null
+++ b/src/options/config/style.rs
@@ -0,0 +1,9 @@
+pub mod colours;
+pub mod palettes;
+
+use serde::Deserialize;
+
+#[derive(Clone, Debug, Default, Deserialize)]
+pub(crate) struct StyleConfig {
+ pub(crate) color: Option<String>,
+}
diff --git a/src/options/colours.rs b/src/options/config/style/colours.rs
index edef00b4..7068bfdb 100644
--- a/src/options/colours.rs
+++ b/src/options/config/style/colours.rs
@@ -3,7 +3,7 @@ use std::borrow::Cow;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
-pub struct ConfigColours {
+pub struct ColourConfig {
pub table_header_color: Option<Cow<'static, str>>,
pub all_cpu_color: Option<Cow<'static, str>>,
pub avg_cpu_color: Option<Cow<'static, str>>,
@@ -31,7 +31,7 @@ pub struct ConfigColours {
pub low_battery_color: Option<Cow<'static, str>>,
}
-impl ConfigColours {
+impl ColourConfig {
/// Returns `true` if there is a [`ConfigColours`] that is empty or there isn't one at all.
pub fn is_empty(&self) -> bool {
if let Ok(serialized_string) = toml_edit::ser::to_string(self) {
diff --git a/src/options/config/style/palettes.rs b/src/options/config/style/palettes.rs
new file mode 100644
index 00000000..2c913f94
--- /dev/null
+++ b/src/options/config/style/palettes.rs
@@ -0,0 +1,255 @@
+use super::colours::ColourConfig;
+
+// Colour profiles
+// TODO: Generate these with a macro or something...
+pub fn default_light_mode_colour_palette() -> ColourConfig {
+ ColourConfig {
+ text_color: Some("black".into()),
+ border_color: Some("black".into()),
+ table_header_color: Some("black".into()),
+ widget_title_color: Some("black".into()),
+ selected_text_color: Some("white".into()),
+ graph_color: Some("black".into()),
+ disabled_text_color: Some("gray".into()),
+ ram_color: Some("blue".into()),
+ #[cfg(not(target_os = "windows"))]
+ cache_color: Some("LightRed".into()),
+ swap_color: Some("red".into()),
+ arc_color: Some("LightBlue".into()),
+ gpu_core_colors: Some(vec![
+ "LightGreen".into(),
+ "LightCyan".into(),
+ "LightRed".into(),
+ "Cyan".into(),
+ "Green".into(),
+ "Blue".into(),
+ "Red".into(),
+ ]),
+ rx_color: Some("blue".into()),
+ tx_color: Some("red".into()),
+ rx_total_color: Some("LightBlue".into()),
+ tx_total_color: Some("LightRed".into()),
+ cpu_core_colors: Some(vec![
+ "LightMagenta".into(),
+ "LightBlue".into(),
+ "LightRed".into(),
+ "Cyan".into(),
+ "Green".into(),
+ "Blue".into(),
+ "Red".into(),
+ ]),
+ ..ColourConfig::default()
+ }
+}
+
+pub fn gruvbox_colour_palette() -> ColourConfig {
+ ColourConfig {
+ table_header_color: Some("#83a598".into()),
+ all_cpu_color: Some("#8ec07c".into()),
+ avg_cpu_color: Some("#fb4934".into()),
+ cpu_core_colors: Some(vec![
+ "#cc241d".into(),
+ "#98971a".into(),
+ "#d79921".into(),
+ "#458588".into(),
+ "#b16286".into(),
+ "#689d6a".into(),
+ "#fe8019".into(),
+ "#b8bb26".into(),
+ "#fabd2f".into(),
+ "#83a598".into(),
+ "#d3869b".into(),
+ "#d65d0e".into(),
+ "#9d0006".into(),
+ "#79740e".into(),
+ "#b57614".into(),
+ "#076678".into(),
+ "#8f3f71".into(),
+ "#427b58".into(),
+ "#d65d03".into(),
+ "#af3a03".into(),
+ ]),
+ ram_color: Some("#8ec07c".into()),
+ #[cfg(not(target_os = "windows"))]
+ cache_color: Some("#b16286".into()),
+ swap_color: Some("#fabd2f".into()),
+ arc_color: Some("#689d6a".into()),
+ gpu_core_colors: Some(vec![
+ "#d79921".into(),
+ "#458588".into(),
+ "#b16286".into(),
+ "#fe8019".into(),
+ "#b8bb26".into(),
+ "#cc241d".into(),
+ "#98971a".into(),
+ ]),
+ rx_color: Some("#8ec07c".into()),
+ tx_color: Some("#fabd2f".into()),
+ rx_total_color: Some("#689d6a".into()),
+ tx_total_color: Some("#d79921".into()),
+ border_color: Some("#ebdbb2".into()),
+ highlighted_border_color: Some("#fe8019".into()),
+ disabled_text_color: Some("#665c54".into()),
+ text_color: Some("#ebdbb2".into()),
+ selected_text_color: Some("#1d2021".into()),
+ selected_bg_color: Some("#ebdbb2".into()),
+ widget_title_color: Some("#ebdbb2".into()),
+ graph_color: Some("#ebdbb2".into()),
+ high_battery_color: Some("#98971a".into()),
+ medium_battery_color: Some("#fabd2f".into()),
+ low_battery_color: Some("#fb4934".into()),
+ }
+}
+
+pub fn gruvbox_light_colour_palette() -> ColourConfig {
+ ColourConfig {
+ table_header_color: Some("#076678".into()),
+ all_cpu_color: Some("#8ec07c".into()),
+ avg_cpu_color: Some("#fb4934".into()),
+ cpu_core_colors: Some(vec![
+ "#cc241d".into(),
+ "#98971a".into(),
+ "#d79921".into(),
+ "#458588".into(),
+ "#b16286".into(),
+ "#689d6a".into(),
+ "#fe8019".into(),
+ "#b8bb26".into(),
+ "#fabd2f".into(),
+ "#83a598".into(),
+ "#d3869b".into(),
+ "#d65d0e".into(),
+ "#9d0006".into(),
+ "#79740e".into(),
+ "#b57614".into(),
+ "#076678".into(),
+ "#8f3f71".into(),
+ "#427b58".into(),
+ "#d65d03".into(),
+ "#af3a03".into(),
+ ]),
+ ram_color: Some("#427b58".into()),
+ #[cfg(not(target_os = "windows"))]
+ cache_color: Some("#d79921".into()),
+ swap_color: Some("#cc241d".into()),
+ arc_color: Some("#689d6a".into()),
+ gpu_core_colors: Some(vec![
+ "#9d0006".into(),</