aboutsummaryrefslogtreecommitdiff
path: root/src/app/impl_self.rs
diff options
context:
space:
mode:
authornc <[email protected]>2020-07-20 23:30:32 +0100
committernc <[email protected]>2020-07-20 23:30:32 +0100
commit66b2f0793f236dccd3269ae1c3cbfe2293f7fb3d (patch)
tree0e1a2604d9d395bda8d8eaae12353014b6adc836 /src/app/impl_self.rs
parent2a3be003015bac9c6a13549029b9fb4595e88384 (diff)
Add RwLock around messages. Catch SIGINT and print that :q is the way to quit.
Note that this doesn't actually capture Ctrl-C. I'm not sure how it works but termion somehow swollows Ctrl-C so and circumvents the signal handler...
Diffstat (limited to 'src/app/impl_self.rs')
-rw-r--r--src/app/impl_self.rs12
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::*;
5use std::path::PathBuf; 5use std::path::PathBuf;
6use std::sync::mpsc::channel; 6use std::sync::mpsc::channel;
7use std::time::Duration; 7use std::time::Duration;
8use std::sync::{RwLock, Arc};
8 9
9use chrono::Local; 10use chrono::Local;
10use cursive::direction::Absolute; 11use 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 }