Files
topgrade/src/ctrlc/windows.rs

22 lines
567 B
Rust
Raw Normal View History

2018-12-31 14:07:55 +02:00
//! A stub for Ctrl + C handling.
use crate::ctrlc::interrupted::set_interrupted;
use tracing::error;
use windows::core::BOOL;
use windows::Win32::System::Console::{SetConsoleCtrlHandler, CTRL_C_EVENT};
2018-12-31 14:07:55 +02:00
extern "system" fn handler(ctrl_type: u32) -> BOOL {
match ctrl_type {
CTRL_C_EVENT => {
set_interrupted();
true.into()
}
_ => false.into(),
}
}
pub fn set_handler() {
if let Err(e) = unsafe { SetConsoleCtrlHandler(Some(handler), true) } {
error!("Cannot set a control C handler: {e}")
}
}