aboutsummaryrefslogtreecommitdiff
path: root/src/app.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app.rs')
-rw-r--r--src/app.rs33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/app.rs b/src/app.rs
index dafeed5..ab0bcd3 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -11,7 +11,7 @@ use cursive::{Printer, Vec2};
11 11
12use chrono::Local; 12use chrono::Local;
13 13
14use crate::habit::{Bit, Count, HabitWrapper, ViewMode}; 14use crate::habit::{Bit, Count, HabitWrapper, TrackEvent, ViewMode};
15use crate::utils; 15use crate::utils;
16use crate::Command; 16use crate::Command;
17use crate::CONFIGURATION; 17use crate::CONFIGURATION;
@@ -46,7 +46,7 @@ impl App {
46 } 46 }
47 47
48 pub fn delete_by_name(&mut self, name: &str) { 48 pub fn delete_by_name(&mut self, name: &str) {
49 self.habits.retain(|h| h.get_name() != name); 49 self.habits.retain(|h| h.name() != name);
50 } 50 }
51 51
52 pub fn get_mode(&self) -> ViewMode { 52 pub fn get_mode(&self) -> ViewMode {
@@ -184,7 +184,7 @@ impl App {
184 184
185 // this function does IO 185 // this function does IO
186 // TODO: convert this into non-blocking async function 186 // TODO: convert this into non-blocking async function
187 fn save_state(&self) { 187 pub fn save_state(&self) {
188 let (regular, auto): (Vec<_>, Vec<_>) = self.habits.iter().partition(|&x| !x.is_auto()); 188 let (regular, auto): (Vec<_>, Vec<_>) = self.habits.iter().partition(|&x| !x.is_auto());
189 let (regular_f, auto_f) = (utils::habit_file(), utils::auto_habit_file()); 189 let (regular_f, auto_f) = (utils::habit_file(), utils::auto_habit_file());
190 190
@@ -205,8 +205,7 @@ impl App {
205 write_to_file(auto, auto_f); 205 write_to_file(auto, auto_f);
206 } 206 }
207 207
208 pub fn parse_command(&mut self, input: &str) { 208 pub fn parse_command(&mut self, c: Command) {
209 let c = Command::from_string(input);
210 match c { 209 match c {
211 Command::Add(name, goal, auto) => { 210 Command::Add(name, goal, auto) => {
212 let kind = if goal == Some(1) { "bit" } else { "count" }; 211 let kind = if goal == Some(1) { "bit" } else { "count" };
@@ -224,6 +223,24 @@ impl App {
224 self.delete_by_name(&name); 223 self.delete_by_name(&name);
225 self.focus = 0; 224 self.focus = 0;
226 } 225 }
226 Command::TrackUp(name) => {
227 let target_habit = self
228 .habits
229 .iter_mut()
230 .find(|x| x.name() == name && x.is_auto());
231 if let Some(h) = target_habit {
232 h.modify(Local::now().naive_utc().date(), TrackEvent::Increment);
233 }
234 }
235 Command::TrackDown(name) => {
236 let target_habit = self
237 .habits
238 .iter_mut()
239 .find(|x| x.name() == name && x.is_auto());
240 if let Some(h) = target_habit {
241 h.modify(Local::now().naive_utc().date(), TrackEvent::Decrement);
242 }
243 }
227 Command::Quit => self.save_state(), 244 Command::Quit => self.save_state(),
228 Command::MonthNext => self.sift_forward(), 245 Command::MonthNext => self.sift_forward(),
229 Command::MonthPrev => self.sift_backward(), 246 Command::MonthPrev => self.sift_backward(),
@@ -253,10 +270,8 @@ impl View for App {
253 let status = self.status(); 270 let status = self.status();
254 printer.print(offset, &status.0); // left status 271 printer.print(offset, &status.0); // left status
255 272
256 let full = grid_width * (view_width + 2); 273 let full = self.max_size().x;
257 offset = offset 274 offset = offset.map_x(|_| full - status.1.len());
258 .map_x(|_| full - status.1.len())
259 .map_y(|_| self.max_size().y - 2);
260 printer.print(offset, &status.1); // right status 275 printer.print(offset, &status.1); // right status
261 } 276 }
262 277