node:tty: use terminal VT mode on Windows (#21161)

mirrors: https://github.com/nodejs/node/pull/58358
This commit is contained in:
Meghan Denny
2025-09-25 18:58:44 -08:00
committed by GitHub
parent 51ce3bc269
commit 5a709a2dbf
2 changed files with 6 additions and 1 deletions

View File

@@ -1471,6 +1471,7 @@ pub const struct_uv_tty_s = extern struct {
normal = 0,
raw = 1,
io = 2,
vt = 3,
};
pub fn setMode(this: *uv_tty_t, mode: Mode) ReturnCode {

View File

@@ -224,7 +224,11 @@ export fn Source__setRawModeStdin(raw: bool) c_int {
.result => |tty| tty,
.err => |e| return e.errno,
};
if (tty.setMode(if (raw) .raw else .normal).toError(.uv_tty_set_mode)) |err| {
// UV_TTY_MODE_RAW_VT is a variant of UV_TTY_MODE_RAW that enables control sequence processing on the TTY implementer side,
// rather than having libuv translate keypress events into control sequences, aligning behavior more closely with
// POSIX platforms. This is also required to support some control sequences at all on Windows, such as bracketed paste mode.
// The Node.js readline implementation handles differences between these modes.
if (tty.setMode(if (raw) .vt else .normal).toError(.uv_tty_set_mode)) |err| {
return err.errno;
}
return 0;