diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app/impl_self.rs | 8 | ||||
-rw-r--r-- | src/command.rs | 3 | ||||
-rw-r--r-- | src/main.rs | 23 |
3 files changed, 31 insertions, 3 deletions
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index cf0e97f..a806dc5 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs | |||
@@ -128,7 +128,7 @@ impl App { | |||
128 | let completed = total - remaining; | 128 | let completed = total - remaining; |
129 | 129 | ||
130 | let timestamp = if self.view_month_offset == 0 { | 130 | let timestamp = if self.view_month_offset == 0 { |
131 | format!("{}", Local::now().date().format("%d/%b/%y"),) | 131 | format!("{}", Local::now().naive_local().date().format("%d/%b/%y"),) |
132 | } else { | 132 | } else { |
133 | let months = self.view_month_offset; | 133 | let months = self.view_month_offset; |
134 | format!("{}", format!("{} months ago", months),) | 134 | format!("{}", format!("{} months ago", months),) |
@@ -217,6 +217,12 @@ impl App { | |||
217 | match result { | 217 | match result { |
218 | Ok(c) => match c { | 218 | Ok(c) => match c { |
219 | Command::Add(name, goal, auto) => { | 219 | Command::Add(name, goal, auto) => { |
220 | if let Some(_) = self.habits.iter().find(|x| x.name() == name) { | ||
221 | self.message.set_kind(MessageKind::Error); | ||
222 | self.message | ||
223 | .set_message(format!("Habit `{}` already exist", &name)); | ||
224 | return; | ||
225 | } | ||
220 | let kind = if goal == Some(1) { "bit" } else { "count" }; | 226 | let kind = if goal == Some(1) { "bit" } else { "count" }; |
221 | if kind == "count" { | 227 | if kind == "count" { |
222 | self.add_habit(Box::new(Count::new(name, goal.unwrap_or(0), auto))); | 228 | self.add_habit(Box::new(Count::new(name, goal.unwrap_or(0), auto))); |
diff --git a/src/command.rs b/src/command.rs index a893430..ae5be66 100644 --- a/src/command.rs +++ b/src/command.rs | |||
@@ -61,8 +61,7 @@ pub fn open_command_window(s: &mut Cursive) { | |||
61 | let completion = get_habit_completion(word, &habit_list); | 61 | let completion = get_habit_completion(word, &habit_list); |
62 | eprintln!("{:?} | {:?}", completion, contents); | 62 | eprintln!("{:?} | {:?}", completion, contents); |
63 | if let Some(c) = completion { | 63 | if let Some(c) = completion { |
64 | let cb = | 64 | let cb = view.set_content(format!("{}", contents) + &c[word.len()..]); |
65 | view.set_content(format!("{}", contents) + c.strip_prefix(word).unwrap()); | ||
66 | return Some(EventResult::Consumed(Some(cb))); | 65 | return Some(EventResult::Consumed(Some(cb))); |
67 | }; | 66 | }; |
68 | return None; | 67 | return None; |
diff --git a/src/main.rs b/src/main.rs index d96119e..609738e 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -12,7 +12,13 @@ use crate::command::{open_command_window, Command}; | |||
12 | use crate::utils::{load_configuration_file, AppConfig}; | 12 | use crate::utils::{load_configuration_file, AppConfig}; |
13 | 13 | ||
14 | use clap::{App as ClapApp, Arg}; | 14 | use clap::{App as ClapApp, Arg}; |
15 | |||
16 | #[cfg(any(target_os = "linux", target_os = "macos"))] | ||
15 | use cursive::termion; | 17 | use cursive::termion; |
18 | |||
19 | #[cfg(target_os = "windows")] | ||
20 | use cursive::crossterm; | ||
21 | |||
16 | use cursive::views::{LinearLayout, NamedView}; | 22 | use cursive::views::{LinearLayout, NamedView}; |
17 | use lazy_static::lazy_static; | 23 | use lazy_static::lazy_static; |
18 | 24 | ||
@@ -33,6 +39,14 @@ fn main() { | |||
33 | .value_name("CMD") | 39 | .value_name("CMD") |
34 | .help("run a dijo command"), | 40 | .help("run a dijo command"), |
35 | ) | 41 | ) |
42 | .arg( | ||
43 | Arg::with_name("list") | ||
44 | .short("l") | ||
45 | .long("list") | ||
46 | .takes_value(false) | ||
47 | .help("list dijo habits") | ||
48 | .conflicts_with("command"), | ||
49 | ) | ||
36 | .get_matches(); | 50 | .get_matches(); |
37 | if let Some(c) = matches.value_of("command") { | 51 | if let Some(c) = matches.value_of("command") { |
38 | let command = Command::from_string(c); | 52 | let command = Command::from_string(c); |
@@ -49,8 +63,17 @@ fn main() { | |||
49 | "Commands other than `track-up` and `track-down` are currently not supported!" | 63 | "Commands other than `track-up` and `track-down` are currently not supported!" |
50 | ), | 64 | ), |
51 | } | 65 | } |
66 | } else if matches.is_present("list") { | ||
67 | for h in App::load_state().list_habits() { | ||
68 | println!("{}", h); | ||
69 | } | ||
52 | } else { | 70 | } else { |
71 | #[cfg(target_os = "windows")] | ||
72 | let mut s = crossterm().unwrap(); | ||
73 | |||
74 | #[cfg(any(target_os = "linux", target_os = "macos"))] | ||
53 | let mut s = termion().unwrap(); | 75 | let mut s = termion().unwrap(); |
76 | |||
54 | let app = App::load_state(); | 77 | let app = App::load_state(); |
55 | let layout = NamedView::new( | 78 | let layout = NamedView::new( |
56 | "Frame", | 79 | "Frame", |