Skip to content

Commit

Permalink
Issue oppiliappan#121: Cursor Color Customization
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Tylryan committed Nov 28, 2022
1 parent 43c995e commit 3f1f31c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
// }
48 changes: 48 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -55,13 +58,55 @@ 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 {
Colors {
reached: cyan(),
todo: magenta(),
inactive: light_black(),
cursor: light_black(),
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 3f1f31c

Please sign in to comment.