From 9a83417067ee86a991163308b99a312230ac5fb1 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Tue, 3 Nov 2020 00:11:42 -0700 Subject: [PATCH] Add color for active context in context switcher --- src/app.rs | 13 +++++++++++-- src/config.rs | 21 ++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/app.rs b/src/app.rs index 021f99c..0821301 100644 --- a/src/app.rs +++ b/src/app.rs @@ -391,9 +391,18 @@ impl TTApp { let selected = self.context_table_state.selected().unwrap_or_default(); let header = headers.iter(); let mut rows = vec![]; - let style = Style::default(); + let mut highlight_style = Style::default(); for (i, context) in contexts.iter().enumerate() { + let mut style = Style::default(); + if &self.contexts[i].active == "yes" { + style = style + .fg(self.config.uda_style_context_active.fg) + .bg(self.config.uda_style_context_active.bg) + } rows.push(Row::StyledData(context.iter(), style)); + if i == self.context_table_state.selected().unwrap_or_default() { + highlight_style = style; + } } let constraints: Vec = widths @@ -401,7 +410,7 @@ impl TTApp { .map(|i| Constraint::Length((*i).try_into().unwrap_or(maximum_column_width as u16))) .collect(); - let highlight_style = Style::default().add_modifier(Modifier::BOLD); + let highlight_style = highlight_style.add_modifier(Modifier::BOLD); let t = Table::new(header, rows.into_iter()) .block( Block::default() diff --git a/src/config.rs b/src/config.rs index 3ccdb63..8203cea 100644 --- a/src/config.rs +++ b/src/config.rs @@ -19,12 +19,18 @@ impl Default for TColor { impl TColor { pub fn default() -> Self { - TColor { + Self { fg: Color::Black, bg: Color::White, modifiers: vec![], } } + + pub fn new(fg: Color, bg: Color, modifiers: Vec) -> Self { + Self { + fg, bg, modifiers, + } + } } #[derive(Debug)] @@ -41,6 +47,7 @@ pub struct Config { pub uda_selection_dim: bool, pub uda_selection_blink: bool, pub uda_calendar_months_per_row: usize, + pub uda_style_context_active: TColor, } trait TaskWarriorBool { @@ -87,6 +94,8 @@ impl Config { uda_selection_dim: Self::get_uda_selection_dim(), uda_selection_blink: Self::get_uda_selection_blink(), uda_calendar_months_per_row: Self::get_uda_months_per_row(), + uda_style_context_active: Self::get_uda_style("context.active") + .unwrap_or(TColor::new(Color::Black, Color::Rgb(220, 220, 220), vec![])), }) } @@ -94,6 +103,16 @@ impl Config { HashMap::new() } + fn get_uda_style(config: &str) -> Option { + let c = format!("uda.taskwarrior-tui.style.{}", config); + let s = Self::get_config(&c); + if s == "" { + None + } else { + Some(Self::get_tcolor(&s)) + } + } + fn get_color_collection() -> Result, Box> { let mut color_collection = HashMap::new(); let output = Command::new("task").arg("rc.color=off").arg("show").output()?;