diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app.rs | 6 | ||||
-rw-r--r-- | src/habit.rs | 1 | ||||
-rw-r--r-- | src/views.rs | 12 |
3 files changed, 11 insertions, 8 deletions
@@ -287,16 +287,16 @@ impl View for App { | |||
287 | if self.habits.is_empty() { | 287 | if self.habits.is_empty() { |
288 | return EventResult::Consumed(None); | 288 | return EventResult::Consumed(None); |
289 | } | 289 | } |
290 | if self.habits[self.focus].view_mode() == ViewMode::Month { | 290 | if self.habits[self.focus].view_mode() == ViewMode::Week { |
291 | self.set_mode(ViewMode::Day) | 291 | self.set_mode(ViewMode::Day) |
292 | } else { | 292 | } else { |
293 | self.set_mode(ViewMode::Month) | 293 | self.set_mode(ViewMode::Week) |
294 | } | 294 | } |
295 | return EventResult::Consumed(None); | 295 | return EventResult::Consumed(None); |
296 | } | 296 | } |
297 | Event::Char('V') => { | 297 | Event::Char('V') => { |
298 | for habit in self.habits.iter_mut() { | 298 | for habit in self.habits.iter_mut() { |
299 | habit.set_view_mode(ViewMode::Month); | 299 | habit.set_view_mode(ViewMode::Week); |
300 | } | 300 | } |
301 | return EventResult::Consumed(None); | 301 | return EventResult::Consumed(None); |
302 | } | 302 | } |
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 { | |||
18 | #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] | 18 | #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] |
19 | pub enum ViewMode { | 19 | pub enum ViewMode { |
20 | Day, | 20 | Day, |
21 | Week, | ||
21 | Month, | 22 | Month, |
22 | Year, | 23 | Year, |
23 | } | 24 | } |
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 | |||
75 | let completions = weekly_goal - remaining; | 75 | let completions = weekly_goal - remaining; |
76 | let full = CONFIGURATION.view_width - 8; | 76 | let full = CONFIGURATION.view_width - 8; |
77 | let bars_to_fill = (completions * full as u32) / weekly_goal; | 77 | let bars_to_fill = (completions * full as u32) / weekly_goal; |
78 | let percentage = (completions as f64 * 100f64) / weekly_goal as f64; | 78 | let percentage = (completions as f64 * 100.) / weekly_goal as f64; |
79 | printer.with_style(future_style, |p| { | 79 | printer.with_style(future_style, |p| { |
80 | p.print((4, line_nr), &"―".repeat(full)); | 80 | p.print((4, line_nr), &"―".repeat(full)); |
81 | }); | 81 | }); |
@@ -89,14 +89,15 @@ where | |||
89 | future_style | 89 | future_style |
90 | }, | 90 | }, |
91 | |p| { | 91 | |p| { |
92 | p.print((0, line_nr), &format!("{:3.0}% ", percentage)); | 92 | p.print((0, line_nr), &format!("{:2.0}% ", percentage)); |
93 | }, | 93 | }, |
94 | ); | 94 | ); |
95 | } | 95 | } |
96 | }; | 96 | }; |
97 | |||
97 | let draw_day = |printer: &Printer| { | 98 | let draw_day = |printer: &Printer| { |
98 | let mut i = 1; | 99 | let mut i = 0; |
99 | while let Some(d) = NaiveDate::from_ymd_opt(year, month, i) { | 100 | while let Some(d) = NaiveDate::from_ymd_opt(year, month, i + 1) { |
100 | let day_style; | 101 | let day_style; |
101 | if self.reached_goal(d) { | 102 | if self.reached_goal(d) { |
102 | day_style = goal_reached_style; | 103 | day_style = goal_reached_style; |
@@ -116,9 +117,10 @@ where | |||
116 | i += 1; | 117 | i += 1; |
117 | } | 118 | } |
118 | }; | 119 | }; |
120 | |||
119 | match self.view_mode() { | 121 | match self.view_mode() { |
120 | ViewMode::Day => draw_day(printer), | 122 | ViewMode::Day => draw_day(printer), |
121 | ViewMode::Month => draw_month(printer), | 123 | ViewMode::Week => draw_month(printer), |
122 | _ => draw_day(printer), | 124 | _ => draw_day(printer), |
123 | }; | 125 | }; |
124 | } | 126 | } |