add labels in oneline view

This commit is contained in:
JMARyA 2024-06-06 10:56:17 +02:00
parent 74ec396296
commit 2aa573088c
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
2 changed files with 18 additions and 2 deletions

View file

@ -2,7 +2,7 @@ use std::io::stdout;
use chrono::{DateTime, Utc};
use crossterm::{
style::{Color, SetForegroundColor},
style::{Color, SetBackgroundColor, SetForegroundColor},
ExecutableCommand,
};
@ -16,6 +16,13 @@ pub fn print_color(color: Color, txt: &str) {
stdout().execute(SetForegroundColor(Color::Reset)).unwrap();
}
/// Print `txt` with a custom `color` as background
pub fn print_color_bg(color: Color, txt: &str) {
stdout().execute(SetBackgroundColor(color)).unwrap();
print!("{txt}");
stdout().execute(SetBackgroundColor(Color::Reset)).unwrap();
}
/// Convert a HEX Color String into a `Color` struct
fn hex_to_color(hex: &str) -> Result<Color, String> {
let hex = hex.trim_start_matches('#');

View file

@ -1,6 +1,6 @@
use crate::{
api::{ProjectID, Task, VikunjaAPI},
ui::{parse_datetime, print_color, time_since},
ui::{hex_to_color, parse_datetime, print_color, print_color_bg, time_since},
};
fn print_task_oneline(task: &Task, api: &VikunjaAPI) {
@ -22,6 +22,15 @@ fn print_task_oneline(task: &Task, api: &VikunjaAPI) {
print_color(crossterm::style::Color::Green, " [✓]");
}
if let Some(labels) = &task.labels {
print!(" ");
for label in labels {
let color = hex_to_color(&label.hex_color).unwrap();
print_color_bg(color, &label.title.trim());
print!(" ");
}
}
print!("\n");
}