From ee9be05579d87ca99f153d20995af3273385b564 Mon Sep 17 00:00:00 2001 From: nc Date: Wed, 5 Aug 2020 22:08:51 -0400 Subject: Override Ctrl-C by disabling callback in Cursive Thanks to @gyscos for the explanation in #22! Also removed extraneous code that's no longer needed. --- Cargo.lock | 1 - Cargo.toml | 1 - src/app/impl_self.rs | 1 - src/app/impl_view.rs | 3 ++- src/main.rs | 9 +++------ 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5075c64..ade0cc4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -271,7 +271,6 @@ dependencies = [ "notify", "serde", "serde_json", - "signal-hook", "typetag", ] diff --git a/Cargo.toml b/Cargo.toml index c97e2a4..9cf3639 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,6 @@ typetag = "0.1.4" directories = "3.0.1" clap = "2.33" notify = "4.0" -signal-hook = "0.1.16" [dependencies.cursive] version = "0.15" diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 325c53f..c2a24cf 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -24,7 +24,6 @@ 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, diff --git a/src/app/impl_view.rs b/src/app/impl_view.rs index b735003..1261208 100644 --- a/src/app/impl_view.rs +++ b/src/app/impl_view.rs @@ -85,6 +85,7 @@ impl View for App { if self.habits.is_empty() { return EventResult::Ignored; } + let m = self.message.clone(); match e { Event::Key(Key::Right) | Event::Key(Key::Tab) | Event::Char('l') => { self.set_focus(Absolute::Right); @@ -166,7 +167,7 @@ impl View for App { return EventResult::Consumed(None); } Event::CtrlChar('c') => { - self.message.write().unwrap().set_message("Use the :q command to quit"); + m.write().unwrap().set_message("Use the :q command to quit"); return EventResult::Consumed(None); } diff --git a/src/main.rs b/src/main.rs index d733f97..3ec964a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,13 +50,11 @@ fn main() { ), } } else { + let mut s = termion().unwrap(); let app = App::load_state(); - let m = app.message.clone(); - unsafe { signal_hook::register(signal_hook::SIGINT, move || { - m.write().unwrap().set_message("Use the :q command to quit"); - }) }.unwrap(); - let mut s = termion().unwrap(); + // prevent Ctrl-C from killing the app and allow the app to override it. + s.clear_global_callbacks(cursive::event::Event::CtrlChar('c')); let layout = NamedView::new( "Frame", @@ -66,7 +64,6 @@ fn main() { s.add_global_callback(':', |s| open_command_window(s)); s.set_theme(theme::theme_gen()); - s.run(); } } -- cgit v1.2.3