Exit immediately when Ctrl-C has been pressed twice

This commit is contained in:
sharkdp 2019-09-15 13:05:53 +02:00
parent 3599a30ee2
commit 2545aaabd2

View file

@ -110,7 +110,12 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) -
if config.ls_colors.is_some() && config.command.is_none() {
let wq = Arc::clone(&wants_to_quit);
ctrlc::set_handler(move || {
wq.store(true, Ordering::Relaxed);
if wq.load(Ordering::Relaxed) {
// Ctrl-C has been pressed twice, exit NOW
process::exit(ExitCode::KilledBySigint.into());
} else {
wq.store(true, Ordering::Relaxed);
}
})
.unwrap();
}