From d51b80c27041513df86116c1c5036b9052d65f2f Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 4 Jul 2020 20:27:09 +0530 Subject: add quit command --- src/app.rs | 13 ++++++++----- src/command.rs | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/app.rs b/src/app.rs index 7495dd8..44de5bb 100644 --- a/src/app.rs +++ b/src/app.rs @@ -192,6 +192,12 @@ impl App { } Command::MonthNext => self.sift_forward(), Command::MonthPrev => self.sift_backward(), + + // we can get away with calling an event here, + // saves us some writing + Command::Quit => { + self.on_event(Event::Char('q')); + } _ => { eprintln!("UNKNOWN COMMAND!"); } @@ -284,7 +290,7 @@ impl View for App { return EventResult::Consumed(None); } Event::Char('q') => { - // self.save_state(); + self.save_state(); return EventResult::with_cb(|s| s.quit()); } @@ -304,10 +310,7 @@ impl View for App { * s down to the focused Habit We sift back to today * before performing any action, "refocusing" the cursor * */ - _ => { - self.set_view_month_offset(0); - self.habits[self.focus].on_event(e) - } + _ => self.habits[self.focus].on_event(e), } } } diff --git a/src/command.rs b/src/command.rs index f94eab8..d25608f 100644 --- a/src/command.rs +++ b/src/command.rs @@ -21,6 +21,7 @@ pub enum Command { MonthPrev, MonthNext, Delete(String), + Quit, Blank, } @@ -53,6 +54,7 @@ impl Command { } "mprev" | "month-prev" => return Command::MonthPrev, "mnext" | "month-next" => return Command::MonthNext, + "q" | "quit" => return Command::Quit, _ => return Command::Blank, } } -- cgit v1.2.3