add labels in oneline view
This commit is contained in:
parent
74ec396296
commit
2aa573088c
2 changed files with 18 additions and 2 deletions
|
@ -2,7 +2,7 @@ use std::io::stdout;
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
style::{Color, SetForegroundColor},
|
style::{Color, SetBackgroundColor, SetForegroundColor},
|
||||||
ExecutableCommand,
|
ExecutableCommand,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,6 +16,13 @@ pub fn print_color(color: Color, txt: &str) {
|
||||||
stdout().execute(SetForegroundColor(Color::Reset)).unwrap();
|
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
|
/// Convert a HEX Color String into a `Color` struct
|
||||||
fn hex_to_color(hex: &str) -> Result<Color, String> {
|
fn hex_to_color(hex: &str) -> Result<Color, String> {
|
||||||
let hex = hex.trim_start_matches('#');
|
let hex = hex.trim_start_matches('#');
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{ProjectID, Task, VikunjaAPI},
|
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) {
|
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, " [✓]");
|
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");
|
print!("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue