Skip to content

Commit

Permalink
Show total time in 'summarize' view (implements #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbor committed Sep 3, 2024
1 parent 7d03838 commit e84b8d7
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,23 +689,33 @@ fn summarize(filter: &Option<String>, tail: usize, args: &Args) -> Result<(), St
.collect();
table_items.sort();

let items_slice = if tail == 0 {
table_items.as_slice()
let mut tailed_items = if tail == 0 {
table_items
} else {
let len = table_items.len();
let idx = if len > tail { len - tail } else { 0 };
&table_items.as_slice()[idx..]
table_items[idx..].to_vec()
};

let table = Table::new(items_slice)
let total = SummaryTableItem {
month: "Total".to_owned(),
total_hours: tailed_items.iter().map(|i| i.total_hours)
.fold(HumanDuration { hours: 0, minutes: 0 }, |a, b| a + b),
hours_per_week: "-".to_owned(),
days: tailed_items.iter().map(|i| i.days).sum(),
nitems: tailed_items.iter().map(|i| i.nitems).sum(),
};

tailed_items.push(total);

let table = Table::new(tailed_items)
.with(Style::rounded())
.with(Rows::new(1..).not(Columns::first()).modify().with(Alignment::center()))
.with(Color::FG_GREEN)
.with(Margin::new(1, 1, 1, 1))
.to_string();
println!("{}", table);


Ok(())
}

Expand Down

0 comments on commit e84b8d7

Please # to comment.