From 89743326517bfc766fbdcde708c04a8a876a424d Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Wed, 1 Sep 2021 15:37:03 +0200 Subject: [PATCH] Render summary vertically With the todo list gone, it makes much more sense to render the summary vertically (and also to isolate the pause time). --- src/layout.rs | 2 +- src/timesheet.rs | 20 +++++++++++++++----- src/tracc.rs | 3 ++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/layout.rs b/src/layout.rs index c4fc68d..f19e288 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -20,7 +20,7 @@ pub fn selectable_list<'a, C: AsRef>( pub fn layout(r: Rect) -> Vec { Layout::default() - .direction(Direction::Vertical) + .direction(Direction::Horizontal) .constraints( [ Constraint::Percentage(0), diff --git a/src/timesheet.rs b/src/timesheet.rs index 450de0e..cbbc7de 100644 --- a/src/timesheet.rs +++ b/src/timesheet.rs @@ -97,7 +97,7 @@ impl TimeSheet { &self.times[self.selected] } - fn grouped_times(&self) -> impl Iterator { + fn grouped_times(&self) -> collections::BTreeMap { self.times .iter() .chain(iter::once(&TimePoint::new("end"))) @@ -111,22 +111,32 @@ impl TimeSheet { .or_insert_with(Duration::zero) += duration; map }) - .into_iter() } pub fn time_by_tasks(&self) -> String { self.grouped_times() + .into_iter() + .filter(|(text, _)| text != MAIN_PAUSE_TEXT) .map(|(text, duration)| format!("{}: {}", text, format_duration(&duration))) - .join(" | ") + .join("\n") } pub fn sum_as_str(&self) -> String { - let total = self - .grouped_times() + let total = self.grouped_times() + .into_iter() .filter(|(text, _)| text != MAIN_PAUSE_TEXT) .fold(Duration::zero(), |total, (_, d)| total + d); format_duration(&total) } + + pub fn pause_time(&self) -> String { + let times = self.grouped_times(); + let duration = times + .get(MAIN_PAUSE_TEXT) + .map(Duration::clone) + .unwrap_or_else(Duration::zero); + format!("{}: {}", MAIN_PAUSE_TEXT, format_duration(&duration)) + } } fn format_duration(d: &Duration) -> String { diff --git a/src/tracc.rs b/src/tracc.rs index fb20417..83501a5 100644 --- a/src/tracc.rs +++ b/src/tracc.rs @@ -118,8 +118,9 @@ impl Tracc { fn refresh(&mut self) -> Result<(), io::Error> { let summary_content = [Text::raw(format!( - "Sum for today: {}\n{}", + "Sum for today: {}\n{}\n\n{}", self.times.sum_as_str(), + self.times.pause_time(), self.times.time_by_tasks() ))]; let mut summary = Paragraph::new(summary_content.iter())