From 5dd90a7808c2a1ed8f7ba901765d2e42858b2192 Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 20 Jul 2020 11:38:20 +0530 Subject: switch to crossterm backend --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index d96119e..fb16aaa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use crate::command::{open_command_window, Command}; use crate::utils::{load_configuration_file, AppConfig}; use clap::{App as ClapApp, Arg}; -use cursive::termion; +use cursive::crossterm; use cursive::views::{LinearLayout, NamedView}; use lazy_static::lazy_static; @@ -50,7 +50,7 @@ fn main() { ), } } else { - let mut s = termion().unwrap(); + let mut s = crossterm().unwrap(); let app = App::load_state(); let layout = NamedView::new( "Frame", -- 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 ++++++++++++++++++++- src/main.rs | 14 ++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'src') 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) { diff --git a/src/main.rs b/src/main.rs index d96119e..050a296 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,6 +33,14 @@ fn main() { .value_name("CMD") .help("run a dijo command"), ) + .arg( + Arg::with_name("list") + .short("l") + .long("list") + .takes_value(false) + .help("list dijo habits") + .conflicts_with("command"), + ) .get_matches(); if let Some(c) = matches.value_of("command") { let command = Command::from_string(c); @@ -49,6 +57,12 @@ fn main() { "Commands other than `track-up` and `track-down` are currently not supported!" ), } + } else if matches.is_present("list") { + let app = App::load_state(); + let _habit_names = app.list_habit(); + for h in _habit_names { + println!("{}", h); + } } else { let mut s = termion().unwrap(); let app = App::load_state(); -- 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') 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') 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 +++++++------------------ src/main.rs | 4 +--- 2 files changed, 8 insertions(+), 21 deletions(-) (limited to 'src') 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))); diff --git a/src/main.rs b/src/main.rs index 050a296..5523073 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,9 +58,7 @@ fn main() { ), } } else if matches.is_present("list") { - let app = App::load_state(); - let _habit_names = app.list_habit(); - for h in _habit_names { + for h in App::load_state().list_habits() { println!("{}", h); } } else { -- cgit v1.2.3 From 7322949561fdbdc36a811b1368222fb5a2bf050a Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 20 Jul 2020 11:38:20 +0530 Subject: switch to crossterm backend --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 5523073..3e35ebc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use crate::command::{open_command_window, Command}; use crate::utils::{load_configuration_file, AppConfig}; use clap::{App as ClapApp, Arg}; -use cursive::termion; +use cursive::crossterm; use cursive::views::{LinearLayout, NamedView}; use lazy_static::lazy_static; @@ -62,7 +62,7 @@ fn main() { println!("{}", h); } } else { - let mut s = termion().unwrap(); + let mut s = crossterm().unwrap(); let app = App::load_state(); let layout = NamedView::new( "Frame", -- cgit v1.2.3 From 2f47f50b0382491099391185c6a2702b1370b206 Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 23 Jul 2020 22:39:28 +0530 Subject: remove dependency on rustc v1.45, bump to v0.2.1 --- src/command.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/command.rs b/src/command.rs index 38d48e9..0372065 100644 --- a/src/command.rs +++ b/src/command.rs @@ -61,8 +61,7 @@ pub fn open_command_window(s: &mut Cursive) { let completion = get_habit_completion(word, &habit_list); eprintln!("{:?} | {:?}", completion, contents); if let Some(c) = completion { - let cb = - view.set_content(format!("{}", contents) + c.strip_prefix(word).unwrap()); + let cb = view.set_content(format!("{}", contents) + &c[word.len()..]); return Some(EventResult::Consumed(Some(cb))); }; return None; -- cgit v1.2.3 From d7c303dda4750a432478c94b3ed41bca1352d839 Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 23 Jul 2020 23:06:22 +0530 Subject: enable feature based compilation to support windows --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index dec3156..609738e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ use crate::utils::{load_configuration_file, AppConfig}; use clap::{App as ClapApp, Arg}; -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "linux", target_os = "macos"))] use cursive::termion; #[cfg(target_os = "windows")] @@ -71,7 +71,7 @@ fn main() { #[cfg(target_os = "windows")] let mut s = crossterm().unwrap(); - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "linux", target_os = "macos"))] let mut s = termion().unwrap(); let app = App::load_state(); -- cgit v1.2.3