-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
create-next-app prompts don't work on Windows #21111
Comments
@dsherret I can't reproduce on Windows, does it still happen? |
@littledivy yes. It happens after accepting the first prompt: |
Maybe try in vscode terminal with powershell. |
Can reproduce. The selection is actually happening but not displayed until you hit Enter. Recording.2024-03-29.094257.mp4 |
Simpler repro: import EventEmitter from "node:events";
import readline from "node:readline";
import process from "node:process";
function prompt() {
const rl = readline.createInterface({
input: process.stdin,
});
readline.emitKeypressEvents(process.stdin, rl);
process.stdin.setRawMode(true);
const { promise, resolve } = Promise.withResolvers();
const keypress = (str, key) => {
process.stdin.setRawMode(false);
rl.close();
process.stdin.removeListener('keypress', keypress)
console.log({ str, key })
resolve()
};
process.stdin.on('keypress', keypress);
return promise;
}
await prompt();
await prompt(); |
Repro using only 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);
resolve();
};
process.stdin.on("data", onData);
return promise;
}
await prompt();
await prompt(); |
Ok, I think this is the same issue as described in this old libuv PR: libuv/libuv#866 We need to unblock the stdin read thread when the stream is cancelled. libuv sends a Enter key to the input buffer to unblock the read and restores it back, we can do something similar. We could also try using cancel handle. |
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.
It's not possibe to change the selection from yes to no:
The text was updated successfully, but these errors were encountered: