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).
This commit is contained in:
FichteFoll 2021-09-01 15:37:03 +02:00
parent 93857d0675
commit 8974332651
3 changed files with 18 additions and 7 deletions

View File

@ -20,7 +20,7 @@ pub fn selectable_list<'a, C: AsRef<str>>(
pub fn layout(r: Rect) -> Vec<Rect> {
Layout::default()
.direction(Direction::Vertical)
.direction(Direction::Horizontal)
.constraints(
[
Constraint::Percentage(0),

View File

@ -97,7 +97,7 @@ impl TimeSheet {
&self.times[self.selected]
}
fn grouped_times(&self) -> impl Iterator<Item = (String, Duration)> {
fn grouped_times(&self) -> collections::BTreeMap<String, Duration> {
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 {

View File

@ -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())