spinner breaks readline loop
jschuur opened this issue · 2 comments
jschuur commented
I'm building a small REPL with readline that runs an async function between prompts and when I show a spinner when the async function runs, this seems to break the loop.
Full CodeSandbox repo, but here's the key parts:
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
async function processPrompt(input) {
const spinner = ora(`Thinking (${input}) ...`).start();
await sleep(1000);
spinner.succeed("Response in 1.2s");
}
(async () => {
rl.setPrompt('> ');
for await (const input of rl) {
if (input.startsWith("!")) {
await runCommand(input.slice(1));
} else {
await processPrompt(input);
}
}
rl.on("close", function () {
console.log("See you later!");
process.exit(0);
});
})();
The version without a spinner behaves as expected, but the spinner version simply ends after the first loop. I expected it to continuously wait for a new prompt and run that through the async function again.
Perhaps related to this is that I don't see my >
prompt (and I don't user rl.prompt()
, because the above for await (const input of rl)
is how I've seen endless loops documented).
cyyyu commented
I had the same issue in my app. discardStdin: false
works for me.