You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Or maybe just provide a method to enable/disable the SIGINT signal and just treat it as other keyboard events. Currently pressing Ctrl+C in a windows terminal immediately terminates the process, making for example a feature similar to nodejs' press Ctrl+C twice to exit.
Below my failed attempt to come up with a PR for this:
use the SetConsoleMode function to disable the ENABLE_PROCESSED_INPUT flag or
call SetConsoleCtrlHandler with NULL and True as arguments.
For option 1:
RawModeCommand seems to be where we should look
pub struct RawModeCommand {
mask: DWORD,
}
use self::wincon::{ENABLE_LINE_INPUT, ENABLE_WRAP_AT_EOL_OUTPUT};
impl RawModeCommand {
pub fn new() -> Self {
RawModeCommand {
mask: ENABLE_WRAP_AT_EOL_OUTPUT | ENABLE_LINE_INPUT,
}
}
}
impl RawModeCommand {
/// Enables raw mode.
pub fn enable(&mut self) -> io::Result<()> {
let console_mode = ConsoleMode::new()?;
let dw_mode = console_mode.mode()?;
let new_mode = dw_mode & !self.mask;
console_mode.set_mode(new_mode)?;
Ok(())
}
/// Disables raw mode.
pub fn disable(&self) -> io::Result<()> {
let console_mode = ConsoleMode::new()?;
let dw_mode = console_mode.mode()?;
let new_mode = dw_mode | self.mask;
console_mode.set_mode(new_mode)?;
return Ok(());
}
}
Disabling ENABLE_PROCESS_INPUT 0x0001 will not work because the handle needs to be an input handle and not a output handle as is the case each time a ConsoleMode instance is created.
A note: ENABLE_LINE_INPUT and ENABLE_WRAP_AT_EOL_OUTPUT are both 0x0002 and so mask: ENABLE_WRAP_AT_EOL_OUTPUT | ENABLE_LINE_INPUT, could be just mask: ENABLE_WRAP_AT_EOL_OUTPUT,
SetConsoleCtrlHandler takes as arguments an Option type and an i32 and should be set to NULL and true respectively. Creating a method for ConsoleMode such as:
pub fn set_ctrl_handler(&self) { unsafe { SetConsoleCtrlHandler(None, 1); } }
and calling it on initialization does not work as well.
The text was updated successfully, but these errors were encountered:
Or maybe just provide a method to enable/disable the SIGINT signal and just treat it as other keyboard events. Currently pressing Ctrl+C in a windows terminal immediately terminates the process, making for example a feature similar to nodejs' press Ctrl+C twice to exit.
Below my failed attempt to come up with a PR for this:
By following the CTRL+C and CTRL+BREAK Signals in widows console documentation, it appears that one should:
For option 1:
RawModeCommand seems to be where we should look
Disabling
ENABLE_PROCESS_INPUT 0x0001
will not work because the handle needs to be an input handle and not a output handle as is the case each time aConsoleMode
instance is created.A note:
ENABLE_LINE_INPUT
andENABLE_WRAP_AT_EOL_OUTPUT
are both0x0002
and somask: ENABLE_WRAP_AT_EOL_OUTPUT | ENABLE_LINE_INPUT,
could be justmask: ENABLE_WRAP_AT_EOL_OUTPUT,
pub fn set_ctrl_handler(&self) { unsafe { SetConsoleCtrlHandler(None, 1); } }
and calling it on initialization does not work as well.
The text was updated successfully, but these errors were encountered: