aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml5
-rw-r--r--src/habit.rs6
-rw-r--r--src/views/bitview.rs4
-rw-r--r--src/views/countview.rs3
4 files changed, 8 insertions, 10 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 53ee9d7..1f9aea9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,9 +8,12 @@ edition = "2018"
8 8
9[dependencies] 9[dependencies]
10cursive = "0.14" 10cursive = "0.14"
11chrono = "0.4"
12serde_json = "1.0" 11serde_json = "1.0"
13 12
13[dependencies.chrono]
14version = "0.4"
15features = ["serde"]
16
14[dependencies.serde] 17[dependencies.serde]
15version = "1.0.103" 18version = "1.0.103"
16features = ["derive"] 19features = ["derive"]
diff --git a/src/habit.rs b/src/habit.rs
index 967e425..6445545 100644
--- a/src/habit.rs
+++ b/src/habit.rs
@@ -1,8 +1,9 @@
1use std::collections::HashMap; 1use std::collections::HashMap;
2 2
3use chrono::NaiveDate; 3use chrono::NaiveDate;
4use serde::Serialize;
4 5
5#[derive(Debug)] 6#[derive(Serialize, Debug)]
6pub struct Habit<T> { 7pub struct Habit<T> {
7 name: String, 8 name: String,
8 stats: HashMap<NaiveDate, T>, 9 stats: HashMap<NaiveDate, T>,
@@ -20,15 +21,12 @@ where
20 goal, 21 goal,
21 }; 22 };
22 } 23 }
23
24 pub fn get_name(&self) -> String { 24 pub fn get_name(&self) -> String {
25 return self.name.to_owned(); 25 return self.name.to_owned();
26 } 26 }
27
28 pub fn get_by_date(&self, date: NaiveDate) -> Option<&T> { 27 pub fn get_by_date(&self, date: NaiveDate) -> Option<&T> {
29 self.stats.get(&date) 28 self.stats.get(&date)
30 } 29 }
31
32 pub fn insert_entry(&mut self, date: NaiveDate, val: T) { 30 pub fn insert_entry(&mut self, date: NaiveDate, val: T) {
33 *self.stats.entry(date).or_insert(val) = val; 31 *self.stats.entry(date).or_insert(val) = val;
34 } 32 }
diff --git a/src/views/bitview.rs b/src/views/bitview.rs
index 16b3ad8..b31b050 100644
--- a/src/views/bitview.rs
+++ b/src/views/bitview.rs
@@ -1,7 +1,6 @@
1use cursive::direction::Direction; 1use cursive::direction::Direction;
2use cursive::event::{Event, EventResult, Key}; 2use cursive::event::{Event, EventResult, Key};
3use cursive::theme::{BaseColor, Color, Effect, Style}; 3use cursive::theme::{BaseColor, Color, Style};
4use cursive::utils::markup::StyledString;
5use cursive::view::View; 4use cursive::view::View;
6use cursive::{Printer, Vec2}; 5use cursive::{Printer, Vec2};
7 6
@@ -46,7 +45,6 @@ impl View for BitView {
46 let true_style = Style::from(Color::Dark(BaseColor::Cyan)); 45 let true_style = Style::from(Color::Dark(BaseColor::Cyan));
47 let false_style = Style::from(Color::Dark(BaseColor::Magenta)); 46 let false_style = Style::from(Color::Dark(BaseColor::Magenta));
48 let future_style = Style::from(Color::Light(BaseColor::Black)); 47 let future_style = Style::from(Color::Light(BaseColor::Black));
49 let today_style = Style::from(Color::Dark(BaseColor::White));
50 48
51 for i in 1..=31 { 49 for i in 1..=31 {
52 let day = NaiveDate::from_ymd_opt(year, month, i); 50 let day = NaiveDate::from_ymd_opt(year, month, i);
diff --git a/src/views/countview.rs b/src/views/countview.rs
index 1e8855a..d906acb 100644
--- a/src/views/countview.rs
+++ b/src/views/countview.rs
@@ -1,7 +1,6 @@
1use cursive::direction::Direction; 1use cursive::direction::Direction;
2use cursive::event::{Event, EventResult, Key}; 2use cursive::event::{Event, EventResult, Key};
3use cursive::theme::{BaseColor, Color, Effect, Style}; 3use cursive::theme::{BaseColor, Color, Style};
4use cursive::utils::markup::StyledString;
5use cursive::view::View; 4use cursive::view::View;
6use cursive::{Printer, Vec2}; 5use cursive::{Printer, Vec2};
7 6