diff options
Diffstat (limited to 'src/views.rs')
-rw-r--r-- | src/views.rs | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/views.rs b/src/views.rs index 24c8a4d..efd1391 100644 --- a/src/views.rs +++ b/src/views.rs | |||
@@ -8,6 +8,7 @@ use chrono::prelude::*; | |||
8 | use chrono::{Duration, Local, NaiveDate}; | 8 | use chrono::{Duration, Local, NaiveDate}; |
9 | 9 | ||
10 | use crate::habit::{Bit, Count, Habit, TrackEvent, ViewMode}; | 10 | use crate::habit::{Bit, Count, Habit, TrackEvent, ViewMode}; |
11 | use crate::utils::VIEW_WIDTH; | ||
11 | 12 | ||
12 | use crate::CONFIGURATION; | 13 | use crate::CONFIGURATION; |
13 | 14 | ||
@@ -36,14 +37,14 @@ where | |||
36 | let year = now.year(); | 37 | let year = now.year(); |
37 | let month = now.month(); | 38 | let month = now.month(); |
38 | 39 | ||
39 | let goal_reached_style = Style::from(CONFIGURATION.reached_color); | 40 | let goal_reached_style = Style::from(CONFIGURATION.reached_color()); |
40 | let todo_style = Style::from(CONFIGURATION.todo_color); | 41 | let todo_style = Style::from(CONFIGURATION.todo_color()); |
41 | let future_style = Style::from(CONFIGURATION.future_color); | 42 | let future_style = Style::from(CONFIGURATION.inactive_color()); |
42 | 43 | ||
43 | let strikethrough = Style::from(Effect::Strikethrough); | 44 | let strikethrough = Style::from(Effect::Strikethrough); |
44 | 45 | ||
45 | let goal_status = | 46 | let goal_status = |
46 | self.view_month_offset() == 0 && self.reached_goal(Local::now().naive_utc().date()); | 47 | self.view_month_offset() == 0 && self.reached_goal(Local::now().naive_local().date()); |
47 | 48 | ||
48 | printer.with_style( | 49 | printer.with_style( |
49 | Style::merge(&[ | 50 | Style::merge(&[ |
@@ -61,11 +62,7 @@ where | |||
61 | |p| { | 62 | |p| { |
62 | p.print( | 63 | p.print( |
63 | (0, 0), | 64 | (0, 0), |
64 | &format!( | 65 | &format!(" {:.width$} ", self.name(), width = VIEW_WIDTH - 6), |
65 | " {:.width$} ", | ||
66 | self.name(), | ||
67 | width = CONFIGURATION.view_width - 6 | ||
68 | ), | ||
69 | ); | 66 | ); |
70 | }, | 67 | }, |
71 | ); | 68 | ); |
@@ -77,12 +74,20 @@ where | |||
77 | .collect::<Vec<_>>(); | 74 | .collect::<Vec<_>>(); |
78 | for (week, line_nr) in days.chunks(7).zip(2..) { | 75 | for (week, line_nr) in days.chunks(7).zip(2..) { |
79 | let weekly_goal = self.goal() * week.len() as u32; | 76 | let weekly_goal = self.goal() * week.len() as u32; |
80 | let is_this_week = week.contains(&Local::now().naive_utc().date()); | 77 | let is_this_week = week.contains(&Local::now().naive_local().date()); |
81 | let remaining = week.iter().map(|&i| self.remaining(i)).sum::<u32>(); | 78 | let remaining = week.iter().map(|&i| self.remaining(i)).sum::<u32>(); |
82 | let completions = weekly_goal - remaining; | 79 | let completions = weekly_goal - remaining; |
83 | let full = CONFIGURATION.view_width - 8; | 80 | let full = VIEW_WIDTH - 8; |
84 | let bars_to_fill = if weekly_goal > 0 {(completions * full as u32) / weekly_goal} else {0}; | 81 | let bars_to_fill = if weekly_goal > 0 { |
85 | let percentage = if weekly_goal > 0 {(completions as f64 * 100.) / weekly_goal as f64} else {0.0}; | 82 | (completions * full as u32) / weekly_goal |
83 | } else { | ||
84 | 0 | ||
85 | }; | ||
86 | let percentage = if weekly_goal > 0 { | ||
87 | (completions as f64 * 100.) / weekly_goal as f64 | ||
88 | } else { | ||
89 | 0.0 | ||
90 | }; | ||
86 | printer.with_style(future_style, |p| { | 91 | printer.with_style(future_style, |p| { |
87 | p.print((4, line_nr), &"─".repeat(full)); | 92 | p.print((4, line_nr), &"─".repeat(full)); |
88 | }); | 93 | }); |
@@ -118,7 +123,7 @@ where | |||
118 | }); | 123 | }); |
119 | } else { | 124 | } else { |
120 | printer.with_style(future_style, |p| { | 125 | printer.with_style(future_style, |p| { |
121 | p.print(coords, &format!("{:^3}", CONFIGURATION.future_chr)); | 126 | p.print(coords, &format!("{:^3}", CONFIGURATION.look.future_chr)); |
122 | }); | 127 | }); |
123 | } | 128 | } |
124 | i += 1; | 129 | i += 1; |
@@ -141,7 +146,7 @@ where | |||
141 | } | 146 | } |
142 | 147 | ||
143 | fn on_event(&mut self, e: Event) -> EventResult { | 148 | fn on_event(&mut self, e: Event) -> EventResult { |
144 | let now = Local::now().naive_utc().date(); | 149 | let now = Local::now().naive_local().date(); |
145 | if self.is_auto() { | 150 | if self.is_auto() { |
146 | return EventResult::Ignored; | 151 | return EventResult::Ignored; |
147 | } | 152 | } |