diff options
author | Akshay <[email protected]> | 2021-02-06 13:30:40 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2021-02-21 05:13:14 +0000 |
commit | 53f7a679a0cf7a510de13d67cf370988f71c0d08 (patch) | |
tree | b43b30df476d76d0a18feb7c6e7e00fd3ac4dae4 /src/app/impl_self.rs | |
parent | 9cdef4e296c77fb94d99553de05ba1aaa6c81ed8 (diff) |
deprecate view_month_offset in favor of cursor
Diffstat (limited to 'src/app/impl_self.rs')
-rw-r--r-- | src/app/impl_self.rs | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index abf5209..d5f93ff 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs | |||
@@ -6,7 +6,7 @@ use std::path::PathBuf; | |||
6 | use std::sync::mpsc::channel; | 6 | use std::sync::mpsc::channel; |
7 | use std::time::Duration; | 7 | use std::time::Duration; |
8 | 8 | ||
9 | use chrono::Local; | 9 | use chrono::{Local, NaiveDate}; |
10 | use cursive::direction::Absolute; | 10 | use cursive::direction::Absolute; |
11 | use cursive::Vec2; | 11 | use cursive::Vec2; |
12 | use notify::{watcher, RecursiveMode, Watcher}; | 12 | use notify::{watcher, RecursiveMode, Watcher}; |
@@ -27,7 +27,6 @@ impl App { | |||
27 | focus: 0, | 27 | focus: 0, |
28 | _file_watcher: watcher, | 28 | _file_watcher: watcher, |
29 | file_event_recv: rx, | 29 | file_event_recv: rx, |
30 | view_month_offset: 0, | ||
31 | cursor: Cursor::new(), | 30 | cursor: Cursor::new(), |
32 | message: Message::startup(), | 31 | message: Message::startup(), |
33 | }; | 32 | }; |
@@ -54,42 +53,42 @@ impl App { | |||
54 | if self.habits.is_empty() { | 53 | if self.habits.is_empty() { |
55 | return ViewMode::Day; | 54 | return ViewMode::Day; |
56 | } | 55 | } |
57 | return self.habits[self.focus].view_mode(); | 56 | return self.habits[self.focus].inner_data_ref().view_mode(); |
58 | } | 57 | } |
59 | 58 | ||
60 | pub fn set_mode(&mut self, mode: ViewMode) { | 59 | pub fn set_mode(&mut self, mode: ViewMode) { |
61 | if !self.habits.is_empty() { | 60 | if !self.habits.is_empty() { |
62 | self.habits[self.focus].set_view_mode(mode); | 61 | self.habits[self.focus] |
62 | .inner_data_mut_ref() | ||
63 | .set_view_mode(mode); | ||
63 | } | 64 | } |
64 | } | 65 | } |
65 | 66 | ||
66 | pub fn set_view_month_offset(&mut self, offset: u32) { | 67 | pub fn sift_backward(&mut self) { |
67 | self.view_month_offset = offset; | 68 | self.cursor.month_backward(); |
68 | for v in self.habits.iter_mut() { | 69 | for v in self.habits.iter_mut() { |
69 | v.set_view_month_offset(offset); | 70 | v.inner_data_mut_ref().cursor.month_backward(); |
70 | } | 71 | } |
71 | } | 72 | } |
72 | 73 | ||
73 | pub fn sift_backward(&mut self) { | 74 | pub fn sift_forward(&mut self) { |
74 | self.view_month_offset += 1; | 75 | self.cursor.month_forward(); |
75 | for v in self.habits.iter_mut() { | 76 | for v in self.habits.iter_mut() { |
76 | v.set_view_month_offset(self.view_month_offset); | 77 | v.inner_data_mut_ref().cursor.month_forward(); |
77 | } | 78 | } |
78 | } | 79 | } |
79 | 80 | ||
80 | pub fn sift_forward(&mut self) { | 81 | pub fn reset_cursor(&mut self) { |
81 | if self.view_month_offset > 0 { | 82 | self.cursor.reset(); |
82 | self.view_month_offset -= 1; | 83 | for v in self.habits.iter_mut() { |
83 | for v in self.habits.iter_mut() { | 84 | v.inner_data_mut_ref().cursor.reset(); |
84 | v.set_view_month_offset(self.view_month_offset); | ||
85 | } | ||
86 | } | 85 | } |
87 | } | 86 | } |
88 | 87 | ||
89 | pub fn move_cursor(&mut self, d: Absolute) { | 88 | pub fn move_cursor(&mut self, d: Absolute) { |
90 | self.cursor.do_move(d); | 89 | self.cursor.small_seek(d); |
91 | for v in self.habits.iter_mut() { | 90 | for v in self.habits.iter_mut() { |
92 | v.move_cursor(d); | 91 | v.inner_data_mut_ref().move_cursor(d); |
93 | } | 92 | } |
94 | } | 93 | } |
95 | 94 | ||
@@ -133,11 +132,12 @@ impl App { | |||
133 | let total = self.habits.iter().map(|h| h.goal()).sum::<u32>(); | 132 | let total = self.habits.iter().map(|h| h.goal()).sum::<u32>(); |
134 | let completed = total - remaining; | 133 | let completed = total - remaining; |
135 | 134 | ||
136 | let timestamp = if self.view_month_offset == 0 { | 135 | let timestamp = if self.cursor.0 == today { |
137 | format!("{}", Local::now().naive_local().date().format("%d/%b/%y"),) | 136 | format!("{}", Local::now().naive_local().date().format("%d/%b/%y"),) |
138 | } else { | 137 | } else { |
139 | let months = self.view_month_offset; | 138 | let since = NaiveDate::signed_duration_since(today, self.cursor.0).num_days(); |
140 | format!("{}", format!("{} month(s) ago", months),) | 139 | let plural = if since == 1 { "" } else { "s" }; |
140 | format!("{} ({} day{} ago)", self.cursor.0, since, plural) | ||
141 | }; | 141 | }; |
142 | 142 | ||
143 | StatusLine { | 143 | StatusLine { |