aboutsummaryrefslogtreecommitdiff
path: root/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/app')
-rw-r--r--src/app/impl_self.rs8
-rw-r--r--src/app/impl_view.rs19
2 files changed, 6 insertions, 21 deletions
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs
index 8a84cb2..1dfe268 100644
--- a/src/app/impl_self.rs
+++ b/src/app/impl_self.rs
@@ -54,6 +54,10 @@ impl App {
54 } 54 }
55 } 55 }
56 56
57 pub fn list_habits(&self) -> Vec<String> {
58 self.habits.iter().map(|x| x.name()).collect::<Vec<_>>()
59 }
60
57 pub fn delete_by_name(&mut self, name: &str) { 61 pub fn delete_by_name(&mut self, name: &str) {
58 let old_len = self.habits.len(); 62 let old_len = self.habits.len();
59 self.habits.retain(|h| h.name() != name); 63 self.habits.retain(|h| h.name() != name);
@@ -141,7 +145,7 @@ impl App {
141 let completed = total - remaining; 145 let completed = total - remaining;
142 146
143 let timestamp = if self.view_month_offset == 0 { 147 let timestamp = if self.view_month_offset == 0 {
144 format!("{}", Local::now().date().format("%d/%b/%y"),) 148 format!("{}", Local::now().naive_local().date().format("%d/%b/%y"),)
145 } else { 149 } else {
146 let months = self.view_month_offset; 150 let months = self.view_month_offset;
147 format!("{}", format!("{} months ago", months),) 151 format!("{}", format!("{} months ago", months),)
@@ -270,7 +274,7 @@ impl App {
270 self.message.set_message("help <command>|commands|keys") 274 self.message.set_message("help <command>|commands|keys")
271 } 275 }
272 } 276 }
273 Command::Quit => self.save_state(), 277 Command::Quit | Command::Write => self.save_state(),
274 Command::MonthNext => self.sift_forward(), 278 Command::MonthNext => self.sift_forward(),
275 Command::MonthPrev => self.sift_backward(), 279 Command::MonthPrev => self.sift_backward(),
276 Command::Blank => {} 280 Command::Blank => {}
diff --git a/src/app/impl_view.rs b/src/app/impl_view.rs
index 892b00c..0dfd20b 100644
--- a/src/app/impl_view.rs
+++ b/src/app/impl_view.rs
@@ -102,25 +102,6 @@ impl View for App {
102 self.set_focus(Absolute::Down); 102 self.set_focus(Absolute::Down);
103 return EventResult::Consumed(None); 103 return EventResult::Consumed(None);
104 } 104 }
105 Event::Char('d') => {
106 if self.habits.is_empty() {
107 return EventResult::Consumed(None);
108 }
109 self.habits.remove(self.focus);
110 self.focus = self.focus.checked_sub(1).unwrap_or(0);
111 return EventResult::Consumed(None);
112 }
113 Event::Char('w') => {
114 // helper bind to test write to file
115 let j = serde_json::to_string_pretty(&self.habits).unwrap();
116 let mut file = File::create("foo.txt").unwrap();
117 file.write_all(j.as_bytes()).unwrap();
118 return EventResult::Consumed(None);
119 }
120 Event::Char('q') => {
121 self.save_state();
122 return EventResult::with_cb(|s| s.quit());
123 }
124 Event::Char('v') => { 105 Event::Char('v') => {
125 if self.habits.is_empty() { 106 if self.habits.is_empty() {
126 return EventResult::Consumed(None); 107 return EventResult::Consumed(None);