mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-25 08:47:18 +02:00
Support color for selected item
This commit is contained in:
parent
a05f4f98a6
commit
28636e112d
2 changed files with 102 additions and 107 deletions
56
src/app.rs
56
src/app.rs
|
@ -385,11 +385,6 @@ impl TTApp {
|
|||
}
|
||||
|
||||
fn draw_task_report(&mut self, f: &mut Frame<impl Backend>, rect: Rect) {
|
||||
let _active_style = Style::default()
|
||||
.fg(Color::Blue)
|
||||
.add_modifier(Modifier::BOLD);
|
||||
let normal_style = Style::default();
|
||||
|
||||
let (tasks, headers, widths) = self.task_report();
|
||||
if tasks.is_empty() {
|
||||
f.render_widget(
|
||||
|
@ -400,37 +395,40 @@ impl TTApp {
|
|||
}
|
||||
let selected = self.state.selected().unwrap_or_default();
|
||||
let header = headers.iter();
|
||||
let ctasks = self.tasks.lock().unwrap().clone();
|
||||
let blocking = &self.colors.blocking;
|
||||
let active = &self.colors.active;
|
||||
let blocked = &self.colors.blocked;
|
||||
let rows = tasks.iter().enumerate().map(|(i, val)| {
|
||||
if ctasks[i]
|
||||
let mut rows = vec![];
|
||||
let mut highlight_style = Style::default();
|
||||
for (i, task) in tasks.into_iter().enumerate() {
|
||||
let mut normal_style = Style::default();
|
||||
if self.tasks.lock().unwrap()[i]
|
||||
.tags()
|
||||
.unwrap_or(&vec![])
|
||||
.join(" ")
|
||||
.contains(&"ACTIVE".to_string())
|
||||
{
|
||||
return Row::StyledData(val.iter(), Style::default().fg(active.fg).bg(active.bg));
|
||||
}
|
||||
if ctasks[i]
|
||||
.tags()
|
||||
.unwrap_or(&vec![])
|
||||
.contains(&"BLOCKED".to_string())
|
||||
{
|
||||
Row::StyledData(val.iter(), normal_style.fg(blocked.fg).bg(blocked.bg))
|
||||
} else if ctasks[i]
|
||||
normal_style = normal_style
|
||||
.fg(self.colors.active.fg)
|
||||
.bg(self.colors.active.bg);
|
||||
} else if self.tasks.lock().unwrap()[i]
|
||||
.tags()
|
||||
.unwrap_or(&vec![])
|
||||
.contains(&"BLOCKING".to_string())
|
||||
{
|
||||
Row::StyledData(val.iter(), normal_style.fg(blocking.fg).bg(blocked.bg))
|
||||
} else if ctasks[i].due().is_some() {
|
||||
Row::StyledData(val.iter(), normal_style)
|
||||
} else {
|
||||
Row::StyledData(val.iter(), normal_style)
|
||||
normal_style = normal_style
|
||||
.fg(self.colors.blocked.fg)
|
||||
.bg(self.colors.blocked.bg);
|
||||
} else if self.tasks.lock().unwrap()[i]
|
||||
.tags()
|
||||
.unwrap_or(&vec![])
|
||||
.contains(&"BLOCKED".to_string())
|
||||
{
|
||||
normal_style = normal_style
|
||||
.fg(self.colors.blocked.fg)
|
||||
.bg(self.colors.blocked.bg);
|
||||
}
|
||||
});
|
||||
if i == selected {
|
||||
highlight_style = normal_style.add_modifier(Modifier::BOLD);
|
||||
}
|
||||
rows.push(Row::StyledData(task.into_iter(), normal_style));
|
||||
}
|
||||
let constraints: Vec<Constraint> = widths
|
||||
.iter()
|
||||
.map(|i| {
|
||||
|
@ -438,9 +436,9 @@ impl TTApp {
|
|||
})
|
||||
.collect();
|
||||
|
||||
let t = Table::new(header, rows)
|
||||
let t = Table::new(header, rows.into_iter())
|
||||
.block(Block::default().borders(Borders::ALL).title("Task next"))
|
||||
.highlight_style(normal_style.add_modifier(Modifier::BOLD))
|
||||
.highlight_style(highlight_style.add_modifier(Modifier::BOLD))
|
||||
.highlight_symbol("• ")
|
||||
.widths(&constraints);
|
||||
f.render_stateful_widget(t, rect, &mut self.state);
|
||||
|
|
153
src/color.rs
153
src/color.rs
|
@ -69,44 +69,41 @@ pub struct TColorConfig {
|
|||
pub warning: TColor,
|
||||
}
|
||||
|
||||
pub fn get_color(line: &str) -> TColor {
|
||||
pub fn get_color(s: &str) -> Color {
|
||||
if s.starts_with("color") {
|
||||
let fg = (s.as_bytes()[5] as char).to_digit(10).unwrap() as u8;
|
||||
Color::Indexed(fg)
|
||||
} else if s.starts_with("rgb") {
|
||||
let red = (s.as_bytes()[3] as char).to_digit(10).unwrap() as u8;
|
||||
let green = (s.as_bytes()[4] as char).to_digit(10).unwrap() as u8;
|
||||
let blue = (s.as_bytes()[5] as char).to_digit(10).unwrap() as u8;
|
||||
Color::Indexed(16 + red * 36 + green * 6 + blue)
|
||||
} else {
|
||||
if s == "white" {
|
||||
Color::White
|
||||
} else if s == "black" {
|
||||
Color::Black
|
||||
} else {
|
||||
Color::Indexed(15)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_tcolor(line: &str) -> TColor {
|
||||
if line.contains(" on ") {
|
||||
let foreground = line.split(" ").collect::<Vec<&str>>()[0];
|
||||
let background = line.split(" ").collect::<Vec<&str>>()[2];
|
||||
if foreground.starts_with("color") {
|
||||
let fg = (foreground.as_bytes()[5] as char).to_digit(10).unwrap() as u8;
|
||||
TColor {
|
||||
fg: Color::Indexed(fg),
|
||||
bg: Color::Indexed(15),
|
||||
}
|
||||
} else if foreground.starts_with("rgb") {
|
||||
let red = (foreground.as_bytes()[3] as char).to_digit(10).unwrap() as u8;
|
||||
let green = (foreground.as_bytes()[4] as char).to_digit(10).unwrap() as u8;
|
||||
let blue = (foreground.as_bytes()[5] as char).to_digit(10).unwrap() as u8;
|
||||
TColor {
|
||||
fg: Color::Indexed(16 + red * 36 + green * 6 + blue),
|
||||
bg: Color::Indexed(15),
|
||||
}
|
||||
} else {
|
||||
TColor::default()
|
||||
TColor {
|
||||
fg: get_color(foreground),
|
||||
bg: get_color(background),
|
||||
}
|
||||
} else if line.contains("on ") {
|
||||
TColor::default()
|
||||
} else {
|
||||
let foreground = line;
|
||||
if foreground.starts_with("color") {
|
||||
// TODO: get the correct color here
|
||||
TColor::default()
|
||||
} else if foreground.starts_with("rgb") {
|
||||
let red = (foreground.as_bytes()[3] as char).to_digit(10).unwrap() as u8;
|
||||
let green = (foreground.as_bytes()[4] as char).to_digit(10).unwrap() as u8;
|
||||
let blue = (foreground.as_bytes()[5] as char).to_digit(10).unwrap() as u8;
|
||||
TColor {
|
||||
fg: Color::Indexed(16 + red * 36 + green * 6 + blue),
|
||||
bg: Color::Indexed(15),
|
||||
}
|
||||
} else {
|
||||
TColor::default()
|
||||
TColor {
|
||||
fg: get_color(foreground),
|
||||
bg: Color::Indexed(15),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -172,283 +169,283 @@ impl TColorConfig {
|
|||
|
||||
for line in data.split('\n') {
|
||||
if line.starts_with("color.active ") {
|
||||
active = get_color(
|
||||
active = get_tcolor(
|
||||
line.trim_start_matches("color.active ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.alternate ") {
|
||||
alternate = get_color(
|
||||
alternate = get_tcolor(
|
||||
line.trim_start_matches("color.alternate ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.blocked ") {
|
||||
blocked = get_color(
|
||||
blocked = get_tcolor(
|
||||
line.trim_start_matches("color.blocked ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.blocking ") {
|
||||
blocking = get_color(
|
||||
blocking = get_tcolor(
|
||||
line.trim_start_matches("color.blocking ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.burndown.done ") {
|
||||
burndown_done = get_color(
|
||||
burndown_done = get_tcolor(
|
||||
line.trim_start_matches("color.burndown.done ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.burndown.pending ") {
|
||||
burndown_pending = get_color(
|
||||
burndown_pending = get_tcolor(
|
||||
line.trim_start_matches("color.burndown.pending ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.burndown.started ") {
|
||||
burndown_started = get_color(
|
||||
burndown_started = get_tcolor(
|
||||
line.trim_start_matches("color.burndown.started ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.calendar.due ") {
|
||||
calendar_due = get_color(
|
||||
calendar_due = get_tcolor(
|
||||
line.trim_start_matches("color.calendar.due ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.calendar.due.today ") {
|
||||
calendar_due_today = get_color(
|
||||
calendar_due_today = get_tcolor(
|
||||
line.trim_start_matches("color.calendar.due.today ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.calendar.holiday ") {
|
||||
calendar_holiday = get_color(
|
||||
calendar_holiday = get_tcolor(
|
||||
line.trim_start_matches("color.calendar.holiday ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.calendar.overdue ") {
|
||||
calendar_overdue = get_color(
|
||||
calendar_overdue = get_tcolor(
|
||||
line.trim_start_matches("color.calendar.overdue ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.calendar.today ") {
|
||||
calendar_today = get_color(
|
||||
calendar_today = get_tcolor(
|
||||
line.trim_start_matches("color.calendar.today ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.calendar.weekend ") {
|
||||
calendar_weekend = get_color(
|
||||
calendar_weekend = get_tcolor(
|
||||
line.trim_start_matches("color.calendar.weekend ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.calendar.weeknumber ") {
|
||||
calendar_weeknumber = get_color(
|
||||
calendar_weeknumber = get_tcolor(
|
||||
line.trim_start_matches("color.calendar.weeknumber ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.completed ") {
|
||||
completed = get_color(
|
||||
completed = get_tcolor(
|
||||
line.trim_start_matches("color.completed ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.debug ") {
|
||||
debug = get_color(
|
||||
debug = get_tcolor(
|
||||
line.trim_start_matches("color.debug ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.deleted ") {
|
||||
deleted = get_color(
|
||||
deleted = get_tcolor(
|
||||
line.trim_start_matches("color.deleted ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.due ") {
|
||||
due = get_color(
|
||||
due = get_tcolor(
|
||||
line.trim_start_matches("color.due ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.due.today ") {
|
||||
due_today = get_color(
|
||||
due_today = get_tcolor(
|
||||
line.trim_start_matches("color.due.today ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.error ") {
|
||||
error = get_color(
|
||||
error = get_tcolor(
|
||||
line.trim_start_matches("color.error ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.footnote ") {
|
||||
footnote = get_color(
|
||||
footnote = get_tcolor(
|
||||
line.trim_start_matches("color.footnote ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.header ") {
|
||||
header = get_color(
|
||||
header = get_tcolor(
|
||||
line.trim_start_matches("color.header ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.history.add ") {
|
||||
history_add = get_color(
|
||||
history_add = get_tcolor(
|
||||
line.trim_start_matches("color.history.add ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.history.delete ") {
|
||||
history_delete = get_color(
|
||||
history_delete = get_tcolor(
|
||||
line.trim_start_matches("color.history.delete ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.history.done ") {
|
||||
history_done = get_color(
|
||||
history_done = get_tcolor(
|
||||
line.trim_start_matches("color.history.done ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.label ") {
|
||||
label = get_color(
|
||||
label = get_tcolor(
|
||||
line.trim_start_matches("color.label ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.label.sort ") {
|
||||
label_sort = get_color(
|
||||
label_sort = get_tcolor(
|
||||
line.trim_start_matches("color.label.sort ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.overdue ") {
|
||||
overdue = get_color(
|
||||
overdue = get_tcolor(
|
||||
line.trim_start_matches("color.overdue ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.project.none ") {
|
||||
project = get_color(
|
||||
project = get_tcolor(
|
||||
line.trim_start_matches("color.project.none ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.recurring ") {
|
||||
recurring = get_color(
|
||||
recurring = get_tcolor(
|
||||
line.trim_start_matches("color.recurring ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.scheduled ") {
|
||||
scheduled = get_color(
|
||||
scheduled = get_tcolor(
|
||||
line.trim_start_matches("color.scheduled ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.summary.background ") {
|
||||
summary_background = get_color(
|
||||
summary_background = get_tcolor(
|
||||
line.trim_start_matches("color.summary.background ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.summary.bar ") {
|
||||
summary_bar = get_color(
|
||||
summary_bar = get_tcolor(
|
||||
line.trim_start_matches("color.summary.bar ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.sync.added ") {
|
||||
sync_added = get_color(
|
||||
sync_added = get_tcolor(
|
||||
line.trim_start_matches("color.sync.added ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.sync.changed ") {
|
||||
sync_changed = get_color(
|
||||
sync_changed = get_tcolor(
|
||||
line.trim_start_matches("color.sync.changed ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.sync.rejected ") {
|
||||
sync_rejected = get_color(
|
||||
sync_rejected = get_tcolor(
|
||||
line.trim_start_matches("color.sync.rejected ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.tag.next ") {
|
||||
tag_next = get_color(
|
||||
tag_next = get_tcolor(
|
||||
line.trim_start_matches("color.tag.next ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.tag.none ") {
|
||||
tag = get_color(
|
||||
tag = get_tcolor(
|
||||
line.trim_start_matches("color.tag.none ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.tagged ") {
|
||||
tagged = get_color(
|
||||
tagged = get_tcolor(
|
||||
line.trim_start_matches("color.tagged ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.uda.priority ") {
|
||||
uda_priority = get_color(
|
||||
uda_priority = get_tcolor(
|
||||
line.trim_start_matches("color.uda.priority ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.uda.priority.H ") {
|
||||
uda_priority_h = get_color(
|
||||
uda_priority_h = get_tcolor(
|
||||
line.trim_start_matches("color.uda.priority.H ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.uda.priority.L ") {
|
||||
uda_priority_l = get_color(
|
||||
uda_priority_l = get_tcolor(
|
||||
line.trim_start_matches("color.uda.priority.L ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.uda.priority.M ") {
|
||||
uda_priority_m = get_color(
|
||||
uda_priority_m = get_tcolor(
|
||||
line.trim_start_matches("color.uda.priority.M ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.undo.after ") {
|
||||
undo_after = get_color(
|
||||
undo_after = get_tcolor(
|
||||
line.trim_start_matches("color.undo.after ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.undo.before ") {
|
||||
undo_before = get_color(
|
||||
undo_before = get_tcolor(
|
||||
line.trim_start_matches("color.undo.before ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.until ") {
|
||||
until = get_color(
|
||||
until = get_tcolor(
|
||||
line.trim_start_matches("color.until ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
}
|
||||
if line.starts_with("color.warning") {
|
||||
warning = get_color(
|
||||
warning = get_tcolor(
|
||||
line.trim_start_matches("color.warning ")
|
||||
.trim_start_matches(" "),
|
||||
);
|
||||
|
@ -514,6 +511,6 @@ mod tests {
|
|||
#[test]
|
||||
fn test_colors() {
|
||||
let tc = TColorConfig::default();
|
||||
println!("{:?}", tc);
|
||||
println!("{:?}", tc.blocked);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue