thebaselab / codeapp

Building a full-fledged code editor for iPad
https://code.thebaselab.com
MIT License
2.68k stars 178 forks source link

Readline not working as expected in NodeJS #1072

Open mzoliker opened 2 weeks ago

mzoliker commented 2 weeks ago

Hi! First, many thanks for supporting process.stdin in nodejs! This was really a feature I was waiting for! :-)

Please note that the sample code below does not work as expected though, as the program hangs (waiting for further input) and does not exit after input as it should. rl.close() should indeed close the interface and let the program close.

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
rl.question('Username: ', user => {
  console.log(`Hello ${user}`);
  rl.close();
});

Kind regards, Maurice

bummoblizard commented 2 weeks ago

Thanks for testing the feature! I can confirm this issue and will look into it. As a workaround, it is possible to end the program by pressing command-c on the keyboard (or its button).

Update: Not quite sure what caused this but another workaround I found is setTimeout(() => {rl.close()}).