From 6f572a1384cfa2aa7cc0c0412b762d03a55f3024 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 12 Jul 2020 14:39:51 +0530 Subject: improve spacing, line counting; add Week mode to enums --- src/app.rs | 6 +++--- src/habit.rs | 1 + src/views.rs | 12 +++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/app.rs b/src/app.rs index 1240877..f8797fc 100644 --- a/src/app.rs +++ b/src/app.rs @@ -287,16 +287,16 @@ impl View for App { if self.habits.is_empty() { return EventResult::Consumed(None); } - if self.habits[self.focus].view_mode() == ViewMode::Month { + if self.habits[self.focus].view_mode() == ViewMode::Week { self.set_mode(ViewMode::Day) } else { - self.set_mode(ViewMode::Month) + self.set_mode(ViewMode::Week) } return EventResult::Consumed(None); } Event::Char('V') => { for habit in self.habits.iter_mut() { - habit.set_view_mode(ViewMode::Month); + habit.set_view_mode(ViewMode::Week); } return EventResult::Consumed(None); } diff --git a/src/habit.rs b/src/habit.rs index cb6f03d..725e15f 100644 --- a/src/habit.rs +++ b/src/habit.rs @@ -18,6 +18,7 @@ pub enum TrackEvent { #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] pub enum ViewMode { Day, + Week, Month, Year, } diff --git a/src/views.rs b/src/views.rs index f5ba01b..9e4a844 100644 --- a/src/views.rs +++ b/src/views.rs @@ -75,7 +75,7 @@ where let completions = weekly_goal - remaining; let full = CONFIGURATION.view_width - 8; let bars_to_fill = (completions * full as u32) / weekly_goal; - let percentage = (completions as f64 * 100f64) / weekly_goal as f64; + let percentage = (completions as f64 * 100.) / weekly_goal as f64; printer.with_style(future_style, |p| { p.print((4, line_nr), &"―".repeat(full)); }); @@ -89,14 +89,15 @@ where future_style }, |p| { - p.print((0, line_nr), &format!("{:3.0}% ", percentage)); + p.print((0, line_nr), &format!("{:2.0}% ", percentage)); }, ); } }; + let draw_day = |printer: &Printer| { - let mut i = 1; - while let Some(d) = NaiveDate::from_ymd_opt(year, month, i) { + let mut i = 0; + while let Some(d) = NaiveDate::from_ymd_opt(year, month, i + 1) { let day_style; if self.reached_goal(d) { day_style = goal_reached_style; @@ -116,9 +117,10 @@ where i += 1; } }; + match self.view_mode() { ViewMode::Day => draw_day(printer), - ViewMode::Month => draw_month(printer), + ViewMode::Week => draw_month(printer), _ => draw_day(printer), }; } -- cgit v1.2.3