summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2020-11-15 05:16:47 -0500
committerGitHub <noreply@github.com>2020-11-15 05:16:47 -0500
commite43456207be0757fbb9c05f93a169063faf673b7 (patch)
tree09a958570fbd0736f070c68d4d9a2f8e1a2af6ed /src
parent4573194cec7391cc15c637e0d91625fa92996595 (diff)
feature: default colour schemes (#296)
Adds some default colour choices to choose from.
Diffstat (limited to 'src')
-rw-r--r--src/bin/main.rs1
-rw-r--r--src/canvas.rs153
-rw-r--r--src/canvas/canvas_colours.rs174
-rw-r--r--src/canvas/canvas_colours/colour_utils.rs1
-rw-r--r--src/canvas/widgets/battery_display.rs6
-rw-r--r--src/canvas/widgets/cpu_graph.rs7
-rw-r--r--src/canvas/widgets/disk_table.rs2
-rw-r--r--src/canvas/widgets/process_table.rs2
-rw-r--r--src/clap.rs31
-rw-r--r--src/constants.rs121
-rw-r--r--src/options.rs47
11 files changed, 408 insertions, 137 deletions
diff --git a/src/bin/main.rs b/src/bin/main.rs
index 8db05b22..a059f4f0 100644
--- a/src/bin/main.rs
+++ b/src/bin/main.rs
@@ -70,6 +70,7 @@ fn main() -> Result<()> {
app.app_config_fields.table_gap,
app.app_config_fields.use_basic_mode,
&config,
+ get_color_scheme(&matches, &config)?,
)?;
// Create termination mutex and cvar
diff --git a/src/canvas.rs b/src/canvas.rs
index d85f2444..626f4f7f 100644
--- a/src/canvas.rs
+++ b/src/canvas.rs
@@ -1,6 +1,5 @@
-use anyhow::Context;
use itertools::izip;
-use std::collections::HashMap;
+use std::{collections::HashMap, str::FromStr};
use tui::{
backend::Backend,
@@ -25,6 +24,7 @@ use crate::{
data_conversion::{ConvertedBatteryData, ConvertedCpuData, ConvertedProcessData},
options::Config,
utils::error,
+ utils::error::BottomError,
};
mod canvas_colours;
@@ -59,6 +59,35 @@ pub struct DisplayableData {
pub battery_data: Vec<ConvertedBatteryData>,
}
+#[derive(Debug)]
+pub enum ColourScheme {
+ Default,
+ DefaultLight,
+ Gruvbox,
+ GruvboxLight,
+ // Nord,
+ Custom,
+}
+
+impl FromStr for ColourScheme {
+ type Err = BottomError;
+
+ fn from_str(s: &str) -> error::Result<Self> {
+ let lower_case = s.to_lowercase();
+ match lower_case.as_str() {
+ "default" => Ok(ColourScheme::Default),
+ "default-light" => Ok(ColourScheme::DefaultLight),
+ "gruvbox" => Ok(ColourScheme::Gruvbox),
+ "gruvbox-light" => Ok(ColourScheme::GruvboxLight),
+ // "nord" => Ok(ColourScheme::Nord),
+ _ => Err(BottomError::ConfigError(format!(
+ "\"{}\" is an invalid built-in color scheme.",
+ s
+ ))),
+ }
+ }
+}
+
/// Handles the canvas' state. TODO: [OPT] implement this.
pub struct Painter {
pub colours: CanvasColours,
@@ -78,6 +107,7 @@ pub struct Painter {
impl Painter {
pub fn init(
widget_layout: BottomLayout, table_gap: u16, is_basic_mode: bool, config: &Config,
+ colour_scheme: ColourScheme,
) -> anyhow::Result<Self> {
// Now for modularity; we have to also initialize the base layouts!
// We want to do this ONCE and reuse; after this we can just construct
@@ -161,117 +191,48 @@ impl Painter {
table_height_offset: if is_basic_mode { 2 } else { 4 } + table_gap,
};
- painter.generate_config_colours(config)?;
+ if let ColourScheme::Custom = colour_scheme {
+ painter.generate_config_colours(config)?;
+ } else {
+ painter.generate_colour_scheme(colour_scheme)?;
+ }
painter.colours.generate_remaining_cpu_colours();
painter.complete_painter_init();
Ok(painter)
}
- pub fn generate_config_colours(&mut self, config: &Config) -> anyhow::Result<()> {
+ fn generate_config_colours(&mut self, config: &Config) -> anyhow::Result<()> {
if let Some(colours) = &config.colors {
- if let Some(border_color) = &colours.border_color {
- self.colours
- .set_border_colour(border_color)
- .context("Update 'border_color' in your config file..")?;
- }
-
- if let Some(highlighted_border_color) = &colours.highlighted_border_color {
- self.colours
- .set_highlighted_border_colour(highlighted_border_color)
- .context("Update 'highlighted_border_color' in your config file..")?;
- }
-
- if let Some(text_color) = &colours.text_color {
- self.colours
- .set_text_colour(text_color)
- .context("Update 'text_color' in your config file..")?;
- }
-
- if let Some(avg_cpu_color) = &colours.avg_cpu_color {
- self.colours
- .set_avg_cpu_colour(avg_cpu_color)
- .context("Update 'avg_cpu_color' in your config file..")?;
- }
-
- if let Some(all_cpu_color) = &colours.all_cpu_color {
- self.colours
- .set_all_cpu_colour(all_cpu_color)
- .context("Update 'all_cpu_color' in your config file..")?;
- }
+ self.colours.set_colours_from_palette(colours)?;
+ }
- if let Some(cpu_core_colors) = &colours.cpu_core_colors {
- self.colours
- .set_cpu_colours(cpu_core_colors)
- .context("Update 'cpu_core_colors' in your config file..")?;
- }
+ Ok(())
+ }
- if let Some(ram_color) = &colours.ram_color {
- self.colours
- .set_ram_colour(ram_color)
- .context("Update 'ram_color' in your config file..")?;
+ fn generate_colour_scheme(&mut self, colour_scheme: ColourScheme) -> anyhow::Result<()> {
+ match colour_scheme {
+ ColourScheme::Default => {
+ // Don't have to do anything.
}
-
- if let Some(swap_color) = &colours.swap_color {
+ ColourScheme::DefaultLight => {
self.colours
- .set_swap_colour(swap_color)
- .context("Update 'swap_color' in your config file..")?;
+ .set_colours_from_palette(&*DEFAULT_LIGHT_MODE_COLOUR_PALETTE)?;
}
-
- if let Some(rx_color) = &colours.rx_color {
+ ColourScheme::Gruvbox => {
self.colours
- .set_rx_colour(rx_color)
- .context("Update 'rx_color' in your config file..")?;
+ .set_colours_from_palette(&*GRUVBOX_COLOUR_PALETTE)?;
}
-
- if let Some(tx_color) = &colours.tx_color {
+ ColourScheme::GruvboxLight => {
self.colours
- .set_tx_colour(tx_color)
- .context("Update 'tx_color' in your config file..")?;
+ .set_colours_from_palette(&*GRUVBOX_LIGHT_COLOUR_PALETTE)?;
}
-
- // if let Some(rx_total_color) = &colours.rx_total_color {
- // painter.colours.set_rx_total_colour(rx_total_color)?;
+ // ColourScheme::Nord => {
+ // self.colours
+ // .set_colours_from_palette(&*NORD_COLOUR_PALETTE)?;
// }
-
- // if let Some(tx_total_color) = &colours.tx_total_color {
- // painter.colours.set_tx_total_colour(tx_total_color)?;
- // }
-
- if let Some(table_header_color) = &colours.table_header_color {
- self.colours
- .set_table_header_colour(table_header_color)
- .context("Update 'table_header_color' in your config file..")?;
- }
-
- if let Some(scroll_entry_text_color) = &colours.selected_text_color {
- self.colours
- .set_scroll_entry_text_color(scroll_entry_text_color)
- .context("Update 'selected_text_color' in your config file..")?;
- }
-
- if let Some(scroll_entry_bg_color) = &colours.selected_bg_color {
- self.colours
- .set_scroll_entry_bg_color(scroll_entry_bg_color)
- .context("Update 'selected_bg_color' in your config file..")?;
- }
-
- if let Some(widget_title_color) = &colours.widget_title_color {
- self.colours
- .set_widget_title_colour(widget_title_color)
- .context("Update 'widget_title_color' in your config file..")?;
- }
-
- if let Some(graph_color) = &colours.graph_color {
- self.colours
- .set_graph_colour(graph_color)
- .context("Update 'graph_color' in your config file..")?;
- }
-
- if let Some(battery_colors) = &colours.battery_colors {
- self.colours
- .set_battery_colors(battery_colors)
- .context("Update 'battery_colors' in your config file.")?;
+ ColourScheme::Custom => {
+ // This case should never occur, just do nothing.
}
}
diff --git a/src/canvas/canvas_colours.rs b/src/canvas/canvas_colours.rs
index 2876e24b..a42eb88c 100644
--- a/src/canvas/canvas_colours.rs
+++ b/src/canvas/canvas_colours.rs
@@ -1,9 +1,7 @@
-use tui::style::{Color, Style};
-
+use crate::{constants::*, options::ConfigColours, utils::error};
+use anyhow::Context;
use colour_utils::*;
-
-use crate::{constants::*, utils::error};
-
+use tui::style::{Color, Style};
mod colour_utils;
pub struct CanvasColours {
@@ -60,6 +58,10 @@ impl Default for CanvasColours {
Style::default().fg(Color::Red),
Style::default().fg(Color::Yellow),
Style::default().fg(Color::Yellow),
+ Style::default().fg(Color::Yellow),
+ Style::default().fg(Color::Green),
+ Style::default().fg(Color::Green),
+ Style::default().fg(Color::Green),
Style::default().fg(Color::Green),
Style::default().fg(Color::Green),
Style::default().fg(Color::Green),
@@ -71,6 +73,118 @@ impl Default for CanvasColours {
}
impl CanvasColours {
+ pub fn set_colours_from_palette(&mut self, colours: &ConfigColours) -> anyhow::Result<()> {
+ if let Some(border_color) = &colours.border_color {
+ self.set_border_colour(border_color)
+ .context("Update 'border_color' in your config file..")?;
+ }
+
+ if let Some(highlighted_border_color) = &colours.highlighted_border_color {
+ self.set_highlighted_border_colour(highlighted_border_color)
+ .context("Update 'highlighted_border_color' in your config file..")?;
+ }
+
+ if let Some(text_color) = &colours.text_color {
+ self.set_text_colour(text_color)
+ .context("Update 'text_color' in your config file..")?;
+ }
+
+ if let Some(avg_cpu_color) = &colours.avg_cpu_color {
+ self.set_avg_cpu_colour(avg_cpu_color)
+ .context("Update 'avg_cpu_color' in your config file..")?;
+ }
+
+ if let Some(all_cpu_color) = &colours.all_cpu_color {
+ self.set_all_cpu_colour(all_cpu_color)
+ .context("Update 'all_cpu_color' in your config file..")?;
+ }
+
+ if let Some(cpu_core_colors) = &colours.cpu_core_colors {
+ self.set_cpu_colours(cpu_core_colors)
+ .context("Update 'cpu_core_colors' in your config file..")?;
+ }
+
+ if let Some(ram_color) = &colours.ram_color {
+ self.set_ram_colour(ram_color)
+ .context("Update 'ram_color' in your config file..")?;
+ }
+
+ if let Some(swap_color) = &colours.swap_color {
+ self.set_swap_colour(swap_color)
+ .context("Update 'swap_color' in your config file..")?;
+ }
+
+ if let Some(rx_color) = &colours.rx_color {
+ self.set_rx_colour(rx_color)
+ .context("Update 'rx_color' in your config file..")?;
+ }
+
+ if let Some(tx_color) = &colours.tx_color {
+ self.set_tx_colour(tx_color)
+ .context("Update 'tx_color' in your config file..")?;
+ }
+
+ if let Some(table_header_color) = &colours.table_header_color {
+ self.set_table_header_colour(table_header_color)
+ .context("Update 'table_header_color' in your config file..")?;
+ }
+
+ if let Some(scroll_entry_text_color) = &colours.selected_text_color {
+ self.set_scroll_entry_text_color(scroll_entry_text_color)
+ .context("Update 'selected_text_color' in your config file..")?;
+ }
+
+ if let Some(scroll_entry_bg_color) = &colours.selected_bg_color {
+ self.set_scroll_entry_bg_color(scroll_entry_bg_color)
+ .context("Update 'selected_bg_color' in your config file..")?;
+ }
+
+ if let Some(widget_title_color) = &colours.widget_title_color {
+ self.set_widget_title_colour(widget_title_color)
+ .context("Update 'widget_title_color' in your config file..")?;
+ }
+
+ if let Some(graph_color) = &colours.graph_color {
+ self.set_graph_colour(graph_color)
+ .context("Update 'graph_color' in your config file..")?;
+ }
+
+ if let Some(high_battery_color) = &colours.high_battery_color {
+ self.set_high_battery_color(high_battery_color)
+ .context("Update 'high_battery_color' in your config file.")?;
+ }
+
+ if let Some(medium_battery_color) = &colours.medium_battery_color {
+ self.set_medium_battery_color(medium_battery_color)
+ .context("Update 'medium_battery_color' in your config file.")?;
+ }
+
+ if let Some(low_battery_color) = &colours.low_battery_color {
+ self.set_low_battery_color(low_battery_color)
+ .context("Update 'low_battery_color' in your config file.")?;
+ }
+
+ if let Some(disabled_text_color) = &colours.disabled_text_color {
+ self.set_disabled_text_colour(disabled_text_color)
+ .context("Update 'disabled_text_color' in your config file.")?;
+ }
+
+ if let Some(rx_total_color) = &colours.rx_total_color {
+ self.set_rx_total_colour(rx_total_color)?;
+ }
+
+ if let Some(tx_total_color) = &colours.tx_total_color {
+ self.set_tx_total_colour(tx_total_color)?;
+ }
+
+ Ok(())
+ }
+
+ pub fn set_disabled_text_colour(&mut self, colour: &str) -> error::Result<()> {
+ self.disabled_text_style = get_style_from_config(colour)?;
+ Ok(())
+ }
+
pub fn set_text_colour(&mut self, colour: &str) -> error::Result<()> {
self.text_style = get_style_from_config(colour)?;
Ok(())
@@ -113,15 +227,15 @@ impl CanvasColours {
Ok(())
}
- // pub fn set_rx_total_colour(&mut self, colour: &str) -> error::Result<()> {
- // self.total_rx_style = get_style_from_config(colour)?;
- // Ok(())
- // }
+ pub fn set_rx_total_colour(&mut self, colour: &str) -> error::Result<()> {
+ self.total_rx_style = get_style_from_config(colour)?;
+ Ok(())
+ }
- // pub fn set_tx_total_colour(&mut self, colour: &str) -> error::Result<()> {
- // self.total_tx_style = get_style_from_config(colour)?;
- // Ok(())
- // }
+ pub fn set_tx_total_colour(&mut self, colour: &str) -> error::Result<()> {
+ self.total_tx_style = get_style_from_config(colour)?;
+ Ok(())
+ }
pub fn set_avg_cpu_colour(&mut self, colour: &str) -> error::Result<()> {
self.avg_colour_style = get_style_from_config(colour)?;
@@ -176,19 +290,27 @@ impl CanvasColours {
Ok(())
}
- pub fn set_battery_colors(&mut self, colours: &[String]) -> error::Result<()> {
- if colours.is_empty() {
- Err(error::BottomError::ConfigError(
- "battery colour list must have at least one colour.".to_string(),
- ))
- } else {
- let generated_colours: Result<Vec<_>, _> = colours
- .iter()
- .map(|colour| get_style_from_config(colour))
- .collect();
+ pub fn set_high_battery_color(&mut self, colour: &str) -> error::Result<()> {
+ let style = get_style_from_config(colour)?;
+ self.battery_bar_styles[0] = style;
+ self.battery_bar_styles[1] = style;
+ self.battery_bar_styles[2] = style;
+ self.battery_bar_styles[3] = style;
+ self.battery_bar_styles[4] = style;
+ self.battery_bar_styles[5] = style;
+ Ok(())
+ }
- self.battery_bar_styles = generated_colours?;
- Ok(())
- }
+ pub fn set_medium_battery_color(&mut self, colour: &str) -> error::Result<()> {
+ let style = get_style_from_config(colour)?;
+ self.battery_bar_styles[6] = style;
+ self.battery_bar_styles[7] = style;
+ self.battery_bar_styles[8] = style;
+ Ok(())
+ }
+
+ pub fn set_low_battery_color(&mut self, colour: &str) -> error::Result<()> {
+ self.battery_bar_styles[9] = get_style_from_config(colour)?;
+ Ok(())
}
}
diff --git a/src/canvas/canvas_colours/colour_utils.rs b/src/canvas/canvas_colours/colour_utils.rs
index f94b9bd9..d104d483 100644
--- a/src/canvas/canvas_colours/colour_utils.rs
+++ b/src/canvas/canvas_colours/colour_utils.rs
@@ -26,6 +26,7 @@ lazy_static! {
("magenta", Color::Magenta),
("cyan", Color::Cyan),
("gray", Color::Gray),
+ ("grey", Color::Gray),
("darkgray", Color::DarkGray),
("lightred", Color::LightRed),
("lightgreen", Color::LightGreen),
diff --git a/src/canvas/widgets/battery_display.rs b/src/canvas/widgets/battery_display.rs
index e27c1aef..ae911d42 100644
--- a/src/canvas/widgets/battery_display.rs
+++ b/src/canvas/widgets/battery_display.rs
@@ -143,10 +143,10 @@ impl BatteryDisplayWidget for Painter {
item.iter(),
if itx == 0 {
let colour_index = ((charge_percentage
- * self.colours.battery_bar_styles.len() as f64
- - 1.0)
+ * self.colours.battery_bar_styles.len() as f64)
/ 100.0)
- .floor() as usize;
+ .ceil() as usize
+ - 1;
*self
.colours
.battery_bar_styles
diff --git a/src/canvas/widgets/cpu_graph.rs b/src/canvas/widgets/cpu_graph.rs
index bce8b699..e03c9032 100644
--- a/src/canvas/widgets/cpu_graph.rs
+++ b/src/canvas/widgets/cpu_graph.rs
@@ -220,7 +220,12 @@ impl CpuGraphWidget for Painter {
self.colours.cpu_colour_styles[cpu_widget_state
.scroll_state
.current_scroll_position
- % self.colours.cpu_colour_styles.len()]
+ - 1 // Because of the all position
+ - (if show_avg_cpu {
+ AVG_POSITION
+ } else {
+ 0
+ }) % self.colours.cpu_colour_styles.len()]
})
.data(&cpu.cpu_data[..])
.graph_type(tui::widgets::GraphType::Line)]
diff --git a/src/canvas/widgets/disk_table.rs b/src/canvas/widgets/disk_table.rs
index c52062b5..9d249f4e 100644
--- a/src/canvas/widgets/disk_table.rs
+++ b/src/canvas/widgets/disk_table.rs
@@ -170,7 +170,7 @@ impl DiskTableWidget for Painter {
Span::styled(" Disk ", self.colours.widget_title_style),
Span::styled(
format!(
- "─{}─ Esc to go back, ",
+ "─{}─ Esc to go back ",
"─".repeat(usize::from(draw_loc.width).saturating_sub(
UnicodeSegmentation::graphemes(TITLE_BASE, true).count() + 2
))
diff --git a/src/canvas/widgets/process_table.rs b/src/canvas/widgets/process_table.rs
index 727abb94..0ee25b1f 100644
--- a/src/canvas/widgets/process_table.rs
+++ b/src/canvas/widgets/process_table.rs
@@ -408,7 +408,7 @@ impl ProcessTableWidget for Painter {
}
});
- // TODO: gotop's "x out of y" thing is really nice to help keep track of the scroll position. Add to everything?
+ // FIXME: gotop's "x out of y" thing is really nice to help keep track of the scroll position. Add to everything?
f.render_stateful_widget(
Table::new(process_headers.iter(), process_rows)
.block(process_block)
diff --git a/src/clap.rs b/src/clap.rs
index 2a03e9b4..5f6d7667 100644
--- a/src/clap.rs
+++ b/src/clap.rs
@@ -197,6 +197,36 @@ entire query by default.\n\n",
Sets the location of the config file. Expects a config
file in the TOML format. If it doesn't exist, one is created.\n\n\n",
);
+ let color = Arg::with_name("color")
+ .long("color")
+ .takes_value(true)
+ .value_name("COLOR SCHEME")
+ .help("Use a color scheme, use --help for supported values.")
+ .long_help(
+ "\
+Use a pre-defined color scheme. Currently supported values are:
+
++------------------------------------------------------------+
+| default |
++------------------------------------------------------------+
+| default-light (default but for use with light backgrounds) |
++------------------------------------------------------------+
+| gruvbox (a bright theme with 'retro groove' colors) |
++------------------------------------------------------------+
+| gruvbox-light (gruvbox but for use with light backgrounds) |
++------------------------------------------------------------+
+
+Defaults to \"default\".
+\n\n",
+ )
+ .possible_values(&[
+ "default",
+ "default-light",
+ "gruvbox",
+ "gruvbox-light",
+ "nord",
+ ])
+ .hide_possible_values(true);
let default_time_value = Arg::with_name("default_time_value")
.short("t")
.long("default_time_value")
@@ -313,6 +343,7 @@ The minimum is 1s (1000), and defaults to 15s (15000).\n\n\n",
.arg(battery)
.arg(case_sensitive)
.arg(config_location)
+ .arg(color)
.arg(debug)
.arg(default_time_value)
.arg(default_widget_count)
diff --git a/src/constants.rs b/src/constants.rs
index 8bc6f11d..91e9419c 100644
--- a/src/constants.rs
+++ b/src/constants.rs
@@ -1,5 +1,7 @@
use lazy_static::lazy_static;
+use crate::options::ConfigColours;
+
// Default widget ID
pub const DEFAULT_WIDGET_ID: u64 = 56709;
@@ -37,6 +39,125 @@ lazy_static! {
tui::style::Style::default().fg(tui::style::Color::LightBlue);
}
+// Colour profiles
+lazy_static! {
+ pub static ref DEFAULT_LIGHT_MODE_COLOUR_PALETTE: ConfigColours = ConfigColours {
+ text_color: Some("black".to_string()),
+ border_color: Some("black".to_string()),
+ table_header_color: Some("black".to_string()),
+ widget_title_color: Some("black".to_string()),
+ selected_text_color: Some("white".to_string()),
+ graph_color: Some("black".to_string()),
+ disabled_text_color: Some("gray".to_string()),
+ ..ConfigColours::default()
+ };
+ pub static ref GRUVBOX_COLOUR_PALETTE: ConfigColours = ConfigColours {
+ table_header_color: Some("#ebdbb2".to_string()),
+ all_cpu_color: Some("#cc241d".to_string()),
+ avg_cpu_color: Some("#98971a".to_string()),
+ cpu_core_colors: Some(vec![
+ "#d79921".to_string(),
+ "#458588".to_string(),
+ "#b16286".to_string(),
+ "#689d6a".to_string(),
+ "#fb4934".to_string(),
+ "#b8bb26".to_string(),
+ "#fe8019".to_string(),
+ "#fabd2f".to_string(),
+ "#83a598".to_string(),
+ "#d3869b".to_string(),
+ "#8ec07c".to_string(),
+ "#d65d0e".to_string(),
+ "#fbf1c7".to_string(),
+ "#ebdbb2".to_string(),
+ "#d5c4a1".to_string(),
+ "#bdae93".to_string(),
+ "#a89984".to_string(),
+ ]),
+ ram_color: Some("#458588".to_string()),
+ swap_color: Some("#fabd2f".to_string()),
+ rx_color: Some("#458588".to_string()),
+ tx_color: Some("#fabd2f".to_string()),
+ rx_total_color: Some("#83a598".to_string()),
+ tx_total_color: Some("#d79921".to_string()),
+ border_color: Some("#ebdbb2".to_string()),
+ highlighted_border_color: Some("#fe8019".to_string()),
+ disabled_text_color: Some("#665c54".to_string()),
+ text_color: Some("#ebdbb2".to_string()),
+ selected_text_color: Some("#1d2021".to_string()),
+ selected_bg_color: Some("#ebdbb2".to_string()),
+ widget_title_color: Some("#ebdbb2".to_string()),
+ graph_color: Some("#ebdbb2".to_string()),
+ high_battery_color: Some("#98971a".to_string()),
+ medium_battery_color: Some("#fabd2f".to_string()),
+ low_battery_color: Some("#fb4934".to_string())
+ };
+ pub static ref GRUVBOX_LIGHT_COLOUR_PALETTE: ConfigColours = ConfigColours {
+ table_header_color: Some("#3c3836".to_string()),
+ all_cpu_color: Some("#cc241d".to_string()),
+ avg_cpu_color: Some("#98971a".to_string()),
+ cpu_core_colors: Some(vec![
+ "#d79921".to_string(),
+ "#458588".to_string(),
+ "#b16286".to_string(),
+ "#689d6a".to_string(),
+ "#fb4934".to_string(),
+ "#b8bb26".to_string(),
+ "#fe8019".to_string(),
+ "#fabd2f".to_string(),
+ "#83a598".to_string(),
+ "#d3869b".to_string(),
+ "#8ec07c".to_string(),
+ "#d65d0e".to_string(),
+ "#928374".to_string(),
+ "#665c54".to_string(),
+ "#504945".to_string(),
+ "#3c3836".to_string(),
+ "#282828".to_string(),
+ ]),
+ ram_color: Some("#458588".to_string()),
+ swap_color: Some("#cc241d".to_string()),
+ rx_color: Some("#458588".to_string()),
+ tx_color: Some("#cc241d".to_string()),
+ rx_total_color: Some("#83a598".to_string()),
+ tx_total_color: Some("#9d0006".to_string()),
+ border_color: Some("#3c3836".to_string()),
+ highlighted_border_color: Some("#fe8019".to_string()),
+ disabled_text_color: Some("#665c54".to_string()),
+ text_color: Some("#3c3836".to_string()),
+ selected_text_color: Some("#f9f5d7".to_string()),
+ selected_bg_color: Some("#665c54".to_string()),
+ widget_title_color: Some("#3c3836".to_string()),
+ graph_color: Some("#3c3836".to_string()),
+ high_battery_color: Some("#98971a".to_string()),
+ medium_battery_color: Some("#fabd2f".to_string()),
+ low_battery_color: Some("#fb4934".to_string())
+ };
+ // pub static ref NORD_COLOUR_PALETTE: ConfigColours = ConfigColours {
+ // table_header_color: None,
+ // all_cpu_color: None,
+ // avg_cpu_color: None,
+ // cpu_core_colors: None,
+ // ram_color: None,
+ // swap_color: None,
+ // rx_color: None,
+ // tx_color: None,
+ // rx_total_color: None,
+ // tx_total_color: None,
+ // border_color: None,
+ // highlighted_border_color: None,
+ // text_color: None,
+ // selected_text_color: None,
+ // selected_bg_color: None,
+ // widget_title_color: None,
+ // graph_color: None,
+ // high_battery_color: None,
+ // medium_battery_color: None,
+ // low_battery_color: None,
+ // disabled_text_color: None,
+ // };
+}
+
// FIXME: [HELP] I wanna update this before release... it's missing mouse too.
// Help text
pub const HELP_CONTENTS_TEXT: [&str; 8] = [
diff --git a/src/options.rs b/src/options.rs
index 27d722ae..07be698f 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -1,13 +1,16 @@
use regex::Regex;
use serde::{Deserialize, Serialize};
-use std::{borrow::Cow, time::Instant};
use std::{
+ borrow::Cow,
collections::{HashMap, HashSet},
path::PathBuf,
+ str::FromStr,
+ time::Instant,
};
use crate::{
app::{layout_manager::*, *},
+ canvas::ColourScheme,
constants::*,
utils::error::{self, BottomError},
};
@@ -112,6 +115,9 @@ pub struct ConfigFlags {
#[builder(default, setter(strip_option))]
pub no_write: Option<bool>,
+ #[builder(default, setter(strip_option))]
+ pub color: Option<String>,
+
// This is a huge hack to enable hashmap functionality WITHOUT being able to serializing the field.
// Basically, keep a hashmap in the struct, and convert to a vector every time.
#[builder(default, setter(strip_option))]
@@ -164,16 +170,19 @@ pub struct ConfigColours {
pub swap_color: Option<String>,
pub rx_color: Option<String>,
pub tx_color: Option<String>,
- pub rx_total_color: Option<String>,
- pub tx_total_color: Option<String>,
+ pub rx_total_color: Option<String>, // These only affect basic mode.
+ pub tx_total_color: Option<String>, // These only affect basic mode.
pub border_color: Option<String>,
pub highlighted_border_color: Option<String>,
+ pub disabled_text_color: Option<String>,
pub text_color: Option<String>,
pub selected_text_color: Option<String>,
pub selected_bg_color: Option<String>,
pub widget_title_color: Option<String>,
pub graph_color: Option<String>,
- pub battery_colors: Option<Vec<String>>,
+ pub high_battery_color: Option<String>,
+ pub medium_battery_color: Option<String>,
+ pub low_battery_color: Option<String>,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
@@ -803,7 +812,7 @@ fn get_disable_click(matches: &clap::ArgMatches<'static>, config: &Config) -> bo
false
}
-pub fn get_use_old_network_legend(matches: &clap::ArgMatches<'static>, config: &Config) -> bool {
+fn get_use_old_network_legend(matches: &clap::ArgMatches<'static>, config: &Config) -> bool {
if matches.is_present("use_old_network_legend") {
return true;
} else if let Some(flags) = &config.flags {
@@ -814,7 +823,7 @@ pub fn get_use_old_network_legend(matches: &clap::ArgMatches<'static>, config: &
false
}
-pub fn get_hide_table_gap(matches: &clap::ArgMatches<'static>, config: &Config) -> bool {
+fn get_hide_table_gap(matches: &clap::ArgMatches<'static>, config: &Config) -> bool {
if matches.is_present("hide_table_gap") {
return true;
} else if let Some(flags) = &config.flags {
@@ -825,7 +834,7 @@ pub fn get_hide_table_gap(matches: &clap::ArgMatches<'static>, config: &Config)
false
}
-pub fn get_use_battery(matches: &clap::ArgMatches<'static>, config: &Config) -> bool {
+fn get_use_battery(matches: &clap::ArgMatches<'static>, config: &Config) -> bool {
if matches.is_present("battery") {
return true;
} else if let Some(flags) = &config.flags {
@@ -836,7 +845,7 @@ pub fn get_use_battery(matches: &clap::ArgMatches<'static>, config: &Config) ->
false
}
-pub fn get_no_write(matches: &clap::ArgMatches<'static>, config: &Config) -> bool {
+fn get_no_write(matches: &clap::ArgMatches<'static>, config: &Config) -> bool {
if matches.is_present("no_write") {
return true;
} else if let Some(flags) = &config.flags {
@@ -847,7 +856,7 @@ pub fn get_no_write(matches: &clap::ArgMatches<'static>, config: &Config) -> boo
false
}
-pub fn get_ignore_list(ignore_list: &Option<IgnoreList>) -> error::Result<Option<Filter>> {
+fn get_ignore_list(ignore_list: &Option<IgnoreList>) -> error::Result<Option<Filter>> {
if let Some(ignore_list) = ignore_list {
let list: Result<Vec<_>, _> = ignore_list
.list
@@ -888,3 +897,23 @@ pub fn get_ignore_list(ignore_list: &Option<IgnoreList>) -> error::Result<Option
Ok(None)
}
}
+
+pub fn get_color_scheme(
+ matches: &clap::ArgMatches<'static>, config: &Config,
+) -> error::Result<ColourScheme> {
+ if let Some(color) = matches.value_of("color") {
+ // Highest priority is always command line flags...
+ return ColourScheme::from_str(color);
+ } else if config.colors.is_some() {
+ // Then, give priority to custom colours...
+ return Ok(ColourScheme::Custom);
+ } else if let Some(flags) = &config.flags {
+ // Last priority is config file flags...
+ if let Some(color) = &flags.color {
+ return ColourScheme::from_str(color);
+ }
+ }
+
+ // And lastly, the final case is just "default".
+ Ok(ColourScheme::Default)
+}
<