From 775f3486a9066dfc8cb1f31e6c5b26be253d05ed Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 30 Jun 2020 10:11:56 +0530 Subject: access command mode via ':' and basic command parsing --- src/app.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/app.rs') diff --git a/src/app.rs b/src/app.rs index 5ba00bf..5b1fa9d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -10,6 +10,7 @@ use cursive::{Printer, Vec2}; use chrono::NaiveDate; use crate::habit::{Bit, Count, Habit, HabitWrapper}; +use crate::Command; use crate::CONFIGURATION; use serde::{Deserialize, Serialize}; @@ -125,6 +126,24 @@ impl App { return serde_json::from_str(&j).unwrap(); } + pub fn parse_command(&mut self, input: &str) { + let c = Command::from_string(input); + match c { + Command::Add(name, kind, goal) => { + if kind == "count" { + self.add_habit(Box::new(Count::new(name, goal.unwrap_or(0)))); + eprintln!("Found COUNT!"); + } else if kind == "bit" { + self.add_habit(Box::new(Bit::new(name))); + eprintln!("Found BIT!"); + } + } + _ => { + eprintln!("UNKNOWN COMMAND!"); + } + } + } + // this function does IO // TODO: convert this into non-blocking async function fn save_state(&self) { -- cgit v1.2.3