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/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index d96119e..ca1b653 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,8 +50,15 @@ 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 || { + std::fs::File::create("killed").unwrap(); + m.write().unwrap().set_message("Use the :q command to quit"); + }) }.unwrap(); + + let mut s = termion().unwrap(); + let layout = NamedView::new( "Frame", LinearLayout::vertical().child(NamedView::new("Main", app)), -- cgit v1.2.3 From 19de1653985520258bd081e32275c48e2ac98f5b Mon Sep 17 00:00:00 2001 From: nc Date: Mon, 20 Jul 2020 18:44:31 -0400 Subject: remove debug code, add cargo.lock --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index ca1b653..d733f97 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,7 +53,6 @@ fn main() { let app = App::load_state(); let m = app.message.clone(); unsafe { signal_hook::register(signal_hook::SIGINT, move || { - std::fs::File::create("killed").unwrap(); m.write().unwrap().set_message("Use the :q command to quit"); }) }.unwrap(); @@ -67,6 +66,7 @@ fn main() { s.add_global_callback(':', |s| open_command_window(s)); s.set_theme(theme::theme_gen()); + s.run(); } } -- cgit v1.2.3 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. --- src/main.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/main.rs') 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 From 976ea0282d373c4d08187a78a7b46a09d66f7918 Mon Sep 17 00:00:00 2001 From: nc Date: Wed, 5 Aug 2020 23:56:06 -0400 Subject: revert --- src/main.rs | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 3ec964a..d96119e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,10 +52,6 @@ fn main() { } else { let mut s = termion().unwrap(); let app = App::load_state(); - - // 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", LinearLayout::vertical().child(NamedView::new("Main", app)), -- cgit v1.2.3 From 9777930868591abdf4a533e4059cc4fd08898521 Mon Sep 17 00:00:00 2001 From: nc Date: Wed, 5 Aug 2020 23:59:40 -0400 Subject: include only minimal code changes to add ctrl-c capturing functionality --- src/main.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index d96119e..3ec964a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,6 +52,10 @@ fn main() { } else { let mut s = termion().unwrap(); let app = App::load_state(); + + // 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", LinearLayout::vertical().child(NamedView::new("Main", app)), -- cgit v1.2.3 From 78685f7cdca15a191a5d086321368e475b0c2ab2 Mon Sep 17 00:00:00 2001 From: nc Date: Thu, 6 Aug 2020 14:51:26 -0400 Subject: Revert "include only minimal code changes to add ctrl-c capturing functionality" This reverts commit 9777930868591abdf4a533e4059cc4fd08898521. --- src/main.rs | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 3ec964a..d96119e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,10 +52,6 @@ fn main() { } else { let mut s = termion().unwrap(); let app = App::load_state(); - - // 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", LinearLayout::vertical().child(NamedView::new("Main", app)), -- cgit v1.2.3 From 92b4ecd7006f68f87dff3130b85c00dddacead85 Mon Sep 17 00:00:00 2001 From: nc Date: Sat, 8 Aug 2020 10:09:52 -0400 Subject: try to unconditionally save after s.run() completes --- src/main.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index d96119e..1d9efb4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,5 +61,12 @@ fn main() { s.set_theme(theme::theme_gen()); s.run(); + + let app = std::rc::Rc::try_unwrap(s.find_name::>("Main").unwrap() + .get_mut() + .into_owner() + .into_owner()).ok().unwrap().into_inner(); + app.save_state(); + } } -- cgit v1.2.3 From 62158c5f142a1838b030c0583c9467a3cb46358b Mon Sep 17 00:00:00 2001 From: nc Date: Sat, 8 Aug 2020 12:47:08 -0400 Subject: use call_on_name which works and is simpler --- src/main.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 1d9efb4..14ddf03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,11 +62,6 @@ fn main() { s.set_theme(theme::theme_gen()); s.run(); - let app = std::rc::Rc::try_unwrap(s.find_name::>("Main").unwrap() - .get_mut() - .into_owner() - .into_owner()).ok().unwrap().into_inner(); - app.save_state(); - + s.call_on_name("Main", |app: &mut App| app.save_state()); } } -- cgit v1.2.3