summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2020-02-04 01:10:14 +0200
committerManos Pitsidianakis <el13635@mail.ntua.gr>2020-10-01 18:57:52 +0300
commitafccc17e8df178ab2ea3db80fbb020c0225a22fa (patch)
tree72e4e48ef9072a8bb2f3eef2b742b0e4e5cd5456
parentb6de185d6b8f911c206a65755d8d21cf58bc4e83 (diff)
Add ^\ -> SIGQUIT handler
-rw-r--r--src/main.rs22
-rw-r--r--src/terminal/keys.rs12
2 files changed, 19 insertions, 15 deletions
diff --git a/src/main.rs b/src/main.rs
index 07a5b4a..167e3fb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -141,17 +141,25 @@ fn notify(
state: Arc<AtomicPtr<StateStdout>>,
) -> Result<crossbeam::channel::Receiver<c_int>, Error> {
let (s, r) = bounded(100);
- let _s = s.clone();
- let sigint_handler = move |_info: &nix::libc::siginfo_t| {
- if exit_flag.load(std::sync::atomic::Ordering::SeqCst) {
- crate::state::restore_to_main_screen(state.clone());
- std::process::exit(130);
+ let sigint_handler = {
+ let s = s.clone();
+ let state = state.clone();
+ move |_info: &nix::libc::siginfo_t| {
+ if exit_flag.load(std::sync::atomic::Ordering::SeqCst) {
+ crate::state::restore_to_main_screen(state.clone());
+ std::process::exit(130);
+ }
+ exit_flag.store(true, std::sync::atomic::Ordering::SeqCst);
+ let _ = s.send(signal_hook::SIGINT);
}
- exit_flag.store(true, std::sync::atomic::Ordering::SeqCst);
- let _ = _s.send(signal_hook::SIGINT);
+ };
+ let sigquit_handler = move |_info: &nix::libc::siginfo_t| {
+ crate::state::restore_to_main_screen(state.clone());
+ std::process::exit(131);
};
unsafe {
signal_hook_registry::register_sigaction(signal_hook::SIGINT, sigint_handler)?;
+ signal_hook_registry::register_sigaction(signal_hook::SIGQUIT, sigquit_handler)?;
}
let signals = signal_hook::iterator::Signals::new(signals)?;
std::thread::spawn(move || {
diff --git a/src/terminal/keys.rs b/src/terminal/keys.rs
index 43e8d7d..9212451 100644
--- a/src/terminal/keys.rs
+++ b/src/terminal/keys.rs
@@ -142,14 +142,6 @@ enum InputMode {
Paste,
}
-/*
- * If we fork (for example start $EDITOR) we want the input-thread to stop reading from stdin. The
- * best way I came up with right now is to send a signal to the thread that is read in the first
- * input in stdin after the fork, and then the thread kills itself. The parent process spawns a new
- * input-thread when the child returns.
- *
- * The main loop uses try_wait_on_child() to check if child has exited.
- */
pub fn get_events(
stdin: io::Stdin,
mut closure: impl FnMut(Key),
@@ -169,6 +161,10 @@ pub fn get_events(
let self_pid = nix::unistd::Pid::this();
nix::sys::signal::kill(self_pid, nix::sys::signal::Signal::SIGINT).unwrap();
}
+ Ok(TermionEvent::Key(TermionKey::Ctrl('4'))) if input_mode == InputMode::Normal => {
+ let self_pid = nix::unistd::Pid::this();
+ nix::sys::signal::kill(self_pid, nix::sys::signal::Signal::SIGQUIT).unwrap();
+ }
Ok(TermionEvent::Key(k)) if input_mode == InputMode::Normal => {
closure(Key::from(k));
}