aboutsummaryrefslogtreecommitdiff
path: root/src/views.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/views.rs')
-rw-r--r--src/views.rs46
1 files changed, 28 insertions, 18 deletions
diff --git a/src/views.rs b/src/views.rs
index efd1391..b90ce2b 100644
--- a/src/views.rs
+++ b/src/views.rs
@@ -1,13 +1,14 @@
1use cursive::direction::Direction; 1use cursive::direction::Direction;
2use cursive::event::{Event, EventResult, Key}; 2use cursive::event::{Event, EventResult, Key};
3use cursive::theme::{Effect, Style}; 3use cursive::theme::{ColorStyle, Effect, Style};
4use cursive::view::View; 4use 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_bg;
11use crate::utils::VIEW_WIDTH; 12use crate::utils::VIEW_WIDTH;
12 13
13use crate::CONFIGURATION; 14use crate::CONFIGURATION;
@@ -27,24 +28,24 @@ 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.inner_data_ref().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
40 let goal_reached_style = Style::from(CONFIGURATION.reached_color()); 43 let goal_reached_style = Style::from(CONFIGURATION.reached_color());
41 let todo_style = Style::from(CONFIGURATION.todo_color());
42 let future_style = Style::from(CONFIGURATION.inactive_color()); 44 let future_style = Style::from(CONFIGURATION.inactive_color());
43 45
44 let strikethrough = Style::from(Effect::Strikethrough); 46 let strikethrough = Style::from(Effect::Strikethrough);
45 47
46 let goal_status = 48 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 49
49 printer.with_style( 50 printer.with_style(
50 Style::merge(&[ 51 Style::merge(&[
@@ -110,11 +111,20 @@ where
110 let draw_day = |printer: &Printer| { 111 let draw_day = |printer: &Printer| {
111 let mut i = 0; 112 let mut i = 0;
112 while let Some(d) = NaiveDate::from_ymd_opt(year, month, i + 1) { 113 while let Some(d) = NaiveDate::from_ymd_opt(year, month, i + 1) {
113 let day_style; 114 let mut day_style = Style::none();
115 let mut fs = future_style;
116 let grs = ColorStyle::front(CONFIGURATION.reached_color());
117 let ts = ColorStyle::front(CONFIGURATION.todo_color());
118 let cs = ColorStyle::back(cursor_bg());
119
114 if self.reached_goal(d) { 120 if self.reached_goal(d) {
115 day_style = goal_reached_style; 121 day_style = day_style.combine(Style::from(grs));
116 } else { 122 } else {
117 day_style = todo_style; 123 day_style = day_style.combine(Style::from(ts));
124 }
125 if d == now && printer.focused {
126 day_style = day_style.combine(cs);
127 fs = fs.combine(cs);
118 } 128 }
119 let coords: Vec2 = ((i % 7) * 3, i / 7 + 2).into(); 129 let coords: Vec2 = ((i % 7) * 3, i / 7 + 2).into();
120 if let Some(c) = self.get_by_date(d) { 130 if let Some(c) = self.get_by_date(d) {
@@ -122,7 +132,7 @@ where
122 p.print(coords, &format!("{:^3}", c)); 132 p.print(coords, &format!("{:^3}", c));
123 }); 133 });
124 } else { 134 } else {
125 printer.with_style(future_style, |p| { 135 printer.with_style(fs, |p| {
126 p.print(coords, &format!("{:^3}", CONFIGURATION.look.future_chr)); 136 p.print(coords, &format!("{:^3}", CONFIGURATION.look.future_chr));
127 }); 137 });
128 } 138 }
@@ -130,7 +140,7 @@ where
130 } 140 }
131 }; 141 };
132 142
133 match self.view_mode() { 143 match self.inner_data_ref().view_mode() {
134 ViewMode::Day => draw_day(printer), 144 ViewMode::Day => draw_day(printer),
135 ViewMode::Week => draw_week(printer), 145 ViewMode::Week => draw_week(printer),
136 _ => draw_day(printer), 146 _ => draw_day(printer),
@@ -146,7 +156,7 @@ where
146 } 156 }
147 157
148 fn on_event(&mut self, e: Event) -> EventResult { 158 fn on_event(&mut self, e: Event) -> EventResult {
149 let now = Local::now().naive_local().date(); 159 let now = self.inner_data_mut_ref().cursor().0;
150 if self.is_auto() { 160 if self.is_auto() {
151 return EventResult::Ignored; 161 return EventResult::Ignored;
152 } 162 }