From 5a709a2dbf3894dd54689dc2c841e06e12152abb Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 25 Sep 2025 18:58:44 -0800 Subject: [PATCH] node:tty: use terminal VT mode on Windows (#21161) mirrors: https://github.com/nodejs/node/pull/58358 --- src/deps/libuv.zig | 1 + src/io/source.zig | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/deps/libuv.zig b/src/deps/libuv.zig index e3b1837f1b..5a59f777ce 100644 --- a/src/deps/libuv.zig +++ b/src/deps/libuv.zig @@ -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 { diff --git a/src/io/source.zig b/src/io/source.zig index 647c5a8165..aeff0ca5bb 100644 --- a/src/io/source.zig +++ b/src/io/source.zig @@ -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;