diff options
author | Akshay <[email protected]> | 2021-01-25 09:24:51 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2021-01-25 09:24:51 +0000 |
commit | cd03d732b1f0df6c020a94135db2db4b690a4937 (patch) | |
tree | 94da0cfb56711abb1d8344d1804882c93201902d /src/views.rs | |
parent | 665fd3fb61891b73175690158cde38cf7f94ebc7 (diff) |
handle cursor events and entry
Diffstat (limited to 'src/views.rs')
-rw-r--r-- | src/views.rs | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/views.rs b/src/views.rs index efd1391..4f78ca2 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 | ||
@@ -41,10 +44,10 @@ where | |||
41 | let todo_style = Style::from(CONFIGURATION.todo_color()); | 44 | let todo_style = Style::from(CONFIGURATION.todo_color()); |
42 | let future_style = Style::from(CONFIGURATION.inactive_color()); | 45 | let future_style = Style::from(CONFIGURATION.inactive_color()); |
43 | 46 | ||
47 | let cursor_style = cursor_gen(); | ||
44 | let strikethrough = Style::from(Effect::Strikethrough); | 48 | let strikethrough = Style::from(Effect::Strikethrough); |
45 | 49 | ||
46 | let goal_status = | 50 | 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 | 51 | ||
49 | printer.with_style( | 52 | printer.with_style( |
50 | Style::merge(&[ | 53 | Style::merge(&[ |
@@ -110,11 +113,9 @@ where | |||
110 | let draw_day = |printer: &Printer| { | 113 | let draw_day = |printer: &Printer| { |
111 | let mut i = 0; | 114 | let mut i = 0; |
112 | while let Some(d) = NaiveDate::from_ymd_opt(year, month, i + 1) { | 115 | while let Some(d) = NaiveDate::from_ymd_opt(year, month, i + 1) { |
113 | let day_style; | 116 | let mut day_style = cursor_style.combine(todo_style); |
114 | if self.reached_goal(d) { | 117 | if self.reached_goal(d) { |
115 | day_style = goal_reached_style; | 118 | day_style = day_style.combine(goal_reached_style); |
116 | } else { | ||
117 | day_style = todo_style; | ||
118 | } | 119 | } |
119 | let coords: Vec2 = ((i % 7) * 3, i / 7 + 2).into(); | 120 | let coords: Vec2 = ((i % 7) * 3, i / 7 + 2).into(); |
120 | if let Some(c) = self.get_by_date(d) { | 121 | if let Some(c) = self.get_by_date(d) { |
@@ -146,7 +147,7 @@ where | |||
146 | } | 147 | } |
147 | 148 | ||
148 | fn on_event(&mut self, e: Event) -> EventResult { | 149 | fn on_event(&mut self, e: Event) -> EventResult { |
149 | let now = Local::now().naive_local().date(); | 150 | let now = self.cursor().0; |
150 | if self.is_auto() { | 151 | if self.is_auto() { |
151 | return EventResult::Ignored; | 152 | return EventResult::Ignored; |
152 | } | 153 | } |