summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAkshay <nerdy@peppe.rs>2020-07-16 21:47:30 +0530
committerAkshay <nerdy@peppe.rs>2020-07-16 21:47:30 +0530
commitbe1540a4ac54a51fce46553303323936165f1735 (patch)
tree1f499847a807a0306a5b8a4b0287a23371fa29e4
parent7d5e46626110a351104ededeaebdcb9723c7e786 (diff)
begin work on command line interface
-rw-r--r--src/habit/traits.rs4
-rw-r--r--src/main.rs39
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 {
fn on_event(&mut self, event: Event) -> EventResult;
fn required_size(&mut self, _: Vec2) -> Vec2;
fn take_focus(&mut self, _: Direction) -> bool;
- fn get_name(&self) -> String;
+ fn name(&self) -> String;
fn set_view_month_offset(&mut self, offset: u32);
fn view_month_offset(&self) -> u32;
@@ -78,7 +78,7 @@ macro_rules! auto_habit_impl {
fn modify(&mut self, date: NaiveDate, event: TrackEvent) {
Habit::modify(self, date, event);
}
- fn get_name(&self) -> String {
+ fn name(&self) -> String {
Habit::name(self)
}
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;
use crate::command::{open_command_window, Command};
use crate::utils::{load_configuration_file, AppConfig};
-use cursive::crossterm;
+use clap::{App as ClapApp, Arg};
+use cursive::ncurses;
use cursive::views::NamedView;
use lazy_static::lazy_static;
@@ -20,11 +21,35 @@ lazy_static! {
}
fn main() {
- let mut s = crossterm().unwrap();
- let app = App::load_state();
- s.add_layer(NamedView::new("Main", app));
- s.add_global_callback(':', |s| open_command_window(s));
+ let matches = ClapApp::new(env!("CARGO_PKG_NAME"))
+ .version(env!("CARGO_PKG_VERSION"))
+ .author(env!("CARGO_PKG_AUTHORS"))
+ .about(env!("CARGO_PKG_DESCRIPTION"))
+ .arg(
+ Arg::with_name("command")
+ .short("c")
+ .long("command")
+ .takes_value(true)
+ .value_name("CMD")
+ .help("run a dijo command"),
+ )
+ .get_matches();
+ if let Some(c) = matches.value_of("command") {
+ let command = Command::from_string(c);
+ if matches!(command, Command::TrackUp(_) | Command::TrackDown(_)) {
+ let mut app = App::load_state();
+ app.parse_command(command);
+ app.save_state();
+ } else {
+ eprintln!("Invalid or unsupported command!");
+ }
+ } else {
+ let mut s = ncurses().unwrap();
+ let app = App::load_state();
+ s.add_layer(NamedView::new("Main", app));
+ s.add_global_callback(':', |s| open_command_window(s));
- s.set_theme(theme::theme_gen());
- s.run();
+ s.set_theme(theme::theme_gen());
+ s.run();
+ }
}