From 3b0ae30021c4ff3f4be9ff96f08c01246bc87dec Mon Sep 17 00:00:00 2001 From: Tyler Ryan Date: Sat, 3 Dec 2022 01:50:57 -0600 Subject: [PATCH] Added Customization features to the Stats View. The user can now customize: - Background color - Foreground color --- src/utils.rs | 36 ++++++++++++++++++++++++------------ src/views.rs | 18 ++++++++++-------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 2d0d3f2..d9543fc 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -48,17 +48,21 @@ impl Default for Characters { #[derive(Serialize, Deserialize)] pub struct Colors { #[serde(default = "cyan")] - pub reached: String, + pub reached: String , #[serde(default = "magenta")] - pub todo: String, + pub todo: String , #[serde(default = "light_black")] - pub inactive: String, + pub inactive: String , #[serde(default = "magenta")] - pub future: String, + pub future: String , #[serde(default = "dark_white")] - pub cursor: String, + pub cursor: String , #[serde(default = "dark_red")] - pub today: String, + pub today: String , + #[serde(default = "light_black")] + pub stats_bar_bg: String , + #[serde(default = "cyan")] + pub stats_bar_fg: String , } // NOTE: These function are only used as the default values for @@ -72,12 +76,14 @@ fn dark_red() -> String { "dark white".into() } impl Default for Colors { fn default() -> Self { Colors { - reached: cyan(), - todo: magenta(), - inactive: light_black(), - future: magenta(), - cursor: light_black(), - today: dark_red(), + reached: cyan(), + todo: magenta(), + inactive: light_black(), + future: magenta(), + cursor: light_black(), + today: dark_red(), + stats_bar_bg: light_black(), + stats_bar_fg: light_black(), } } } @@ -120,6 +126,12 @@ impl AppConfig { pub fn today_color(&self) -> Color { return Color::parse(&self.colors.today).unwrap_or(Color::Dark(BaseColor::Red)); } + pub fn stats_bar_bg_color(&self) -> Color { + return Color::parse(&self.colors.stats_bar_bg).unwrap_or(Color::Light(BaseColor::Black)); + } + pub fn stats_bar_fg_color(&self) -> Color { + return Color::parse(&self.colors.stats_bar_fg).unwrap_or(Color::Dark(BaseColor::White)); + } } pub fn load_configuration_file() -> AppConfig { diff --git a/src/views.rs b/src/views.rs index 51cf3ca..f292f26 100644 --- a/src/views.rs +++ b/src/views.rs @@ -40,10 +40,12 @@ where let is_this_month = now.month() == Local::now().month(); let is_this_year = now.year() == Local::now().year(); - let goal_reached_style = Style::from(CONFIGURATION.reached_color()); - let mut future_style = Style::from(CONFIGURATION.future_color()); - let mut today_style = Style::from(CONFIGURATION.today_color()); - let mut past_style = Style::from(CONFIGURATION.inactive_color()); + let goal_reached_style = Style::from(CONFIGURATION.reached_color()); + let mut future_style = Style::from(CONFIGURATION.future_color()); + let mut today_style = Style::from(CONFIGURATION.today_color()); + let mut past_style = Style::from(CONFIGURATION.inactive_color()); + let stats_bar_bg_style = Style::from(CONFIGURATION.stats_bar_bg_color()); + let stats_bar_fg_style = Style::from(CONFIGURATION.stats_bar_fg_color()); let strikethrough = Style::from(Effect::Strikethrough); let bold = Style::from(Effect::Bold); @@ -91,17 +93,17 @@ where } else { 0.0 }; - printer.with_style(future_style, |p| { + printer.with_style(stats_bar_bg_style, |p| { p.print((4, line_nr), &"─".repeat(full)); }); - printer.with_style(goal_reached_style, |p| { + printer.with_style(stats_bar_fg_style, |p| { p.print((4, line_nr), &"─".repeat(bars_to_fill as usize)); }); printer.with_style( if is_this_week { - Style::none() - } else { future_style + } else { + Style::none() }, |p| { p.print((0, line_nr), &format!("{:2.0}% ", percentage));