From 3f1f31ca93e22aa3e015a3a77596d883e1f2dec7 Mon Sep 17 00:00:00 2001 From: Tyler Ryan Date: Sun, 27 Nov 2022 21:08:15 -0600 Subject: [PATCH] Issue #121: Cursor Color Customization The user can now specify which color they want the cursor to be in the config file. E.g. --- cursor = "light blue" --- Additionally, I've added a few more colors to choose from. --- src/theme.rs | 6 +++--- src/utils.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/views.rs | 4 ++-- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/theme.rs b/src/theme.rs index 879584c..b5d47ee 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -25,6 +25,6 @@ pub fn theme_gen() -> Theme { return t; } -pub fn cursor_bg() -> Color { - Light(cursive::theme::BaseColor::Black) -} +// pub fn cursor_bg() -> Color { +// Light(cursive::theme::BaseColor::Black) +// } diff --git a/src/utils.rs b/src/utils.rs index f5a25c8..c9a2576 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -44,8 +44,11 @@ pub struct Colors { pub todo: String, #[serde(default = "light_black")] pub inactive: String, + #[serde(default = "dark_white")] + pub cursor: String, } +// Cyan and Magenta are dark by default fn cyan() -> String { "cyan".into() } @@ -55,6 +58,47 @@ fn magenta() -> String { fn light_black() -> String { "light black".into() } +fn light_cyan() -> String { + "light cyan".into() +} +fn light_magenta() -> String { + "light magenta".into() +} +fn light_blue() -> String { + "light blue".into() +} +fn light_green() -> String { + "light green".into() +} +fn light_red() -> String { + "light red".into() +} +fn light_white() -> String { + "light white".into() +} +fn light_yellow() -> String { + "light yellow".into() +} +fn dark_white() -> String { + "dark white".into() +} +fn dark_black() -> String { + "dark black".into() +} +fn dark_blue() -> String { + "dark blue".into() +} +fn dark_green() -> String { + "dark green".into() +} +fn dark_red() -> String { + "dark red".into() +} +fn dark_yellow() -> String { + "dark yellow".into() +} + + impl Default for Colors { fn default() -> Self { @@ -62,6 +106,7 @@ impl Default for Colors { reached: cyan(), todo: magenta(), inactive: light_black(), + cursor: light_black(), } } } @@ -95,6 +140,9 @@ impl AppConfig { pub fn inactive_color(&self) -> Color { return Color::parse(&self.colors.inactive).unwrap_or(Color::Light(BaseColor::Black)); } + pub fn cursor_color(&self) -> Color { + return Color::parse(&self.colors.cursor).unwrap_or(Color::Light(BaseColor::Black)); + } } pub fn load_configuration_file() -> AppConfig { diff --git a/src/views.rs b/src/views.rs index 1bda8a8..2ce8244 100644 --- a/src/views.rs +++ b/src/views.rs @@ -8,7 +8,7 @@ use chrono::prelude::*; use chrono::{Local, NaiveDate}; use crate::habit::{Bit, Count, Float, Habit, TrackEvent, ViewMode}; -use crate::theme::cursor_bg; +// use crate::theme::cursor_bg; use crate::utils::VIEW_WIDTH; use crate::CONFIGURATION; @@ -115,7 +115,7 @@ where let mut fs = future_style; let grs = ColorStyle::front(CONFIGURATION.reached_color()); let ts = ColorStyle::front(CONFIGURATION.todo_color()); - let cs = ColorStyle::back(cursor_bg()); + let cs = ColorStyle::back(CONFIGURATION.cursor_color()); if self.reached_goal(d) { day_style = day_style.combine(Style::from(grs));