From fbcc966a3da8a75842c6b8843a9fd7f1edb0db15 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 24 Feb 2021 11:57:37 +0530 Subject: add GoalKinds - this allows for changing habit goals easily - easier to add new habits to dijo in newer versions --- src/app/impl_self.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/app/impl_self.rs') 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; use cursive::Vec2; use notify::{watcher, RecursiveMode, Watcher}; -use crate::command::{Command, CommandLineError}; -use crate::habit::{Bit, Count, HabitWrapper, TrackEvent, ViewMode}; +use crate::command::{Command, CommandLineError, GoalKind}; +use crate::habit::{Bit, Count, Float, HabitWrapper, TrackEvent, ViewMode}; use crate::utils::{self, GRID_WIDTH, VIEW_HEIGHT, VIEW_WIDTH}; use crate::app::{App, Cursor, Message, MessageKind, StatusLine}; @@ -227,11 +227,21 @@ impl App { .set_message(format!("Habit `{}` already exist", &name)); return; } - let kind = if goal == Some(1) { "bit" } else { "count" }; - if kind == "count" { - self.add_habit(Box::new(Count::new(name, goal.unwrap_or(0), auto))); - } else if kind == "bit" { - self.add_habit(Box::new(Bit::new(name, auto))); + match goal { + Some(GoalKind::Bit) => { + self.add_habit(Box::new(Bit::new(name, auto))); + } + Some(GoalKind::Count(v)) => { + self.add_habit(Box::new(Count::new(name, v, auto))); + } + Some(GoalKind::Float(v, p)) => { + self.message.set_kind(MessageKind::Error); + self.message.set_message(format!("Added floating habit")); + self.add_habit(Box::new(Float::new(name, v, p, auto))); + } + _ => { + self.add_habit(Box::new(Count::new(name, 0, auto))); + } } } Command::Delete(name) => { -- cgit v1.2.3