aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock44
-rw-r--r--src/habit/bit.rs17
-rw-r--r--src/habit/count.rs7
-rw-r--r--src/habit/prelude.rs1
4 files changed, 21 insertions, 48 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 63d34ea..ade0cc4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -92,12 +92,6 @@ dependencies = [
92] 92]
93 93
94[[package]] 94[[package]]
95name = "cc"
96version = "1.0.58"
97source = "registry+https://github.com/rust-lang/crates.io-index"
98checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518"
99
100[[package]]
101name = "cfg-if" 95name = "cfg-if"
102version = "0.1.10" 96version = "0.1.10"
103source = "registry+https://github.com/rust-lang/crates.io-index" 97source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -201,10 +195,7 @@ dependencies = [
201 "lazy_static", 195 "lazy_static",
202 "libc", 196 "libc",
203 "log", 197 "log",
204 "maplit",
205 "ncurses",
206 "signal-hook", 198 "signal-hook",
207 "term_size",
208 "termion", 199 "termion",
209 "unicode-segmentation", 200 "unicode-segmentation",
210 "unicode-width", 201 "unicode-width",
@@ -269,7 +260,7 @@ dependencies = [
269 260
270[[package]] 261[[package]]
271name = "dijo" 262name = "dijo"
272version = "0.1.3" 263version = "0.1.4"
273dependencies = [ 264dependencies = [
274 "chrono", 265 "chrono",
275 "clap", 266 "clap",
@@ -540,12 +531,6 @@ dependencies = [
540] 531]
541 532
542[[package]] 533[[package]]
543name = "maplit"
544version = "1.0.2"
545source = "registry+https://github.com/rust-lang/crates.io-index"
546checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
547
548[[package]]
549name = "maybe-uninit" 534name = "maybe-uninit"
550version = "2.0.0" 535version = "2.0.0"
551source = "registry+https://github.com/rust-lang/crates.io-index" 536source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -595,17 +580,6 @@ dependencies = [
595] 580]
596 581
597[[package]] 582[[package]]
598name = "ncurses"
599version = "5.99.0"
600source = "registry+https://github.com/rust-lang/crates.io-index"
601checksum = "15699bee2f37e9f8828c7b35b2bc70d13846db453f2d507713b758fabe536b82"
602dependencies = [
603 "cc",
604 "libc",
605 "pkg-config",
606]
607
608[[package]]
609name = "net2" 583name = "net2"
610version = "0.2.34" 584version = "0.2.34"
611source = "registry+https://github.com/rust-lang/crates.io-index" 585source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -713,12 +687,6 @@ dependencies = [
713] 687]
714 688
715[[package]] 689[[package]]
716name = "pkg-config"
717version = "0.3.18"
718source = "registry+https://github.com/rust-lang/crates.io-index"
719checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33"
720
721[[package]]
722name = "proc-macro-hack" 690name = "proc-macro-hack"
723version = "0.5.16" 691version = "0.5.16"
724source = "registry+https://github.com/rust-lang/crates.io-index" 692source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -882,16 +850,6 @@ dependencies = [
882] 850]
883 851
884[[package]] 852[[package]]
885name = "term_size"
886version = "0.3.2"
887source = "registry+https://github.com/rust-lang/crates.io-index"
888checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9"
889dependencies = [
890 "libc",
891 "winapi 0.3.9",
892]
893
894[[package]]
895name = "termion" 853name = "termion"
896version = "1.5.5" 854version = "1.5.5"
897source = "registry+https://github.com/rust-lang/crates.io-index" 855source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src/habit/bit.rs b/src/habit/bit.rs
index 3386182..8fa14c2 100644
--- a/src/habit/bit.rs
+++ b/src/habit/bit.rs
@@ -100,11 +100,22 @@ impl Habit for Bit {
100 fn goal(&self) -> u32 { 100 fn goal(&self) -> u32 {
101 return 1; 101 return 1;
102 } 102 }
103 fn modify(&mut self, date: NaiveDate, _: TrackEvent) { 103 fn modify(&mut self, date: NaiveDate, event: TrackEvent) {
104 if let Some(val) = self.stats.get_mut(&date) { 104 if let Some(val) = self.stats.get_mut(&date) {
105 *val = (val.0 ^ true).into(); 105 match event {
106 TrackEvent::Increment => *val = (val.0 ^ true).into(),
107 TrackEvent::Decrement => {
108 if val.0 {
109 *val = false.into();
110 } else {
111 self.stats.remove(&date);
112 }
113 }
114 }
106 } else { 115 } else {
107 self.insert_entry(date, CustomBool(true)); 116 if event == TrackEvent::Increment {
117 self.insert_entry(date, CustomBool(true));
118 }
108 } 119 }
109 } 120 }
110 fn set_view_month_offset(&mut self, offset: u32) { 121 fn set_view_month_offset(&mut self, offset: u32) {
diff --git a/src/habit/count.rs b/src/habit/count.rs
index 1bdf920..d351758 100644
--- a/src/habit/count.rs
+++ b/src/habit/count.rs
@@ -84,12 +84,15 @@ impl Habit for Count {
84 if *val > 0 { 84 if *val > 0 {
85 *val -= 1 85 *val -= 1
86 } else { 86 } else {
87 *val = 0 87 self.stats.remove(&date);
88 }; 88 };
89 } 89 }
90 } 90 }
91 } else { 91 } else {
92 self.insert_entry(date, 1); 92 match event {
93 TrackEvent::Increment => self.insert_entry(date, 1),
94 _ => {}
95 };
93 } 96 }
94 } 97 }
95 fn set_view_month_offset(&mut self, offset: u32) { 98 fn set_view_month_offset(&mut self, offset: u32) {
diff --git a/src/habit/prelude.rs b/src/habit/prelude.rs
index 19b00a7..8335d6c 100644
--- a/src/habit/prelude.rs
+++ b/src/habit/prelude.rs
@@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};
2use std::default; 2use std::default;
3use std::fmt; 3use std::fmt;
4 4
5#[derive(Debug, PartialEq)]
5pub enum TrackEvent { 6pub enum TrackEvent {
6 Increment, 7 Increment,
7 Decrement, 8 Decrement,