diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/habit/traits.rs | 4 | ||||
-rw-r--r-- | src/main.rs | 39 |
2 files changed, 34 insertions, 9 deletions
diff --git a/src/habit/traits.rs b/src/habit/traits.rs index 5092bc5..74fd00b 100644 --- a/src/habit/traits.rs +++ b/src/habit/traits.rs | |||
@@ -39,7 +39,7 @@ pub trait HabitWrapper: erased_serde::Serialize { | |||
39 | fn on_event(&mut self, event: Event) -> EventResult; | 39 | fn on_event(&mut self, event: Event) -> EventResult; |
40 | fn required_size(&mut self, _: Vec2) -> Vec2; | 40 | fn required_size(&mut self, _: Vec2) -> Vec2; |
41 | fn take_focus(&mut self, _: Direction) -> bool; | 41 | fn take_focus(&mut self, _: Direction) -> bool; |
42 | fn get_name(&self) -> String; | 42 | fn name(&self) -> String; |
43 | 43 | ||
44 | fn set_view_month_offset(&mut self, offset: u32); | 44 | fn set_view_month_offset(&mut self, offset: u32); |
45 | fn view_month_offset(&self) -> u32; | 45 | fn view_month_offset(&self) -> u32; |
@@ -78,7 +78,7 @@ macro_rules! auto_habit_impl { | |||
78 | fn modify(&mut self, date: NaiveDate, event: TrackEvent) { | 78 | fn modify(&mut self, date: NaiveDate, event: TrackEvent) { |
79 | Habit::modify(self, date, event); | 79 | Habit::modify(self, date, event); |
80 | } | 80 | } |
81 | fn get_name(&self) -> String { | 81 | fn name(&self) -> String { |
82 | Habit::name(self) | 82 | Habit::name(self) |
83 | } | 83 | } |
84 | fn set_view_month_offset(&mut self, offset: u32) { | 84 | fn set_view_month_offset(&mut self, offset: u32) { |
diff --git a/src/main.rs b/src/main.rs index 2313201..3efecd6 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -11,7 +11,8 @@ use crate::app::App; | |||
11 | use crate::command::{open_command_window, Command}; | 11 | 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 cursive::crossterm; | 14 | use clap::{App as ClapApp, Arg}; |
15 | use cursive::ncurses; | ||
15 | use cursive::views::NamedView; | 16 | use cursive::views::NamedView; |
16 | use lazy_static::lazy_static; | 17 | use lazy_static::lazy_static; |
17 | 18 | ||
@@ -20,11 +21,35 @@ lazy_static! { | |||
20 | } | 21 | } |
21 | 22 | ||
22 | fn main() { | 23 | fn main() { |
23 | let mut s = crossterm().unwrap(); | 24 | let matches = ClapApp::new(env!("CARGO_PKG_NAME")) |
24 | let app = App::load_state(); | 25 | .version(env!("CARGO_PKG_VERSION")) |
25 | s.add_layer(NamedView::new("Main", app)); | 26 | .author(env!("CARGO_PKG_AUTHORS")) |
26 | s.add_global_callback(':', |s| open_command_window(s)); | 27 | .about(env!("CARGO_PKG_DESCRIPTION")) |
28 | .arg( | ||
29 | Arg::with_name("command") | ||
30 | .short("c") | ||
31 | .long("command") | ||
32 | .takes_value(true) | ||
33 | .value_name("CMD") | ||
34 | .help("run a dijo command"), | ||
35 | ) | ||
36 | .get_matches(); | ||
37 | if let Some(c) = matches.value_of("command") { | ||
38 | let command = Command::from_string(c); | ||
39 | if matches!(command, Command::TrackUp(_) | Command::TrackDown(_)) { | ||
40 | let mut app = App::load_state(); | ||
41 | app.parse_command(command); | ||
42 | app.save_state(); | ||
43 | } else { | ||
44 | eprintln!("Invalid or unsupported command!"); | ||
45 | } | ||
46 | } else { | ||
47 | let mut s = ncurses().unwrap(); | ||
48 | let app = App::load_state(); | ||
49 | s.add_layer(NamedView::new("Main", app)); | ||
50 | s.add_global_callback(':', |s| open_command_window(s)); | ||
27 | 51 | ||
28 | s.set_theme(theme::theme_gen()); | 52 | s.set_theme(theme::theme_gen()); |
29 | s.run(); | 53 | s.run(); |
54 | } | ||
30 | } | 55 | } |