diff options
-rw-r--r-- | src/app/impl_self.rs | 25 | ||||
-rw-r--r-- | src/views.rs | 11 |
2 files changed, 20 insertions, 16 deletions
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 { | |||
211 | } | 211 | } |
212 | 212 | ||
213 | pub fn parse_command(&mut self, result: Result<Command, CommandLineError>) { | 213 | pub fn parse_command(&mut self, result: Result<Command, CommandLineError>) { |
214 | let mut _track = |name: &str, event: TrackEvent| { | ||
215 | let target_habit = self | ||
216 | .habits | ||
217 | .iter_mut() | ||
218 | .find(|x| x.name() == name && x.is_auto()); | ||
219 | if let Some(h) = target_habit { | ||
220 | h.modify(Local::now().naive_utc().date(), event); | ||
221 | } | ||
222 | }; | ||
214 | match result { | 223 | match result { |
215 | Ok(c) => match c { | 224 | Ok(c) => match c { |
216 | Command::Add(name, goal, auto) => { | 225 | Command::Add(name, goal, auto) => { |
@@ -226,22 +235,10 @@ impl App { | |||
226 | self.focus = 0; | 235 | self.focus = 0; |
227 | } | 236 | } |
228 | Command::TrackUp(name) => { | 237 | Command::TrackUp(name) => { |
229 | let target_habit = self | 238 | _track(&name, TrackEvent::Increment); |
230 | .habits | ||
231 | .iter_mut() | ||
232 | .find(|x| x.name() == name && x.is_auto()); | ||
233 | if let Some(h) = target_habit { | ||
234 | h.modify(Local::now().naive_utc().date(), TrackEvent::Increment); | ||
235 | } | ||
236 | } | 239 | } |
237 | Command::TrackDown(name) => { | 240 | Command::TrackDown(name) => { |
238 | let target_habit = self | 241 | _track(&name, TrackEvent::Decrement); |
239 | .habits | ||
240 | .iter_mut() | ||
241 | .find(|x| x.name() == name && x.is_auto()); | ||
242 | if let Some(h) = target_habit { | ||
243 | h.modify(Local::now().naive_utc().date(), TrackEvent::Decrement); | ||
244 | } | ||
245 | } | 242 | } |
246 | Command::Quit => self.save_state(), | 243 | Command::Quit => self.save_state(), |
247 | Command::MonthNext => self.sift_forward(), | 244 | 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 | |||
59 | }, | 59 | }, |
60 | ]), | 60 | ]), |
61 | |p| { | 61 | |p| { |
62 | p.print((0, 0), &format!(" {} ", self.name())); | 62 | p.print( |
63 | (0, 0), | ||
64 | &format!( | ||
65 | " {:.width$} ", | ||
66 | self.name(), | ||
67 | width = CONFIGURATION.view_width - 6 | ||
68 | ), | ||
69 | ); | ||
63 | }, | 70 | }, |
64 | ); | 71 | ); |
65 | 72 | ||
@@ -136,7 +143,7 @@ where | |||
136 | fn on_event(&mut self, e: Event) -> EventResult { | 143 | fn on_event(&mut self, e: Event) -> EventResult { |
137 | let now = Local::now().naive_utc().date(); | 144 | let now = Local::now().naive_utc().date(); |
138 | if self.is_auto() { | 145 | if self.is_auto() { |
139 | return EventResult::Consumed(None); | 146 | return EventResult::Ignored; |
140 | } | 147 | } |
141 | match e { | 148 | match e { |
142 | Event::Key(Key::Enter) | Event::Char('n') => { | 149 | Event::Key(Key::Enter) | Event::Char('n') => { |