diff options
author | Akshay <[email protected]> | 2020-07-10 17:21:37 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2020-07-10 17:21:37 +0100 |
commit | 188827f3548ea8ca1ab84735b8fe19f99c790207 (patch) | |
tree | 70e4803b0538fda181de2de7430fb3f6c9707fb6 /src | |
parent | f156defd5b1a7e38b8f98e6df3135b288ac61722 (diff) |
redo quit command
Diffstat (limited to 'src')
-rw-r--r-- | src/app.rs | 27 | ||||
-rw-r--r-- | src/command.rs | 10 |
2 files changed, 26 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 | } |
diff --git a/src/command.rs b/src/command.rs index d25608f..afc00ba 100644 --- a/src/command.rs +++ b/src/command.rs | |||
@@ -13,9 +13,19 @@ fn call_on_app(s: &mut Cursive, input: &str) { | |||
13 | s.call_on_name("Main", |view: &mut App| { | 13 | s.call_on_name("Main", |view: &mut App| { |
14 | view.parse_command(input); | 14 | view.parse_command(input); |
15 | }); | 15 | }); |
16 | |||
17 | // special command that requires access to | ||
18 | // our main cursive object, has to be parsed again | ||
19 | // here | ||
20 | // TODO: fix this somehow | ||
21 | if Command::from_string(input) == Command::Quit { | ||
22 | s.quit(); | ||
23 | } | ||
24 | |||
16 | s.pop_layer(); | 25 | s.pop_layer(); |
17 | } | 26 | } |
18 | 27 | ||
28 | #[derive(PartialEq)] | ||
19 | pub enum Command { | 29 | pub enum Command { |
20 | Add(String, String, Option<u32>), // habit name, habit type, optional goal | 30 | Add(String, String, Option<u32>), // habit name, habit type, optional goal |
21 | MonthPrev, | 31 | MonthPrev, |