Skip to content

Commit

Permalink
Merge pull request #5 from Tylryan/customize-stats-bar-colors
Browse files Browse the repository at this point in the history
Added Customization features to the Stats View.
  • Loading branch information
Tylryan authored Dec 3, 2022
2 parents 6d3733e + 3b0ae30 commit 66a5bb4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
36 changes: 24 additions & 12 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 10 additions & 8 deletions src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 66a5bb4

Please sign in to comment.