Skip to content

Commit db2aae8

Browse files
authored
tty: use terminal VT mode on Windows
As of 0315283, the libuv `UV_TTY_MODE_RAW_VT` flag is available for applications on Windows in order to have the terminal itself translate keypresses into control sequences, rather than libuv. This aligns the TTY setup more closely with POSIX platforms, and enables handling of control sequences in applications which libuv is not able to emit at all. Since the Node.js `readline` implementation already handles divergences between different control character sequences for the same keypresses (e.g. `<ESC>[[A` vs `<ESC>OP` for the F1 key), this should not present a visible change for typical Node.js TTY applications. Testing is handled on the libuv side, and not easily feasible with Node.js’s current TTY test setup. PR-URL: #58358 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
1 parent 61aecf2 commit db2aae8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/tty_wrap.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,17 @@ void TTYWrap::SetRawMode(const FunctionCallbackInfo<Value>& args) {
116116
TTYWrap* wrap;
117117
ASSIGN_OR_RETURN_UNWRAP(
118118
&wrap, args.This(), args.GetReturnValue().Set(UV_EBADF));
119-
int err = uv_tty_set_mode(&wrap->handle_, args[0]->IsTrue());
119+
// UV_TTY_MODE_RAW_VT is a variant of UV_TTY_MODE_RAW that
120+
// enables control sequence processing on the TTY implementer side,
121+
// rather than having libuv translate keypress events into
122+
// control sequences, aligning behavior more closely with
123+
// POSIX platforms. This is also required to support some control
124+
// sequences at all on Windows, such as bracketed paste mode.
125+
// The Node.js readline implementation handles differences between
126+
// these modes.
127+
int err = uv_tty_set_mode(
128+
&wrap->handle_,
129+
args[0]->IsTrue() ? UV_TTY_MODE_RAW_VT : UV_TTY_MODE_NORMAL);
120130
args.GetReturnValue().Set(err);
121131
}
122132

0 commit comments

Comments
 (0)