aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/views.rs31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/views.rs b/src/views.rs
index 5b9ec20..4f1594a 100644
--- a/src/views.rs
+++ b/src/views.rs
@@ -1,5 +1,7 @@
1use cursive::direction::Direction; 1use cursive::direction::Direction;
2use cursive::event::{Event, EventResult, Key}; 2use cursive::event::{Event, EventResult, Key};
3use cursive::theme::{BaseColor, Color, Effect, Style};
4use cursive::utils::markup::StyledString;
3use cursive::view::View; 5use cursive::view::View;
4use cursive::{Printer, Vec2}; 6use cursive::{Printer, Vec2};
5 7
@@ -23,9 +25,9 @@ impl BitView {
23 pub fn new(habit: Habit<bool>) -> Self { 25 pub fn new(habit: Habit<bool>) -> Self {
24 return BitView { 26 return BitView {
25 habit, 27 habit,
26 true_chr: 'x', 28 true_chr: '·',
27 false_chr: 'o', 29 false_chr: '·',
28 future_chr: '.', 30 future_chr: '·',
29 view_width: 21, 31 view_width: 21,
30 view_height: 9, 32 view_height: 9,
31 }; 33 };
@@ -41,27 +43,40 @@ impl View for BitView {
41 let year = now.year(); 43 let year = now.year();
42 let month = now.month(); 44 let month = now.month();
43 45
46 let true_style = Style::from(Color::Dark(BaseColor::Cyan));
47 let false_style = Style::from(Color::Dark(BaseColor::Magenta));
48 let future_style = Style::from(Color::Light(BaseColor::Black));
49
44 for i in 1..=31 { 50 for i in 1..=31 {
45 let day = NaiveDate::from_ymd_opt(year, month, i); 51 let day = NaiveDate::from_ymd_opt(year, month, i);
52 let day_style;
53
46 if let Some(d) = day { 54 if let Some(d) = day {
47 let day_status = self.habit.get_by_date(d).unwrap_or(&false); 55 let day_status = self.habit.get_by_date(d).unwrap_or(&false);
48 let coords = ((i % 7) * 3, i / 7 + 2); 56 let coords = ((i % 7) * 3, i / 7 + 2);
49 57 let day_chr;
50 if d <= now.naive_utc().date() { 58 if d <= now.naive_utc().date() {
51 if *day_status { 59 if *day_status {
52 printer.print(coords, &format!("{:^3}", self.true_chr)) 60 day_chr = self.true_chr;
61 day_style = true_style;
53 } else { 62 } else {
54 printer.print(coords, &format!("{:^3}", self.false_chr)) 63 day_chr = self.false_chr;
64 day_style = false_style;
55 } 65 }
56 } else { 66 } else {
57 printer.print(coords, &format!("{:^3}", self.future_chr)) 67 day_chr = self.future_chr;
68 day_style = future_style;
58 } 69 }
70
71 printer.with_style(day_style, |p| {
72 p.print(coords, &format!("{:^3}", day_chr));
73 });
59 } 74 }
60 } 75 }
61 } 76 }
62 77
63 fn required_size(&mut self, _: Vec2) -> Vec2 { 78 fn required_size(&mut self, _: Vec2) -> Vec2 {
64 (20, 9).into() 79 (self.view_width, self.view_height).into()
65 } 80 }
66 81
67 fn take_focus(&mut self, _: Direction) -> bool { 82 fn take_focus(&mut self, _: Direction) -> bool {