aboutsummaryrefslogtreecommitdiff
path: root/src/app/impl_self.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-02-24 06:27:37 +0000
committerAkshay <[email protected]>2021-02-24 06:27:37 +0000
commitfbcc966a3da8a75842c6b8843a9fd7f1edb0db15 (patch)
treebe2851277e689fec2f1629ca7a03bba1c8931446 /src/app/impl_self.rs
parent3169cb6c8056b46a6f08533014366b8c441971f8 (diff)
add GoalKinds
- this allows for changing habit goals easily - easier to add new habits to dijo in newer versions
Diffstat (limited to 'src/app/impl_self.rs')
-rw-r--r--src/app/impl_self.rs24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs
index d5f93ff..fad965a 100644
--- a/src/app/impl_self.rs
+++ b/src/app/impl_self.rs
@@ -11,8 +11,8 @@ use cursive::direction::Absolute;
11use cursive::Vec2; 11use cursive::Vec2;
12use notify::{watcher, RecursiveMode, Watcher}; 12use notify::{watcher, RecursiveMode, Watcher};
13 13
14use crate::command::{Command, CommandLineError}; 14use crate::command::{Command, CommandLineError, GoalKind};
15use crate::habit::{Bit, Count, HabitWrapper, TrackEvent, ViewMode}; 15use crate::habit::{Bit, Count, Float, HabitWrapper, TrackEvent, ViewMode};
16use crate::utils::{self, GRID_WIDTH, VIEW_HEIGHT, VIEW_WIDTH}; 16use crate::utils::{self, GRID_WIDTH, VIEW_HEIGHT, VIEW_WIDTH};
17 17
18use crate::app::{App, Cursor, Message, MessageKind, StatusLine}; 18use crate::app::{App, Cursor, Message, MessageKind, StatusLine};
@@ -227,11 +227,21 @@ impl App {
227 .set_message(format!("Habit `{}` already exist", &name)); 227 .set_message(format!("Habit `{}` already exist", &name));
228 return; 228 return;
229 } 229 }
230 let kind = if goal == Some(1) { "bit" } else { "count" }; 230 match goal {
231 if kind == "count" { 231 Some(GoalKind::Bit) => {
232 self.add_habit(Box::new(Count::new(name, goal.unwrap_or(0), auto))); 232 self.add_habit(Box::new(Bit::new(name, auto)));
233 } else if kind == "bit" { 233 }
234 self.add_habit(Box::new(Bit::new(name, auto))); 234 Some(GoalKind::Count(v)) => {
235 self.add_habit(Box::new(Count::new(name, v, auto)));
236 }
237 Some(GoalKind::Float(v, p)) => {
238 self.message.set_kind(MessageKind::Error);
239 self.message.set_message(format!("Added floating habit"));
240 self.add_habit(Box::new(Float::new(name, v, p, auto)));
241 }
242 _ => {
243 self.add_habit(Box::new(Count::new(name, 0, auto)));
244 }
235 } 245 }
236 } 246 }
237 Command::Delete(name) => { 247 Command::Delete(name) => {