diff options
-rw-r--r-- | Cargo.lock | 44 | ||||
-rw-r--r-- | src/habit/bit.rs | 17 | ||||
-rw-r--r-- | src/habit/count.rs | 7 | ||||
-rw-r--r-- | src/habit/prelude.rs | 1 |
4 files changed, 21 insertions, 48 deletions
@@ -92,12 +92,6 @@ dependencies = [ | |||
92 | ] | 92 | ] |
93 | 93 | ||
94 | [[package]] | 94 | [[package]] |
95 | name = "cc" | ||
96 | version = "1.0.58" | ||
97 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
98 | checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518" | ||
99 | |||
100 | [[package]] | ||
101 | name = "cfg-if" | 95 | name = "cfg-if" |
102 | version = "0.1.10" | 96 | version = "0.1.10" |
103 | source = "registry+https://github.com/rust-lang/crates.io-index" | 97 | source = "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]] |
271 | name = "dijo" | 262 | name = "dijo" |
272 | version = "0.1.3" | 263 | version = "0.1.4" |
273 | dependencies = [ | 264 | dependencies = [ |
274 | "chrono", | 265 | "chrono", |
275 | "clap", | 266 | "clap", |
@@ -540,12 +531,6 @@ dependencies = [ | |||
540 | ] | 531 | ] |
541 | 532 | ||
542 | [[package]] | 533 | [[package]] |
543 | name = "maplit" | ||
544 | version = "1.0.2" | ||
545 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
546 | checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" | ||
547 | |||
548 | [[package]] | ||
549 | name = "maybe-uninit" | 534 | name = "maybe-uninit" |
550 | version = "2.0.0" | 535 | version = "2.0.0" |
551 | source = "registry+https://github.com/rust-lang/crates.io-index" | 536 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -595,17 +580,6 @@ dependencies = [ | |||
595 | ] | 580 | ] |
596 | 581 | ||
597 | [[package]] | 582 | [[package]] |
598 | name = "ncurses" | ||
599 | version = "5.99.0" | ||
600 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
601 | checksum = "15699bee2f37e9f8828c7b35b2bc70d13846db453f2d507713b758fabe536b82" | ||
602 | dependencies = [ | ||
603 | "cc", | ||
604 | "libc", | ||
605 | "pkg-config", | ||
606 | ] | ||
607 | |||
608 | [[package]] | ||
609 | name = "net2" | 583 | name = "net2" |
610 | version = "0.2.34" | 584 | version = "0.2.34" |
611 | source = "registry+https://github.com/rust-lang/crates.io-index" | 585 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -713,12 +687,6 @@ dependencies = [ | |||
713 | ] | 687 | ] |
714 | 688 | ||
715 | [[package]] | 689 | [[package]] |
716 | name = "pkg-config" | ||
717 | version = "0.3.18" | ||
718 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
719 | checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" | ||
720 | |||
721 | [[package]] | ||
722 | name = "proc-macro-hack" | 690 | name = "proc-macro-hack" |
723 | version = "0.5.16" | 691 | version = "0.5.16" |
724 | source = "registry+https://github.com/rust-lang/crates.io-index" | 692 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -882,16 +850,6 @@ dependencies = [ | |||
882 | ] | 850 | ] |
883 | 851 | ||
884 | [[package]] | 852 | [[package]] |
885 | name = "term_size" | ||
886 | version = "0.3.2" | ||
887 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
888 | checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9" | ||
889 | dependencies = [ | ||
890 | "libc", | ||
891 | "winapi 0.3.9", | ||
892 | ] | ||
893 | |||
894 | [[package]] | ||
895 | name = "termion" | 853 | name = "termion" |
896 | version = "1.5.5" | 854 | version = "1.5.5" |
897 | source = "registry+https://github.com/rust-lang/crates.io-index" | 855 | source = "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}; | |||
2 | use std::default; | 2 | use std::default; |
3 | use std::fmt; | 3 | use std::fmt; |
4 | 4 | ||
5 | #[derive(Debug, PartialEq)] | ||
5 | pub enum TrackEvent { | 6 | pub enum TrackEvent { |
6 | Increment, | 7 | Increment, |
7 | Decrement, | 8 | Decrement, |