set columns in t list

This commit is contained in:
Abraham Toriz 2021-07-15 11:48:33 -05:00
parent e703db5189
commit 28f041831b
No known key found for this signature in database
GPG Key ID: D5B4A746DB5DD42A
1 changed files with 34 additions and 11 deletions

View File

@ -47,6 +47,8 @@ impl<'a> Command<'a> for ListCommand {
db.entries_full(None, None)?
};
let current = db.current_sheet()?.unwrap_or("".into());
sheets.sort_unstable_by_key(|e| e.sheet.clone());
let sheets: Vec<_> = sheets
@ -55,24 +57,40 @@ impl<'a> Command<'a> for ListCommand {
.into_iter()
.map(|(key, group)| {
(
if current == key { "*".into() } else { "".into() },
key,
group.fold(Duration::seconds(0), |acc, e| {
"running".into(),
"today".into(),
// total
format_duration(group.fold(Duration::seconds(0), |acc, e| {
acc + (e.end.unwrap_or(now) - e.start)
}),
})),
)
})
.collect();
let mut tabs = Tabulate::with_columns(vec![
// indicator of current of prev sheet
Col::min_width(1).and_alignment(Right),
Col::min_width(1).and_alignment(Left),
Col::min_width(1).and_alignment(Right),
Col::min_width(1).and_alignment(Right),
Col::min_width(1).and_alignment(Right),
// sheet name
Col::min_width(9).and_alignment(Left),
// running time
Col::min_width(9).and_alignment(Right),
// today
Col::min_width(7).and_alignment(Right),
// accumulated
Col::min_width(12).and_alignment(Right),
]);
tabs.feed(vec!["".into(), "Timesheet".into(), "Running".into(), "Today".into(), "Total Time".into()]);
for sheet in sheets {
tabs.feed(vec![sheet.0, format_duration(sheet.1)]);
tabs.feed(vec![sheet.0, sheet.1, sheet.2, sheet.3, sheet.4]);
}
out.write_all(tabs.print().as_bytes())?;
@ -107,10 +125,10 @@ mod tests {
ListCommand::handle(args, &mut db, &mut out, &mut err, &config).unwrap();
assert_eq!(PrettyString(&String::from_utf8_lossy(&out)), PrettyString(" Timesheet Running Today Total Time
sheet1 0:00:00 0:00:00 10:13:55
*sheet2 0:00:00 0:00:00 0:00:00
sheet3 0:00:00 1:52:45 9:32:03
assert_eq!(PrettyString(&String::from_utf8_lossy(&out)), PrettyString(" Timesheet Running Today Total Time
sheet1 0:00:00 0:00:00 10:13:55
* sheet2 0:00:00 0:00:00 0:00:00
sheet3 0:00:00 1:52:45 9:32:03
"));
}
@ -118,4 +136,9 @@ mod tests {
fn list_sheets_shows_last() {
assert!(false);
}
#[test]
fn list_sheets_shows_running() {
assert!(false);
}
}