diff options
Diffstat (limited to 'src/app.rs')
-rw-r--r-- | src/app.rs | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -32,8 +32,10 @@ struct StatusLine(String, String); | |||
32 | 32 | ||
33 | #[derive(Serialize, Deserialize)] | 33 | #[derive(Serialize, Deserialize)] |
34 | pub struct App { | 34 | pub struct App { |
35 | // holds app data | ||
35 | habits: Vec<Box<dyn HabitWrapper>>, | 36 | habits: Vec<Box<dyn HabitWrapper>>, |
36 | 37 | ||
38 | // serialization of the rest can be skipped | ||
37 | #[serde(skip)] | 39 | #[serde(skip)] |
38 | focus: usize, | 40 | focus: usize, |
39 | 41 | ||
@@ -135,6 +137,7 @@ impl App { | |||
135 | width = CONFIGURATION.view_width * CONFIGURATION.grid_width | 137 | width = CONFIGURATION.view_width * CONFIGURATION.grid_width |
136 | ) | 138 | ) |
137 | } else { | 139 | } else { |
140 | let months = self.view_month_offset; | ||
138 | format!( | 141 | format!( |
139 | "{:>width$}", | 142 | "{:>width$}", |
140 | format!("{} months ago", self.view_month_offset), | 143 | format!("{} months ago", self.view_month_offset), |
@@ -190,14 +193,9 @@ impl App { | |||
190 | self.delete_by_name(&name); | 193 | self.delete_by_name(&name); |
191 | self.focus = 0; | 194 | self.focus = 0; |
192 | } | 195 | } |
196 | Command::Quit => self.save_state(), | ||
193 | Command::MonthNext => self.sift_forward(), | 197 | Command::MonthNext => self.sift_forward(), |
194 | Command::MonthPrev => self.sift_backward(), | 198 | Command::MonthPrev => self.sift_backward(), |
195 | |||
196 | // we can get away with calling an event here, | ||
197 | // saves us some writing | ||
198 | Command::Quit => { | ||
199 | self.on_event(Event::Char('q')); | ||
200 | } | ||
201 | _ => { | 199 | _ => { |
202 | eprintln!("UNKNOWN COMMAND!"); | 200 | eprintln!("UNKNOWN COMMAND!"); |
203 | } | 201 | } |
@@ -297,20 +295,27 @@ impl View for App { | |||
297 | /* We want sifting to be an app level function, | 295 | /* We want sifting to be an app level function, |
298 | * that later trickles down into each habit | 296 | * that later trickles down into each habit |
299 | * */ | 297 | * */ |
300 | Event::CtrlChar('f') => { | 298 | Event::Char(']') => { |
301 | self.sift_forward(); | 299 | self.sift_forward(); |
302 | return EventResult::Consumed(None); | 300 | return EventResult::Consumed(None); |
303 | } | 301 | } |
304 | Event::CtrlChar('b') => { | 302 | Event::Char('[') => { |
305 | self.sift_backward(); | 303 | self.sift_backward(); |
306 | return EventResult::Consumed(None); | 304 | return EventResult::Consumed(None); |
307 | } | 305 | } |
306 | Event::Char('}') => { | ||
307 | self.set_view_month_offset(0); | ||
308 | return EventResult::Consumed(None); | ||
309 | } | ||
308 | 310 | ||
309 | /* Every keybind that is not caught by App trickle | 311 | /* Every keybind that is not caught by App trickles |
310 | * s down to the focused Habit We sift back to today | 312 | * down to the focused Habit We sift back to today |
311 | * before performing any action, "refocusing" the cursor | 313 | * before performing any action, "refocusing" the cursor |
312 | * */ | 314 | * */ |
313 | _ => self.habits[self.focus].on_event(e), | 315 | _ => { |
316 | self.set_view_month_offset(0); | ||
317 | self.habits[self.focus].on_event(e) | ||
318 | } | ||
314 | } | 319 | } |
315 | } | 320 | } |
316 | } | 321 | } |