From 516116fbe429043303a354f4a71eba4badbd34fc Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 19 Jul 2020 11:57:32 +0530 Subject: stop habits from consuming global events --- src/app/impl_self.rs | 25 +++++++++++-------------- src/views.rs | 11 +++++++++-- 2 files changed, 20 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index f4c16f3..2b115a0 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -211,6 +211,15 @@ impl App { } pub fn parse_command(&mut self, result: Result) { + let mut _track = |name: &str, event: TrackEvent| { + let target_habit = self + .habits + .iter_mut() + .find(|x| x.name() == name && x.is_auto()); + if let Some(h) = target_habit { + h.modify(Local::now().naive_utc().date(), event); + } + }; match result { Ok(c) => match c { Command::Add(name, goal, auto) => { @@ -226,22 +235,10 @@ impl App { self.focus = 0; } Command::TrackUp(name) => { - let target_habit = self - .habits - .iter_mut() - .find(|x| x.name() == name && x.is_auto()); - if let Some(h) = target_habit { - h.modify(Local::now().naive_utc().date(), TrackEvent::Increment); - } + _track(&name, TrackEvent::Increment); } Command::TrackDown(name) => { - let target_habit = self - .habits - .iter_mut() - .find(|x| x.name() == name && x.is_auto()); - if let Some(h) = target_habit { - h.modify(Local::now().naive_utc().date(), TrackEvent::Decrement); - } + _track(&name, TrackEvent::Decrement); } Command::Quit => self.save_state(), Command::MonthNext => self.sift_forward(), diff --git a/src/views.rs b/src/views.rs index f06978c..e11b844 100644 --- a/src/views.rs +++ b/src/views.rs @@ -59,7 +59,14 @@ where }, ]), |p| { - p.print((0, 0), &format!(" {} ", self.name())); + p.print( + (0, 0), + &format!( + " {:.width$} ", + self.name(), + width = CONFIGURATION.view_width - 6 + ), + ); }, ); @@ -136,7 +143,7 @@ where fn on_event(&mut self, e: Event) -> EventResult { let now = Local::now().naive_utc().date(); if self.is_auto() { - return EventResult::Consumed(None); + return EventResult::Ignored; } match e { Event::Key(Key::Enter) | Event::Char('n') => { -- cgit v1.2.3