Skip to content

Commit

Permalink
feat(update): improve stat table
Browse files Browse the repository at this point in the history
  • Loading branch information
madonuko committed Jul 16, 2024
1 parent 0ce4683 commit 38c8272
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn update(
if val == v {
continue;
}
continue 'p; // filtered because label value doesn't match
}
continue 'p; // for any filters !match labels in proj (strict)
}
Expand Down Expand Up @@ -73,6 +74,10 @@ pub fn update(
}

tasks.sort_unstable_by(|(_, duration0), (_, duration1)| duration1.cmp(duration0));
let pname_len = tasks
.iter()
.max_by(|(name0, _), (name1, _)| name0.len().cmp(&name1.len()))
.map_or(13, |(name, _)| name.len());
let mut stdout = std::io::stdout();

writeln!(
Expand All @@ -83,11 +88,12 @@ pub fn update(
)
.unwrap();
writeln!(stdout, "Here is a list of unfiltered tasks:\n").unwrap();
writeln!(stdout, " Time (ms) Project").unwrap();
writeln!(stdout, "No. ══════════╤═════════").unwrap();
writeln!(stdout, "No. Time/ms Project/alias").unwrap();
writeln!(stdout, "═════╤════════╤═{}", "═".repeat(pname_len.max(13))).unwrap();

for (n, (name, duration)) in tasks.into_iter().enumerate() {
writeln!(stdout, "{:<5} {:>9} │ {name}", n + 1, duration.as_millis()).unwrap();
let sep = if n % 2 == 0 { '┃' } else { '│' };
writeln!(stdout, "{:<5}{sep}{:>7} {sep} {name}", n + 1, duration.as_millis()).unwrap();
}

Ok(())
Expand Down

0 comments on commit 38c8272

Please sign in to comment.