Ctrl+C handling (#75)
As stated [here](https://doc.rust-lang.org/std/io/trait.BufRead.html#errors-1), `read_until` (and `read_line`) ignore Ctrl+C, so Topgrade does not respond to Ctrl+C in the retry prompt, and instead will exit only when enter is pressed after Ctrl+C. This is undesirable, so this pull request is a WIP until we find a solution.
This commit is contained in:
committed by
GitHub
parent
41621bd08f
commit
a6b6b7aa4e
29
src/ctrlc/unix.rs
Normal file
29
src/ctrlc/unix.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use nix::sys::signal;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
lazy_static! {
|
||||
static ref RUNNING: AtomicBool = AtomicBool::new(true);
|
||||
}
|
||||
|
||||
pub fn running() -> bool {
|
||||
RUNNING.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
pub fn set_running(value: bool) {
|
||||
RUNNING.store(value, Ordering::SeqCst)
|
||||
}
|
||||
|
||||
extern "C" fn handle_sigint(_: i32) {
|
||||
set_running(false);
|
||||
}
|
||||
|
||||
pub fn set_handler() {
|
||||
let sig_action = signal::SigAction::new(
|
||||
signal::SigHandler::Handler(handle_sigint),
|
||||
signal::SaFlags::empty(),
|
||||
signal::SigSet::empty(),
|
||||
);
|
||||
unsafe {
|
||||
signal::sigaction(signal::SIGINT, &sig_action).unwrap();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user