From a947c6fbf7c71544687c79716eadbffe4bdedc82 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Wed, 29 May 2024 09:53:04 -0700 Subject: fix(ext/node): windows cancel stdin read in line mode (#23969) This patch fixes stdin read hanging on user input when switching tty mode on Windows Fixes #21111 On Windows, when switching from line to raw mode: - Cancel ongoing console read by writing a return keypress to its input buffer. This blocks the main thread until any ongoing read has been cancelled to prevent interference with the screen state. - On the read thread, restore the cursor position to where it was before writing the enter, undoing its effect on the screen state. - Restart reading and notify the main thread. --- tests/testdata/run/process_stdin_unblock.mjs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/testdata/run/process_stdin_unblock.mjs (limited to 'tests/testdata') diff --git a/tests/testdata/run/process_stdin_unblock.mjs b/tests/testdata/run/process_stdin_unblock.mjs new file mode 100644 index 000000000..bbeea2afb --- /dev/null +++ b/tests/testdata/run/process_stdin_unblock.mjs @@ -0,0 +1,21 @@ +import process from "node:process"; + +function prompt() { + process.stdin.setRawMode(true); + + const { promise, resolve } = Promise.withResolvers(); + + const onData = (buf) => { + process.stdin.setRawMode(false); + process.stdin.removeListener("data", onData); + console.log(buf.length); + resolve(); + }; + + process.stdin.on("data", onData); + return promise; +} + +await prompt(); +await prompt(); +Deno.exit(0); -- cgit v1.2.3