From cc8cde9b229b1cd8de8e9e67b164c80b1cdc0ebf Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 27 Feb 2020 18:23:19 +0530 Subject: add helpers for statusline --- src/habit.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/habit.rs b/src/habit.rs index 8527ac2..7d50adf 100644 --- a/src/habit.rs +++ b/src/habit.rs @@ -34,6 +34,7 @@ pub trait HabitTrait { fn insert_entry(&mut self, date: NaiveDate, val: HabitType); fn reached_goal(&self, date: NaiveDate) -> bool; fn remaining(&self, date: NaiveDate) -> u32; + fn total(&self) -> u32; } #[derive(Serialize, Debug)] @@ -75,7 +76,7 @@ impl Habit { } else { match self.goal { HabitType::Bit(_) => self.insert_entry(date, HabitType::Bit(true)), - HabitType::Count(_) => self.insert_entry(date, HabitType::Count(0)), + HabitType::Count(_) => self.insert_entry(date, HabitType::Count(1)), } } } @@ -119,7 +120,13 @@ impl HabitTrait for Habit { HabitType::Count(c) => return self.goal.inner_count() - *c, } } else { - return 0; + return self.total(); + } + } + fn total(&self) -> u32 { + match self.goal { + HabitType::Bit(_) => return 1, + HabitType::Count(c) => return c, } } } -- cgit v1.2.3