diff options
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/impl_self.rs | 20 | ||||
-rw-r--r-- | src/app/impl_view.rs | 16 | ||||
-rw-r--r-- | src/app/message.rs | 12 |
3 files changed, 23 insertions, 25 deletions
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 2b115a0..744f906 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs | |||
@@ -16,24 +16,20 @@ use crate::habit::{Bit, Count, HabitWrapper, TrackEvent, ViewMode}; | |||
16 | use crate::utils; | 16 | use crate::utils; |
17 | use crate::CONFIGURATION; | 17 | use crate::CONFIGURATION; |
18 | 18 | ||
19 | use crate::app::{App, Message, MessageKind, StatusLine}; | 19 | use crate::app::{App, MessageKind, StatusLine}; |
20 | 20 | ||
21 | impl App { | 21 | impl App { |
22 | pub fn new() -> Self { | 22 | pub fn new() -> Self { |
23 | let (tx, rx) = channel(); | 23 | let (tx, rx) = channel(); |
24 | let mut watcher = watcher(tx, Duration::from_secs(1)).unwrap(); | 24 | let mut watcher = watcher(tx, Duration::from_secs(1)).unwrap(); |
25 | watcher | 25 | watcher.watch(utils::auto_habit_file(), RecursiveMode::Recursive); |
26 | .watch(utils::auto_habit_file(), RecursiveMode::Recursive) | ||
27 | .unwrap_or_else(|e| { | ||
28 | panic!("Unable to start file watcher: {}", e); | ||
29 | }); | ||
30 | return App { | 26 | return App { |
31 | habits: vec![], | 27 | habits: vec![], |
32 | focus: 0, | 28 | focus: 0, |
33 | _file_watcher: watcher, | 29 | _file_watcher: watcher, |
34 | file_event_recv: rx, | 30 | file_event_recv: rx, |
35 | view_month_offset: 0, | 31 | view_month_offset: 0, |
36 | message: Message::default(), | 32 | message: "Type :add <habit-name> <goal> to get started, Ctrl-L to dismiss".into(), |
37 | }; | 33 | }; |
38 | } | 34 | } |
39 | 35 | ||
@@ -147,15 +143,9 @@ impl App { | |||
147 | 143 | ||
148 | pub fn max_size(&self) -> Vec2 { | 144 | pub fn max_size(&self) -> Vec2 { |
149 | let grid_width = CONFIGURATION.grid_width; | 145 | let grid_width = CONFIGURATION.grid_width; |
150 | let width = { | 146 | let width = grid_width * CONFIGURATION.view_width; |
151 | if self.habits.len() > 0 { | ||
152 | grid_width * CONFIGURATION.view_width | ||
153 | } else { | ||
154 | 0 | ||
155 | } | ||
156 | }; | ||
157 | let height = { | 147 | let height = { |
158 | if self.habits.len() > 0 { | 148 | if !self.habits.is_empty() { |
159 | (CONFIGURATION.view_height as f64 | 149 | (CONFIGURATION.view_height as f64 |
160 | * (self.habits.len() as f64 / grid_width as f64).ceil()) | 150 | * (self.habits.len() as f64 / grid_width as f64).ceil()) |
161 | as usize | 151 | as usize |
diff --git a/src/app/impl_view.rs b/src/app/impl_view.rs index 0a6bce6..892b00c 100644 --- a/src/app/impl_view.rs +++ b/src/app/impl_view.rs | |||
@@ -5,7 +5,7 @@ use std::path::PathBuf; | |||
5 | 5 | ||
6 | use cursive::direction::{Absolute, Direction}; | 6 | use cursive::direction::{Absolute, Direction}; |
7 | use cursive::event::{Event, EventResult, Key}; | 7 | use cursive::event::{Event, EventResult, Key}; |
8 | use cursive::theme::{Color, Style}; | 8 | use cursive::theme::Color; |
9 | use cursive::view::View; | 9 | use cursive::view::View; |
10 | use cursive::{Printer, Vec2}; | 10 | use cursive::{Printer, Vec2}; |
11 | use notify::DebouncedEvent; | 11 | use notify::DebouncedEvent; |
@@ -48,23 +48,16 @@ impl View for App { | |||
48 | let grid_width = CONFIGURATION.grid_width; | 48 | let grid_width = CONFIGURATION.grid_width; |
49 | let view_width = CONFIGURATION.view_width; | 49 | let view_width = CONFIGURATION.view_width; |
50 | let view_height = CONFIGURATION.view_height; | 50 | let view_height = CONFIGURATION.view_height; |
51 | let width = { | 51 | let width = grid_width * (view_width + 2); |
52 | if self.habits.len() > 0 { | ||
53 | grid_width * (view_width + 2) | ||
54 | } else { | ||
55 | 0 | ||
56 | } | ||
57 | }; | ||
58 | let height = { | 52 | let height = { |
59 | if self.habits.len() > 0 { | 53 | if self.habits.len() > 0 { |
60 | (view_height as f64 * (self.habits.len() as f64 / grid_width as f64).ceil()) | 54 | (view_height as f64 * (self.habits.len() as f64 / grid_width as f64).ceil()) |
61 | as usize | 55 | as usize |
62 | + 2 // to acoomodate statusline and message line | ||
63 | } else { | 56 | } else { |
64 | 0 | 57 | 0 |
65 | } | 58 | } |
66 | }; | 59 | }; |
67 | Vec2::new(width, height) | 60 | Vec2::new(width, height + 2) |
68 | } | 61 | } |
69 | 62 | ||
70 | fn take_focus(&mut self, _: Direction) -> bool { | 63 | fn take_focus(&mut self, _: Direction) -> bool { |
@@ -89,6 +82,9 @@ impl View for App { | |||
89 | } | 82 | } |
90 | _ => {} | 83 | _ => {} |
91 | }; | 84 | }; |
85 | if self.habits.is_empty() { | ||
86 | return EventResult::Ignored; | ||
87 | } | ||
92 | match e { | 88 | match e { |
93 | Event::Key(Key::Right) | Event::Key(Key::Tab) | Event::Char('l') => { | 89 | Event::Key(Key::Right) | Event::Key(Key::Tab) | Event::Char('l') => { |
94 | self.set_focus(Absolute::Right); | 90 | self.set_focus(Absolute::Right); |
diff --git a/src/app/message.rs b/src/app/message.rs index 34d3293..65f0a5c 100644 --- a/src/app/message.rs +++ b/src/app/message.rs | |||
@@ -17,6 +17,18 @@ impl From<MessageKind> for Color { | |||
17 | } | 17 | } |
18 | } | 18 | } |
19 | 19 | ||
20 | impl<T> From<T> for Message | ||
21 | where | ||
22 | T: AsRef<str>, | ||
23 | { | ||
24 | fn from(item: T) -> Self { | ||
25 | return Message { | ||
26 | msg: item.as_ref().to_string(), | ||
27 | kind: MessageKind::Info, | ||
28 | }; | ||
29 | } | ||
30 | } | ||
31 | |||
20 | pub struct Message { | 32 | pub struct Message { |
21 | msg: String, | 33 | msg: String, |
22 | kind: MessageKind, | 34 | kind: MessageKind, |