task_tracker_cli/ui/
display.rs

1/// Display functions for rendering tasks in the terminal
2
3use crate::task::Task;
4use prettytable::{Table, row};
5use tracing::info;
6
7/// Displays a single task in a formatted table
8pub fn display_task(task: &Task) {
9    let mut table = Table::new();
10    table.add_row(row!["ID", "Description", "Status", "Created At", "Updated At"]);
11    table.add_row(row![
12        task.id,
13        task.description,
14        task.status.to_string(),
15        task.created_at.format("%Y-%m-%d %H:%M:%S"),
16        task.updated_at.format("%Y-%m-%d %H:%M:%S")
17    ]);
18    table.printstd();
19}
20
21/// Displays all tasks in a formatted table
22pub fn display_tasks(tasks: &[Task]) {
23    if tasks.is_empty() {
24        info!("No tasks to display");
25        return;
26    }
27
28    let mut table = Table::new();
29    table.add_row(row!["ID", "Description", "Status", "Created At", "Updated At"]);
30
31    for task in tasks {
32        table.add_row(row![
33            task.id,
34            task.description,
35            task.status.to_string(),
36            task.created_at.format("%Y-%m-%d %H:%M:%S"),
37            task.updated_at.format("%Y-%m-%d %H:%M:%S")
38        ]);
39    }
40
41    println!();
42    table.printstd();
43    println!();
44}