From 715f35d635bf5a4e972238e6ac8d290c0e096083 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 5 Dec 2022 09:46:04 -0500 Subject: [PATCH] fix(windows): support special key presses in raw mode (#16904) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartek IwaƄczuk --- runtime/ops/tty.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/runtime/ops/tty.rs b/runtime/ops/tty.rs index 6382f967fc..f807889051 100644 --- a/runtime/ops/tty.rs +++ b/runtime/ops/tty.rs @@ -16,10 +16,6 @@ use deno_core::error::custom_error; use winapi::shared::minwindef::DWORD; #[cfg(windows)] use winapi::um::wincon; -#[cfg(windows)] -const RAW_MODE_MASK: DWORD = wincon::ENABLE_LINE_INPUT - | wincon::ENABLE_ECHO_INPUT - | wincon::ENABLE_PROCESSED_INPUT; #[cfg(windows)] fn get_windows_handle( @@ -85,11 +81,16 @@ fn op_stdin_set_raw( { return Err(Error::last_os_error().into()); } + + const RAW_MODE_MASK: DWORD = wincon::ENABLE_LINE_INPUT + | wincon::ENABLE_ECHO_INPUT + | wincon::ENABLE_PROCESSED_INPUT; let new_mode = if is_raw { - original_mode & !RAW_MODE_MASK + original_mode & !RAW_MODE_MASK | wincon::ENABLE_VIRTUAL_TERMINAL_INPUT } else { - original_mode | RAW_MODE_MASK + original_mode | RAW_MODE_MASK & !wincon::ENABLE_VIRTUAL_TERMINAL_INPUT }; + // SAFETY: winapi call if unsafe { consoleapi::SetConsoleMode(handle, new_mode) } == FALSE { return Err(Error::last_os_error().into());