nushell/src/signals.rs
Hofer-Julian 24aa1f312a
Cleanup of src/main.rs (#7801)
While reading nushell's code, I've started to clean up `src/main.rs` a
bit.
The description of the changes can be found in the commit messages.
2023-01-20 10:44:49 -08:00

30 lines
877 B
Rust

use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
use nu_protocol::engine::EngineState;
pub(crate) fn ctrlc_protection(engine_state: &mut EngineState, ctrlc: &Arc<AtomicBool>) {
let handler_ctrlc = ctrlc.clone();
let engine_state_ctrlc = ctrlc.clone();
ctrlc::set_handler(move || {
handler_ctrlc.store(true, Ordering::SeqCst);
})
.expect("Error setting Ctrl-C handler");
engine_state.ctrlc = Some(engine_state_ctrlc);
}
#[cfg(not(windows))]
pub(crate) fn sigquit_protection(engine_state: &mut EngineState) {
use signal_hook::consts::SIGQUIT;
let sig_quit = Arc::new(AtomicBool::new(false));
signal_hook::flag::register(SIGQUIT, sig_quit.clone()).expect("Error setting SIGQUIT flag");
engine_state.set_sig_quit(sig_quit);
}
#[cfg(windows)]
pub(crate) fn sigquit_protection(_engine_state: &mut EngineState) {}