WebStorm: readline() doesn't close after input

I'm taking input from terminal using the following code:

```

const readline = require('readline')
const rl = readline.createInterface({input: process.stdin, output: process.stdout});

...

rl.question("Enter your move: ", userInput => {
proposedMove = userInput.trim() + '';
rl.close();
})

```

The problem is, after I type in the input and hit enter, readline interface doesn't close. I basically end up stuck in perpetual input mode and can only Ctrl-C out of it. 

The exact same code works ok in normal terminal.

I tried searching for the "Use Console Input" option, which I've seen mentioned on the forums - but I can't find it. Seems like it was removed?

Any advice greatly appreciated!

4 comments
Comment actions Permalink

Can't reproduce the issue using your example... So just a guess: are you using Node.js run configuration to run your scripts? by default, Node console in WebStorm is non-Tty, as node process is started with input/output streams redirection.
You can work out the issue by enabling using terminal console for Node.js. To do this, please try the following:

  • choose Help | Find Action... on the main menu;
  • type registry... to locate the Registry
  • find nodejs.console.use.terminal key there and enable it.
0
Comment actions Permalink

Ok I thought it works but it creates a new issue - now in debugger window I can't enter any input at all... the prompt is there blinking, but I can't enter anything.

To add some detail: it works ok when there's no breakpoint. As soon as I have a breakpoint anywhere in the code it prevents me from entering any input. In fact it somehow magically jumps past the input phase and goes straight to the breakpoint..

Exactly same issue with the Inquirer module - https://www.npmjs.com/package/inquirer

Here's the file if you want to play with it -  https://github.com/ilmoi/TheOdinProject/blob/main/Javascript/Project%20TicTacToe/TicTacToe.js

Lines 54-72

0
Comment actions Permalink

Works fine for me

What window are you trying to enter text in - Console or Debugger Console? what are your IDE and Node.js versions?

0
Comment actions Permalink

Nevermind... my incompetent coding is at fault.

The problem turned out to be that prompt input actually returns a promise, and I wasn't handling it appropriately. Of course the flow runs away and I can't enter anything anymore...

Hope this helps the next incompetent coder who reads this:)

Note: everything works ok WITH the settings Elena proposed above.

1

Please sign in to leave a comment.