diff options
Diffstat (limited to 'src/views.rs')
-rw-r--r-- | src/views.rs | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/views.rs b/src/views.rs index efd1391..a0beb2c 100644 --- a/src/views.rs +++ b/src/views.rs | |||
@@ -5,9 +5,10 @@ use cursive::view::View; | |||
5 | use cursive::{Printer, Vec2}; | 5 | use cursive::{Printer, Vec2}; |
6 | 6 | ||
7 | use chrono::prelude::*; | 7 | use chrono::prelude::*; |
8 | use chrono::{Duration, Local, NaiveDate}; | 8 | use chrono::{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::theme::cursor_gen; | ||
11 | use crate::utils::VIEW_WIDTH; | 12 | use crate::utils::VIEW_WIDTH; |
12 | 13 | ||
13 | use crate::CONFIGURATION; | 14 | use crate::CONFIGURATION; |
@@ -27,13 +28,15 @@ where | |||
27 | T::HabitType: std::fmt::Display, | 28 | T::HabitType: std::fmt::Display, |
28 | { | 29 | { |
29 | fn draw(&self, printer: &Printer) { | 30 | fn draw(&self, printer: &Printer) { |
30 | let now = if self.view_month_offset() == 0 { | 31 | // let now = if self.view_month_offset() == 0 { |
31 | Local::today() | 32 | // Local::today() |
32 | } else { | 33 | // } else { |
33 | Local::today() | 34 | // Local::today() |
34 | .checked_sub_signed(Duration::weeks(4 * self.view_month_offset() as i64)) | 35 | // .checked_sub_signed(Duration::weeks(4 * self.view_month_offset() as i64)) |
35 | .unwrap() | 36 | // .unwrap() |
36 | }; | 37 | // }; |
38 | let now = self.cursor().0; | ||
39 | let is_today = now == Local::now().naive_local().date(); | ||
37 | let year = now.year(); | 40 | let year = now.year(); |
38 | let month = now.month(); | 41 | let month = now.month(); |
39 | 42 | ||
@@ -43,8 +46,7 @@ where | |||
43 | 46 | ||
44 | let strikethrough = Style::from(Effect::Strikethrough); | 47 | let strikethrough = Style::from(Effect::Strikethrough); |
45 | 48 | ||
46 | let goal_status = | 49 | let goal_status = is_today && self.reached_goal(Local::now().naive_local().date()); |
47 | self.view_month_offset() == 0 && self.reached_goal(Local::now().naive_local().date()); | ||
48 | 50 | ||
49 | printer.with_style( | 51 | printer.with_style( |
50 | Style::merge(&[ | 52 | Style::merge(&[ |
@@ -110,11 +112,12 @@ where | |||
110 | let draw_day = |printer: &Printer| { | 112 | let draw_day = |printer: &Printer| { |
111 | let mut i = 0; | 113 | let mut i = 0; |
112 | while let Some(d) = NaiveDate::from_ymd_opt(year, month, i + 1) { | 114 | while let Some(d) = NaiveDate::from_ymd_opt(year, month, i + 1) { |
113 | let day_style; | 115 | let mut day_style = todo_style; |
114 | if self.reached_goal(d) { | 116 | if self.reached_goal(d) { |
115 | day_style = goal_reached_style; | 117 | day_style = goal_reached_style; |
116 | } else { | 118 | } |
117 | day_style = todo_style; | 119 | if d == now && printer.focused { |
120 | day_style = day_style.combine(cursor_gen(day_style)); | ||
118 | } | 121 | } |
119 | let coords: Vec2 = ((i % 7) * 3, i / 7 + 2).into(); | 122 | let coords: Vec2 = ((i % 7) * 3, i / 7 + 2).into(); |
120 | if let Some(c) = self.get_by_date(d) { | 123 | if let Some(c) = self.get_by_date(d) { |
@@ -146,7 +149,7 @@ where | |||
146 | } | 149 | } |
147 | 150 | ||
148 | fn on_event(&mut self, e: Event) -> EventResult { | 151 | fn on_event(&mut self, e: Event) -> EventResult { |
149 | let now = Local::now().naive_local().date(); | 152 | let now = self.cursor().0; |
150 | if self.is_auto() { | 153 | if self.is_auto() { |
151 | return EventResult::Ignored; | 154 | return EventResult::Ignored; |
152 | } | 155 | } |