Skip to content

Commit bd0ca20

Browse files
authored
fix(cli-repl): support bracketed paste on Windows MONGOSH-1999 (#2338)
Split out into a separate piece because this adds a patch to libuv that has non-trivial downsides, as explained in the referenced PR. I'd assume that mitigating this through a `process.on('exit')` handler is sufficient and that we don't need to plan specifically for e.g. hard crashes of mongosh here, but I didn't want to merge this together with the original work in 4232a98 but rather have it stand on its own (including for the simple reason that it's easier to revert if we decide that we have to).
1 parent 4232a98 commit bd0ca20

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

packages/cli-repl/src/run.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ async function main() {
174174

175175
applyPacProxyS390XPatch();
176176

177+
process.on('exit', () => {
178+
// https://github.com/libuv/libuv/pull/4688
179+
process.stdin?.setRawMode?.(false);
180+
});
181+
177182
// If we are spawned via Windows doubleclick, ask the user for an URI to
178183
// connect to. Allow an environment variable to override this for testing.
179184
isSingleConsoleProcess =
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
diff --git a/deps/uv/src/win/tty.c b/deps/uv/src/win/tty.c
2+
index 7e1f15544b17..37bc2c4ace57 100644
3+
--- a/deps/uv/src/win/tty.c
4+
+++ b/deps/uv/src/win/tty.c
5+
@@ -58,6 +58,9 @@
6+
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
7+
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
8+
#endif
9+
+#ifndef ENABLE_VIRTUAL_TERMINAL_INPUT
10+
+#define ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200
11+
+#endif
12+
13+
#define CURSOR_SIZE_SMALL 25
14+
#define CURSOR_SIZE_LARGE 100
15+
@@ -344,6 +347,7 @@ static void uv__tty_capture_initial_style(
16+
17+
int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
18+
DWORD flags;
19+
+ DWORD try_set_flags;
20+
unsigned char was_reading;
21+
uv_alloc_cb alloc_cb;
22+
uv_read_cb read_cb;
23+
@@ -360,9 +364,11 @@ int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
24+
switch (mode) {
25+
case UV_TTY_MODE_NORMAL:
26+
flags = ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
27+
+ try_set_flags = 0;
28+
break;
29+
case UV_TTY_MODE_RAW:
30+
flags = ENABLE_WINDOW_INPUT;
31+
+ try_set_flags = ENABLE_VIRTUAL_TERMINAL_INPUT;
32+
break;
33+
case UV_TTY_MODE_IO:
34+
return UV_ENOTSUP;
35+
@@ -386,7 +392,10 @@ int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
36+
}
37+
38+
uv_sem_wait(&uv_tty_output_lock);
39+
- if (!SetConsoleMode(tty->handle, flags)) {
40+
+ if (
41+
+ !SetConsoleMode(tty->handle, flags | try_set_flags) &&
42+
+ !SetConsoleMode(tty->handle, flags)
43+
+ ) {
44+
err = uv_translate_sys_error(GetLastError());
45+
uv_sem_post(&uv_tty_output_lock);
46+
return err;

0 commit comments

Comments
 (0)