aboutsummaryrefslogtreecommitdiff
path: root/src/app/impl_self.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/impl_self.rs')
-rw-r--r--src/app/impl_self.rs41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs
index abf5209..fec7219 100644
--- a/src/app/impl_self.rs
+++ b/src/app/impl_self.rs
@@ -6,7 +6,7 @@ use std::path::PathBuf;
6use std::sync::mpsc::channel; 6use std::sync::mpsc::channel;
7use std::time::Duration; 7use std::time::Duration;
8 8
9use chrono::Local; 9use chrono::{Local, NaiveDate};
10use cursive::direction::Absolute; 10use cursive::direction::Absolute;
11use cursive::Vec2; 11use cursive::Vec2;
12use notify::{watcher, RecursiveMode, Watcher}; 12use notify::{watcher, RecursiveMode, Watcher};
@@ -54,42 +54,42 @@ impl App {
54 if self.habits.is_empty() { 54 if self.habits.is_empty() {
55 return ViewMode::Day; 55 return ViewMode::Day;
56 } 56 }
57 return self.habits[self.focus].view_mode(); 57 return self.habits[self.focus].inner_data_ref().view_mode();
58 } 58 }
59 59
60 pub fn set_mode(&mut self, mode: ViewMode) { 60 pub fn set_mode(&mut self, mode: ViewMode) {
61 if !self.habits.is_empty() { 61 if !self.habits.is_empty() {
62 self.habits[self.focus].set_view_mode(mode); 62 self.habits[self.focus]
63 .inner_data_mut_ref()
64 .set_view_mode(mode);
63 } 65 }
64 } 66 }
65 67
66 pub fn set_view_month_offset(&mut self, offset: u32) { 68 pub fn sift_backward(&mut self) {
67 self.view_month_offset = offset; 69 self.cursor.month_backward();
68 for v in self.habits.iter_mut() { 70 for v in self.habits.iter_mut() {
69 v.set_view_month_offset(offset); 71 v.inner_data_mut_ref().cursor.month_backward();
70 } 72 }
71 } 73 }
72 74
73 pub fn sift_backward(&mut self) { 75 pub fn sift_forward(&mut self) {
74 self.view_month_offset += 1; 76 self.cursor.month_forward();
75 for v in self.habits.iter_mut() { 77 for v in self.habits.iter_mut() {
76 v.set_view_month_offset(self.view_month_offset); 78 v.inner_data_mut_ref().cursor.month_forward();
77 } 79 }
78 } 80 }
79 81
80 pub fn sift_forward(&mut self) { 82 pub fn reset_cursor(&mut self) {
81 if self.view_month_offset > 0 { 83 self.cursor.reset();
82 self.view_month_offset -= 1; 84 for v in self.habits.iter_mut() {
83 for v in self.habits.iter_mut() { 85 v.inner_data_mut_ref().cursor.reset();
84 v.set_view_month_offset(self.view_month_offset);
85 }
86 } 86 }
87 } 87 }
88 88
89 pub fn move_cursor(&mut self, d: Absolute) { 89 pub fn move_cursor(&mut self, d: Absolute) {
90 self.cursor.do_move(d); 90 self.cursor.small_seek(d);
91 for v in self.habits.iter_mut() { 91 for v in self.habits.iter_mut() {
92 v.move_cursor(d); 92 v.inner_data_mut_ref().move_cursor(d);
93 } 93 }
94 } 94 }
95 95
@@ -133,11 +133,12 @@ impl App {
133 let total = self.habits.iter().map(|h| h.goal()).sum::<u32>(); 133 let total = self.habits.iter().map(|h| h.goal()).sum::<u32>();
134 let completed = total - remaining; 134 let completed = total - remaining;
135 135
136 let timestamp = if self.view_month_offset == 0 { 136 let timestamp = if self.cursor.0 == today {
137 format!("{}", Local::now().naive_local().date().format("%d/%b/%y"),) 137 format!("{}", Local::now().naive_local().date().format("%d/%b/%y"),)
138 } else { 138 } else {
139 let months = self.view_month_offset; 139 let since = NaiveDate::signed_duration_since(today, self.cursor.0).num_days();
140 format!("{}", format!("{} month(s) ago", months),) 140 let plural = if since == 1 { "" } else { "s" };
141 format!("{} ({} day{} ago)", self.cursor.0, since, plural)
141 }; 142 };
142 143
143 StatusLine { 144 StatusLine {