From 76a6e78ccbea125ab5b8c06ff254260759d3140c Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 21 Jul 2020 11:24:42 +0530 Subject: switch to local time over utc time --- src/app/impl_self.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/app') diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 744f906..2450bff 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -118,7 +118,7 @@ impl App { } pub fn status(&self) -> StatusLine { - let today = chrono::Local::now().naive_utc().date(); + let today = chrono::Local::now().naive_local().date(); let remaining = self.habits.iter().map(|h| h.remaining(today)).sum::(); let total = self.habits.iter().map(|h| h.goal()).sum::(); let completed = total - remaining; @@ -207,7 +207,7 @@ impl App { .iter_mut() .find(|x| x.name() == name && x.is_auto()); if let Some(h) = target_habit { - h.modify(Local::now().naive_utc().date(), event); + h.modify(Local::now().naive_local().date(), event); } }; match result { -- cgit v1.2.3 From 4f76460efa869317bd7065b4770c16d0146a92da Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 21 Jul 2020 20:33:22 +0530 Subject: add help command --- src/app/impl_self.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/app') diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 2450bff..95f1871 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -230,6 +230,29 @@ impl App { Command::TrackDown(name) => { _track(&name, TrackEvent::Decrement); } + Command::Help(input) => { + if let Some(topic) = input.as_ref().map(String::as_ref) { + self.message.set_message( + match topic { + "a" | "add" => "add [goal] (alias: a)", + "aa" | "add-auto" => "add-auto [goal] (alias: aa)", + "d" | "delete" => "delete (alias: d)", + "mprev" | "month-prev" => "month-prev (alias: mprev)", + "mnext" | "month-next" => "month-next (alias: mnext)", + "tup" | "track-up" => "track-up (alias: tup)", + "tdown" | "track-down" => "track-down (alias: tdown)", + "q" | "quit" => "quit", + "h"|"?" | "help" => "help [|commands|keys] (aliases: h, ?)", + "cmds" | "commands" => "add, add-auto, delete, month-{prev,next}, track-{up,down}, help, quit", + "keys" => "TODO", // TODO (view?) + _ => "unknown command or help topic.", + } + ) + } else { + // TODO (view?) + self.message.set_message("help |commands|keys") + } + } Command::Quit => self.save_state(), Command::MonthNext => self.sift_forward(), Command::MonthPrev => self.sift_backward(), -- cgit v1.2.3 From 9dfe454cd8bc816522446e7e3b9f45630c886112 Mon Sep 17 00:00:00 2001 From: Guillaume Hormiere Date: Wed, 22 Jul 2020 00:38:01 +0200 Subject: Add list command for shell script purpose Usage dijo -l for printing the habit names list Add check on habit add to avoid duplicate habits --- src/app/impl_self.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/app') diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 95f1871..38162ee 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -33,8 +33,27 @@ impl App { }; } + pub fn list_habit(&self) -> Vec { + let mut habits_names: Vec = vec![]; + for h in self.habits.iter() { + habits_names.push(h.name()) + } + return habits_names; + } + pub fn add_habit(&mut self, h: Box) { - self.habits.push(h); + if self + .habits + .iter() + .filter(|hab| hab.name() == h.name()) + .count() + > 0 + { + self.message + .set_message(format!("Habit `{}` allready exist", h.name())) + } else { + self.habits.push(h); + } } pub fn delete_by_name(&mut self, name: &str) { -- cgit v1.2.3 From 3f64deb152c31f2a04612d9c525537a72605d678 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 22 Jul 2020 21:00:38 +0530 Subject: remove `d` keybind, add tab completion --- src/app/impl_self.rs | 4 ++++ src/app/impl_view.rs | 8 -------- 2 files changed, 4 insertions(+), 8 deletions(-) (limited to 'src/app') diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 95f1871..7eae853 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -37,6 +37,10 @@ impl App { self.habits.push(h); } + pub fn list_habits(&self) -> Vec { + self.habits.iter().map(|x| x.name()).collect::>() + } + pub fn delete_by_name(&mut self, name: &str) { let old_len = self.habits.len(); self.habits.retain(|h| h.name() != name); diff --git a/src/app/impl_view.rs b/src/app/impl_view.rs index 892b00c..b8c4589 100644 --- a/src/app/impl_view.rs +++ b/src/app/impl_view.rs @@ -102,14 +102,6 @@ impl View for App { self.set_focus(Absolute::Down); return EventResult::Consumed(None); } - Event::Char('d') => { - if self.habits.is_empty() { - return EventResult::Consumed(None); - } - self.habits.remove(self.focus); - self.focus = self.focus.checked_sub(1).unwrap_or(0); - return EventResult::Consumed(None); - } Event::Char('w') => { // helper bind to test write to file let j = serde_json::to_string_pretty(&self.habits).unwrap(); -- cgit v1.2.3 From 5c910bc6cf193725575ef6146dcc8620e7a4a800 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 22 Jul 2020 22:08:50 +0530 Subject: remove debug key binds, add :write command --- src/app/impl_self.rs | 2 +- src/app/impl_view.rs | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) (limited to 'src/app') diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 7eae853..cf0e97f 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -257,7 +257,7 @@ impl App { self.message.set_message("help |commands|keys") } } - Command::Quit => self.save_state(), + Command::Quit | Command::Write => self.save_state(), Command::MonthNext => self.sift_forward(), Command::MonthPrev => self.sift_backward(), Command::Blank => {} diff --git a/src/app/impl_view.rs b/src/app/impl_view.rs index b8c4589..0dfd20b 100644 --- a/src/app/impl_view.rs +++ b/src/app/impl_view.rs @@ -102,17 +102,6 @@ impl View for App { self.set_focus(Absolute::Down); return EventResult::Consumed(None); } - Event::Char('w') => { - // helper bind to test write to file - let j = serde_json::to_string_pretty(&self.habits).unwrap(); - let mut file = File::create("foo.txt").unwrap(); - file.write_all(j.as_bytes()).unwrap(); - return EventResult::Consumed(None); - } - Event::Char('q') => { - self.save_state(); - return EventResult::with_cb(|s| s.quit()); - } Event::Char('v') => { if self.habits.is_empty() { return EventResult::Consumed(None); -- cgit v1.2.3 From a0c57162b2026e37220e31a39d821c2a2e31cc51 Mon Sep 17 00:00:00 2001 From: Guillaume Hormiere Date: Wed, 22 Jul 2020 22:26:19 +0200 Subject: Use immutable vector instead of mutable one and change the message kind to Error Apply code review --- src/app/impl_self.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/app') diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 38162ee..8a84cb2 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -34,10 +34,7 @@ impl App { } pub fn list_habit(&self) -> Vec { - let mut habits_names: Vec = vec![]; - for h in self.habits.iter() { - habits_names.push(h.name()) - } + let habits_names = self.habits.iter().map(|x| x.name()).collect::>(); return habits_names; } @@ -49,6 +46,7 @@ impl App { .count() > 0 { + self.message.set_kind(MessageKind::Error); self.message .set_message(format!("Habit `{}` allready exist", h.name())) } else { -- cgit v1.2.3 From f5940ea5fc507ec34d686a888a1aa1aba50be277 Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 23 Jul 2020 10:06:34 +0530 Subject: fix tiemzones in statusline --- src/app/impl_self.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/app') diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index cf0e97f..1ed19e6 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -128,7 +128,7 @@ impl App { let completed = total - remaining; let timestamp = if self.view_month_offset == 0 { - format!("{}", Local::now().date().format("%d/%b/%y"),) + format!("{}", Local::now().naive_local().date().format("%d/%b/%y"),) } else { let months = self.view_month_offset; format!("{}", format!("{} months ago", months),) -- cgit v1.2.3 From b0b6c04a052955834f0603df79db7a0a517a9b9d Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 23 Jul 2020 13:19:15 +0530 Subject: move duplicate check to command parsing block --- src/app/impl_self.rs | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'src/app') diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 1dfe268..a806dc5 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -33,25 +33,8 @@ impl App { }; } - pub fn list_habit(&self) -> Vec { - let habits_names = self.habits.iter().map(|x| x.name()).collect::>(); - return habits_names; - } - pub fn add_habit(&mut self, h: Box) { - if self - .habits - .iter() - .filter(|hab| hab.name() == h.name()) - .count() - > 0 - { - self.message.set_kind(MessageKind::Error); - self.message - .set_message(format!("Habit `{}` allready exist", h.name())) - } else { - self.habits.push(h); - } + self.habits.push(h); } pub fn list_habits(&self) -> Vec { @@ -234,6 +217,12 @@ impl App { match result { Ok(c) => match c { Command::Add(name, goal, auto) => { + if let Some(_) = self.habits.iter().find(|x| x.name() == name) { + self.message.set_kind(MessageKind::Error); + self.message + .set_message(format!("Habit `{}` already exist", &name)); + return; + } let kind = if goal == Some(1) { "bit" } else { "count" }; if kind == "count" { self.add_habit(Box::new(Count::new(name, goal.unwrap_or(0), auto))); -- cgit v1.2.3