diff options
-rw-r--r-- | src/app.rs | 19 | ||||
-rw-r--r-- | src/main.rs | 7 |
2 files changed, 24 insertions, 2 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) { |
diff --git a/src/main.rs b/src/main.rs index 3e838e5..418ec3b 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -6,14 +6,17 @@ use lazy_static::lazy_static; | |||
6 | 6 | ||
7 | //use cursive::views::{Dialog, EditView, LinearLayout, ListView, SelectView}; | 7 | //use cursive::views::{Dialog, EditView, LinearLayout, ListView, SelectView}; |
8 | use cursive::theme::{BaseColor, Color}; | 8 | use cursive::theme::{BaseColor, Color}; |
9 | use cursive::views::NamedView; | ||
9 | use cursive::Cursive; | 10 | use cursive::Cursive; |
10 | 11 | ||
11 | mod habit; | 12 | mod habit; |
12 | use crate::habit::{Bit, Count, Habit}; | 13 | use crate::habit::{Bit, Count, Habit}; |
13 | 14 | ||
14 | mod app; | 15 | mod app; |
16 | mod command; | ||
15 | mod theme; | 17 | mod theme; |
16 | use crate::app::{App, ViewMode}; | 18 | use crate::app::{App, ViewMode}; |
19 | use crate::command::{open_command_window, Command}; | ||
17 | 20 | ||
18 | mod views; | 21 | mod views; |
19 | 22 | ||
@@ -77,13 +80,13 @@ fn main() { | |||
77 | // walking.insert_entry(NaiveDate::from_ymd(2020, 5, 14), false.into()); | 80 | // walking.insert_entry(NaiveDate::from_ymd(2020, 5, 14), false.into()); |
78 | // walking.insert_entry(NaiveDate::from_ymd(2020, 5, 15), true.into()); | 81 | // walking.insert_entry(NaiveDate::from_ymd(2020, 5, 15), true.into()); |
79 | 82 | ||
80 | // let mut app = App::new(); | ||
81 | // app.add_habit(Box::new(gymming)); | 83 | // app.add_habit(Box::new(gymming)); |
82 | // app.add_habit(Box::new(reading)); | 84 | // app.add_habit(Box::new(reading)); |
83 | // app.add_habit(Box::new(walking)); | 85 | // app.add_habit(Box::new(walking)); |
84 | 86 | ||
85 | let app = App::load_state(); | 87 | let app = App::load_state(); |
86 | s.add_layer(app); | 88 | s.add_layer(NamedView::new("Main", app)); |
89 | s.add_global_callback(':', |s| open_command_window(s)); | ||
87 | 90 | ||
88 | s.set_theme(theme::theme_gen()); | 91 | s.set_theme(theme::theme_gen()); |
89 | s.run(); | 92 | s.run(); |