mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-26 03:07:18 +02:00
Add color for active context in context switcher
This commit is contained in:
parent
2250c20cfa
commit
9a83417067
2 changed files with 31 additions and 3 deletions
13
src/app.rs
13
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<Constraint> = 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()
|
||||
|
|
|
@ -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<Modifier>) -> 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<TColor> {
|
||||
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<HashMap<String, TColor>, Box<dyn Error>> {
|
||||
let mut color_collection = HashMap::new();
|
||||
let output = Command::new("task").arg("rc.color=off").arg("show").output()?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue