aboutsummaryrefslogtreecommitdiff
path: root/src/views.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/views.rs')
-rw-r--r--src/views.rs31
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;
5use cursive::{Printer, Vec2}; 5use cursive::{Printer, Vec2};
6 6
7use chrono::prelude::*; 7use chrono::prelude::*;
8use chrono::{Duration, Local, NaiveDate}; 8use chrono::{Local, NaiveDate};
9 9
10use crate::habit::{Bit, Count, Habit, TrackEvent, ViewMode}; 10use crate::habit::{Bit, Count, Habit, TrackEvent, ViewMode};
11use crate::theme::cursor_gen;
11use crate::utils::VIEW_WIDTH; 12use crate::utils::VIEW_WIDTH;
12 13
13use crate::CONFIGURATION; 14use 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 }