From 66b2f0793f236dccd3269ae1c3cbfe2293f7fb3d Mon Sep 17 00:00:00 2001 From: nc Date: Mon, 20 Jul 2020 18:30:32 -0400 Subject: 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... --- src/app/impl_self.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/app/impl_self.rs') 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::*; use std::path::PathBuf; use std::sync::mpsc::channel; use std::time::Duration; +use std::sync::{RwLock, Arc}; use chrono::Local; use cursive::direction::Absolute; @@ -23,13 +24,14 @@ impl App { let (tx, rx) = channel(); let mut watcher = watcher(tx, Duration::from_secs(1)).unwrap(); watcher.watch(utils::auto_habit_file(), RecursiveMode::Recursive); + return App { habits: vec![], focus: 0, _file_watcher: watcher, file_event_recv: rx, view_month_offset: 0, - message: "Type :add to get started, Ctrl-L to dismiss".into(), + message: Arc::new(RwLock::new("Type :add to get started, Ctrl-L to dismiss".into())), }; } @@ -41,7 +43,7 @@ impl App { let old_len = self.habits.len(); self.habits.retain(|h| h.name() != name); if old_len == self.habits.len() { - self.message + self.message.write().unwrap() .set_message(format!("Could not delete habit `{}`", name)) } } @@ -114,7 +116,7 @@ impl App { } pub fn clear_message(&mut self) { - self.message.clear(); + self.message.write().unwrap().clear(); } pub fn status(&self) -> StatusLine { @@ -236,8 +238,8 @@ impl App { Command::Blank => {} }, Err(e) => { - self.message.set_message(e.to_string()); - self.message.set_kind(MessageKind::Error); + self.message.write().unwrap().set_message(e.to_string()); + self.message.write().unwrap().set_kind(MessageKind::Error); } } } -- cgit v1.2.3