diff options
author | Akshay <[email protected]> | 2020-06-30 05:41:56 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2020-06-30 05:41:56 +0100 |
commit | 775f3486a9066dfc8cb1f31e6c5b26be253d05ed (patch) | |
tree | 441a355d6fcf22e56ad132a9e656a1fb7d0efe63 /src/app.rs | |
parent | 501e44c193cc6dd1299956f1ab85465a444b84a2 (diff) |
access command mode via ':' and basic command parsing
Diffstat (limited to 'src/app.rs')
-rw-r--r-- | src/app.rs | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -10,6 +10,7 @@ use cursive::{Printer, Vec2}; | |||
10 | use chrono::NaiveDate; | 10 | use chrono::NaiveDate; |
11 | 11 | ||
12 | use crate::habit::{Bit, Count, Habit, HabitWrapper}; | 12 | use crate::habit::{Bit, Count, Habit, HabitWrapper}; |
13 | use crate::Command; | ||
13 | use crate::CONFIGURATION; | 14 | use crate::CONFIGURATION; |
14 | 15 | ||
15 | use serde::{Deserialize, Serialize}; | 16 | use serde::{Deserialize, Serialize}; |
@@ -125,6 +126,24 @@ impl App { | |||
125 | return serde_json::from_str(&j).unwrap(); | 126 | return serde_json::from_str(&j).unwrap(); |
126 | } | 127 | } |
127 | 128 | ||
129 | pub fn parse_command(&mut self, input: &str) { | ||
130 | let c = Command::from_string(input); | ||
131 | match c { | ||
132 | Command::Add(name, kind, goal) => { | ||
133 | if kind == "count" { | ||
134 | self.add_habit(Box::new(Count::new(name, goal.unwrap_or(0)))); | ||
135 | eprintln!("Found COUNT!"); | ||
136 | } else if kind == "bit" { | ||
137 | self.add_habit(Box::new(Bit::new(name))); | ||
138 | eprintln!("Found BIT!"); | ||
139 | } | ||
140 | } | ||
141 | _ => { | ||
142 | eprintln!("UNKNOWN COMMAND!"); | ||
143 | } | ||
144 | } | ||
145 | } | ||
146 | |||
128 | // this function does IO | 147 | // this function does IO |
129 | // TODO: convert this into non-blocking async function | 148 | // TODO: convert this into non-blocking async function |
130 | fn save_state(&self) { | 149 | fn save_state(&self) { |