Skip to content

Commit 715f35d

Browse files
fix(windows): support special key presses in raw mode (#16904)
Co-authored-by: Bartek Iwańczuk <[email protected]>
1 parent 918518b commit 715f35d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

runtime/ops/tty.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ use deno_core::error::custom_error;
1616
use winapi::shared::minwindef::DWORD;
1717
#[cfg(windows)]
1818
use winapi::um::wincon;
19-
#[cfg(windows)]
20-
const RAW_MODE_MASK: DWORD = wincon::ENABLE_LINE_INPUT
21-
| wincon::ENABLE_ECHO_INPUT
22-
| wincon::ENABLE_PROCESSED_INPUT;
2319

2420
#[cfg(windows)]
2521
fn get_windows_handle(
@@ -85,11 +81,16 @@ fn op_stdin_set_raw(
8581
{
8682
return Err(Error::last_os_error().into());
8783
}
84+
85+
const RAW_MODE_MASK: DWORD = wincon::ENABLE_LINE_INPUT
86+
| wincon::ENABLE_ECHO_INPUT
87+
| wincon::ENABLE_PROCESSED_INPUT;
8888
let new_mode = if is_raw {
89-
original_mode & !RAW_MODE_MASK
89+
original_mode & !RAW_MODE_MASK | wincon::ENABLE_VIRTUAL_TERMINAL_INPUT
9090
} else {
91-
original_mode | RAW_MODE_MASK
91+
original_mode | RAW_MODE_MASK & !wincon::ENABLE_VIRTUAL_TERMINAL_INPUT
9292
};
93+
9394
// SAFETY: winapi call
9495
if unsafe { consoleapi::SetConsoleMode(handle, new_mode) } == FALSE {
9596
return Err(Error::last_os_error().into());

0 commit comments

Comments
 (0)