From 17ed668aacd067c645d7de19d4dc7ae652aa760a Mon Sep 17 00:00:00 2001 From: P T Weir Date: Tue, 23 Jul 2024 12:03:00 +0100 Subject: fix(themes): Restore default theme, refactor (#2294) * fix(theme): let the base colour remain unchanged * fix(theme): split out default * fix(theme): make base theme 'default' not an empty string * wip(theme): return styles, not colors * wip(theme): tidy up module structure a little * wip(theme): removed unhandled references to foreground_color * chore: fix cargo fmt * feat(theme): allow crossterm-deserializable colors --- crates/atuin-history/src/stats.rs | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'crates/atuin-history/src') diff --git a/crates/atuin-history/src/stats.rs b/crates/atuin-history/src/stats.rs index 92e08340..6312f518 100644 --- a/crates/atuin-history/src/stats.rs +++ b/crates/atuin-history/src/stats.rs @@ -1,10 +1,10 @@ use std::collections::{HashMap, HashSet}; -use crossterm::style::{ResetColor, SetAttribute, SetForegroundColor}; +use crossterm::style::{Color, ResetColor, SetAttribute, SetForegroundColor}; use serde::{Deserialize, Serialize}; use unicode_segmentation::UnicodeSegmentation; -use atuin_client::{history::History, settings::Settings, theme::Theme}; +use atuin_client::{history::History, settings::Settings, theme::Meaning, theme::Theme}; #[derive(Debug, Serialize, Deserialize)] pub struct Stats { @@ -126,21 +126,42 @@ pub fn pretty_print(stats: Stats, ngram_size: usize, theme: &Theme) { }); for (command, count) in stats.top { - let gray = SetForegroundColor(theme.get_base()); + let gray = SetForegroundColor(match theme.as_style(Meaning::Muted).foreground_color { + Some(color) => color, + None => Color::Grey, + }); let bold = SetAttribute(crossterm::style::Attribute::Bold); let in_ten = 10 * count / max; print!("["); - print!("{}", SetForegroundColor(theme.get_error())); + print!( + "{}", + SetForegroundColor(match theme.get_error().foreground_color { + Some(color) => color, + None => Color::Red, + }) + ); for i in 0..in_ten { if i == 2 { - print!("{}", SetForegroundColor(theme.get_warning())); + print!( + "{}", + SetForegroundColor(match theme.get_warning().foreground_color { + Some(color) => color, + None => Color::Yellow, + }) + ); } if i == 5 { - print!("{}", SetForegroundColor(theme.get_info())); + print!( + "{}", + SetForegroundColor(match theme.get_info().foreground_color { + Some(color) => color, + None => Color::Green, + }) + ); } print!("▮"); -- cgit v1.3.1