Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli-repl): support bracketed paste on Windows MONGOSH-1999 #2338

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/cli-repl/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ async function main() {

applyPacProxyS390XPatch();

process.on('exit', () => {
// https://github.com/libuv/libuv/pull/4688
process.stdin?.setRawMode?.(false);
});

// If we are spawned via Windows doubleclick, ask the user for an URI to
// connect to. Allow an environment variable to override this for testing.
isSingleConsoleProcess =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
diff --git a/deps/uv/src/win/tty.c b/deps/uv/src/win/tty.c
index 7e1f15544b17..37bc2c4ace57 100644
--- a/deps/uv/src/win/tty.c
+++ b/deps/uv/src/win/tty.c
@@ -58,6 +58,9 @@
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
#endif
+#ifndef ENABLE_VIRTUAL_TERMINAL_INPUT
+#define ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the significance of the 0x0200 value? is it just an available value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can look up the values here: https://learn.microsoft.com/en-us/windows/console/setconsolemode#parameters

This #define, like the one above, is added in case the compilation happens on a Windows machine that doesn't have the most recent system headers and doesn't know about the flag yet, so you can still compile a program that can make use of it when run on more recent Windows machines.

That's not a practical concern for mongosh, but for the libuv PR it's relevant.

+#endif

#define CURSOR_SIZE_SMALL 25
#define CURSOR_SIZE_LARGE 100
@@ -344,6 +347,7 @@ static void uv__tty_capture_initial_style(

int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
DWORD flags;
+ DWORD try_set_flags;
unsigned char was_reading;
uv_alloc_cb alloc_cb;
uv_read_cb read_cb;
@@ -360,9 +364,11 @@ int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
switch (mode) {
case UV_TTY_MODE_NORMAL:
flags = ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
+ try_set_flags = 0;
break;
case UV_TTY_MODE_RAW:
flags = ENABLE_WINDOW_INPUT;
+ try_set_flags = ENABLE_VIRTUAL_TERMINAL_INPUT;
break;
case UV_TTY_MODE_IO:
return UV_ENOTSUP;
@@ -386,7 +392,10 @@ int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
}

uv_sem_wait(&uv_tty_output_lock);
- if (!SetConsoleMode(tty->handle, flags)) {
+ if (
+ !SetConsoleMode(tty->handle, flags | try_set_flags) &&
+ !SetConsoleMode(tty->handle, flags)
+ ) {
err = uv_translate_sys_error(GetLastError());
uv_sem_post(&uv_tty_output_lock);
return err;