56 lines
1.3 KiB
Rust
56 lines
1.3 KiB
Rust
use colored::Colorize;
|
|
|
|
use crate::model::{Priority, Todo};
|
|
|
|
pub fn print_todo(todo: &Todo) {
|
|
let id = format!("{:>3}", todo.id).dimmed();
|
|
|
|
let priority = match todo.priority {
|
|
Priority::Critical => "CRIT".red().bold(),
|
|
Priority::High => "high".red(),
|
|
Priority::Medium => " med".yellow(),
|
|
Priority::Low => " low".dimmed(),
|
|
};
|
|
|
|
let done_mark = if todo.is_done() { "[x]" } else { "[ ]" };
|
|
|
|
let text = if todo.is_done() {
|
|
todo.text.strikethrough().dimmed().to_string()
|
|
} else {
|
|
todo.text.clone()
|
|
};
|
|
|
|
let tags = if todo.tags.is_empty() {
|
|
String::new()
|
|
} else {
|
|
todo.tags
|
|
.iter()
|
|
.map(|t| format!("#{t}"))
|
|
.collect::<Vec<_>>()
|
|
.join(" ")
|
|
.blue()
|
|
.to_string()
|
|
};
|
|
|
|
let project = todo
|
|
.project_short()
|
|
.map(|p| format!("({})", p).dimmed().to_string())
|
|
.unwrap_or_default();
|
|
|
|
println!("{id} {done_mark} [{priority}] {text} {tags} {project}");
|
|
}
|
|
|
|
pub fn print_todo_list(todos: &[Todo]) {
|
|
if todos.is_empty() {
|
|
println!("{}", "no todos found".dimmed());
|
|
return;
|
|
}
|
|
|
|
for todo in todos {
|
|
print_todo(todo);
|
|
}
|
|
|
|
let count = todos.len();
|
|
println!("{}", format!("\n{count} item(s)").dimmed());
|
|
}
|