aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.rs43
-rw-r--r--src/habit/prelude.rs15
-rw-r--r--src/views.rs3
3 files changed, 45 insertions, 16 deletions
diff --git a/src/app.rs b/src/app.rs
index 93e5def..2d83714 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -48,6 +48,13 @@ impl App {
48 self.habits.retain(|h| h.get_name() != name); 48 self.habits.retain(|h| h.get_name() != name);
49 } 49 }
50 50
51 pub fn get_mode(&self) -> ViewMode {
52 if self.habits.is_empty() {
53 return ViewMode::Day;
54 }
55 return self.habits[self.focus].view_mode();
56 }
57
51 pub fn set_mode(&mut self, mode: ViewMode) { 58 pub fn set_mode(&mut self, mode: ViewMode) {
52 if !self.habits.is_empty() { 59 if !self.habits.is_empty() {
53 self.habits[self.focus].set_view_mode(mode); 60 self.habits[self.focus].set_view_mode(mode);
@@ -115,22 +122,19 @@ impl App {
115 let completed = total - remaining; 122 let completed = total - remaining;
116 123
117 let timestamp = if self.view_month_offset == 0 { 124 let timestamp = if self.view_month_offset == 0 {
118 format!( 125 format!("{}", Local::now().date().format("%d/%b/%y"),)
119 "{:>width$}",
120 Local::now().date().format("%d/%b/%y"),
121 width = CONFIGURATION.view_width * CONFIGURATION.grid_width
122 )
123 } else { 126 } else {
124 let months = self.view_month_offset; 127 let months = self.view_month_offset;
125 format!( 128 format!("{}", format!("{} months ago", months),)
126 "{:>width$}",
127 format!("{} months ago", months),
128 width = CONFIGURATION.view_width * CONFIGURATION.grid_width
129 )
130 }; 129 };
131 130
132 StatusLine { 131 StatusLine {
133 0: format!("Today: {} completed, {} remaining", completed, remaining), 132 0: format!(
133 "Today: {} completed, {} remaining --{}--",
134 completed,
135 remaining,
136 self.get_mode()
137 ),
134 1: timestamp, 138 1: timestamp,
135 } 139 }
136 } 140 }
@@ -218,18 +222,27 @@ impl App {
218impl View for App { 222impl View for App {
219 fn draw(&self, printer: &Printer) { 223 fn draw(&self, printer: &Printer) {
220 let grid_width = CONFIGURATION.grid_width; 224 let grid_width = CONFIGURATION.grid_width;
225 let view_width = CONFIGURATION.view_width;
226 let view_height = CONFIGURATION.view_height;
221 let mut offset = Vec2::zero(); 227 let mut offset = Vec2::zero();
222 for (idx, i) in self.habits.iter().enumerate() { 228 for (idx, i) in self.habits.iter().enumerate() {
223 if idx >= grid_width && idx % grid_width == 0 { 229 if idx >= grid_width && idx % grid_width == 0 {
224 offset = offset.map_y(|y| y + CONFIGURATION.view_height).map_x(|_| 0); 230 offset = offset.map_y(|y| y + view_height).map_x(|_| 0);
225 } 231 }
226 i.draw(&printer.offset(offset).focused(self.focus == idx)); 232 i.draw(&printer.offset(offset).focused(self.focus == idx));
227 offset = offset.map_x(|x| x + CONFIGURATION.view_width + 2); 233 offset = offset.map_x(|x| x + view_width + 2);
228 } 234 }
229 235
230 offset = offset.map_x(|_| 0).map_y(|_| self.max_size().y - 2); 236 offset = offset.map_x(|_| 0).map_y(|_| self.max_size().y - 2);
231 printer.print(offset, &self.status().1); // right status 237
232 printer.print(offset, &self.status().0); // left status 238 let status = self.status();
239 printer.print(offset, &status.0); // left status
240
241 let full = grid_width * (view_width + 2);
242 offset = offset
243 .map_x(|_| full - status.1.len())
244 .map_y(|_| self.max_size().y - 2);
245 printer.print(offset, &status.1); // right status
233 } 246 }
234 247
235 fn required_size(&mut self, _: Vec2) -> Vec2 { 248 fn required_size(&mut self, _: Vec2) -> Vec2 {
diff --git a/src/habit/prelude.rs b/src/habit/prelude.rs
index b8b2bb2..19b00a7 100644
--- a/src/habit/prelude.rs
+++ b/src/habit/prelude.rs
@@ -1,4 +1,6 @@
1use serde::{Deserialize, Serialize}; 1use serde::{Deserialize, Serialize};
2use std::default;
3use std::fmt;
2 4
3pub enum TrackEvent { 5pub enum TrackEvent {
4 Increment, 6 Increment,
@@ -13,12 +15,23 @@ pub enum ViewMode {
13 Year, 15 Year,
14} 16}
15 17
16impl std::default::Default for ViewMode { 18impl default::Default for ViewMode {
17 fn default() -> Self { 19 fn default() -> Self {
18 ViewMode::Day 20 ViewMode::Day
19 } 21 }
20} 22}
21 23
24impl fmt::Display for ViewMode {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 match self {
27 ViewMode::Day => write!(f, "DAY"),
28 ViewMode::Week => write!(f, "WEEK"),
29 ViewMode::Month => write!(f, "MONTH"),
30 ViewMode::Year => write!(f, "YEAR"),
31 }
32 }
33}
34
22pub fn default_auto() -> bool { 35pub fn default_auto() -> bool {
23 false 36 false
24} 37}
diff --git a/src/views.rs b/src/views.rs
index 54d5431..f06978c 100644
--- a/src/views.rs
+++ b/src/views.rs
@@ -135,6 +135,9 @@ where
135 135
136 fn on_event(&mut self, e: Event) -> EventResult { 136 fn on_event(&mut self, e: Event) -> EventResult {
137 let now = Local::now().naive_utc().date(); 137 let now = Local::now().naive_utc().date();
138 if self.is_auto() {
139 return EventResult::Consumed(None);
140 }
138 match e { 141 match e {
139 Event::Key(Key::Enter) | Event::Char('n') => { 142 Event::Key(Key::Enter) | Event::Char('n') => {
140 self.modify(now, TrackEvent::Increment); 143 self.modify(now, TrackEvent::Increment);