mirror of
https://github.com/denoland/deno.git
synced 2024-11-30 16:40:57 -05:00
a947c6fbf7
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.
21 lines
417 B
JavaScript
21 lines
417 B
JavaScript
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);
|