diff options
Diffstat (limited to 'src/app/impl_self.rs')
-rw-r--r-- | src/app/impl_self.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 744f906..325c53f 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs | |||
@@ -5,6 +5,7 @@ use std::io::prelude::*; | |||
5 | use std::path::PathBuf; | 5 | use std::path::PathBuf; |
6 | use std::sync::mpsc::channel; | 6 | use std::sync::mpsc::channel; |
7 | use std::time::Duration; | 7 | use std::time::Duration; |
8 | use std::sync::{RwLock, Arc}; | ||
8 | 9 | ||
9 | use chrono::Local; | 10 | use chrono::Local; |
10 | use cursive::direction::Absolute; | 11 | use cursive::direction::Absolute; |
@@ -23,13 +24,14 @@ impl App { | |||
23 | let (tx, rx) = channel(); | 24 | let (tx, rx) = channel(); |
24 | let mut watcher = watcher(tx, Duration::from_secs(1)).unwrap(); | 25 | let mut watcher = watcher(tx, Duration::from_secs(1)).unwrap(); |
25 | watcher.watch(utils::auto_habit_file(), RecursiveMode::Recursive); | 26 | watcher.watch(utils::auto_habit_file(), RecursiveMode::Recursive); |
27 | |||
26 | return App { | 28 | return App { |
27 | habits: vec![], | 29 | habits: vec![], |
28 | focus: 0, | 30 | focus: 0, |
29 | _file_watcher: watcher, | 31 | _file_watcher: watcher, |
30 | file_event_recv: rx, | 32 | file_event_recv: rx, |
31 | view_month_offset: 0, | 33 | view_month_offset: 0, |
32 | message: "Type :add <habit-name> <goal> to get started, Ctrl-L to dismiss".into(), | 34 | message: Arc::new(RwLock::new("Type :add <habit-name> <goal> to get started, Ctrl-L to dismiss".into())), |
33 | }; | 35 | }; |
34 | } | 36 | } |
35 | 37 | ||
@@ -41,7 +43,7 @@ impl App { | |||
41 | let old_len = self.habits.len(); | 43 | let old_len = self.habits.len(); |
42 | self.habits.retain(|h| h.name() != name); | 44 | self.habits.retain(|h| h.name() != name); |
43 | if old_len == self.habits.len() { | 45 | if old_len == self.habits.len() { |
44 | self.message | 46 | self.message.write().unwrap() |
45 | .set_message(format!("Could not delete habit `{}`", name)) | 47 | .set_message(format!("Could not delete habit `{}`", name)) |
46 | } | 48 | } |
47 | } | 49 | } |
@@ -114,7 +116,7 @@ impl App { | |||
114 | } | 116 | } |
115 | 117 | ||
116 | pub fn clear_message(&mut self) { | 118 | pub fn clear_message(&mut self) { |
117 | self.message.clear(); | 119 | self.message.write().unwrap().clear(); |
118 | } | 120 | } |
119 | 121 | ||
120 | pub fn status(&self) -> StatusLine { | 122 | pub fn status(&self) -> StatusLine { |
@@ -236,8 +238,8 @@ impl App { | |||
236 | Command::Blank => {} | 238 | Command::Blank => {} |
237 | }, | 239 | }, |
238 | Err(e) => { | 240 | Err(e) => { |
239 | self.message.set_message(e.to_string()); | 241 | self.message.write().unwrap().set_message(e.to_string()); |
240 | self.message.set_kind(MessageKind::Error); | 242 | self.message.write().unwrap().set_kind(MessageKind::Error); |
241 | } | 243 | } |
242 | } | 244 | } |
243 | } | 245 | } |