Inquirer.js: `@inquirer/select`: prompt closes after timeout on `CTRL+C` or `CTRL+D`

When terminating the @inquirer/select prompt with CTRL+C or CTRL+D it properly throws the Error User force closed the prompt with 0 null Though, it does so after the timeout searchTimeoutRef is expired.

Example reproduction In this reproduction, try running node index.mjs and stop it with CTRL+C or CTRL+D. To compare the behavior, I also added the index2.mjs which uses @inquirer/input

By debugging the behavior, I noticed that on CTRL+C or CTRL+D, the useKeypress callback is called, the timeout is cleared and then, since the key combination does not match any of the if/else if statements, it enters the else condition. Here the timeout is created again, and after that timeout expires the Error is thrown.

https://github.com/SBoudrias/Inquirer.js/blob/ac687691f6847816e89a80a589e82738bc4c13b0/packages/select/src/index.mts#L124-L142

To address it, the simplest solution would be to change the else statement to an else if checking that it does not match CTRL+C or CTRL+D. Though, other strategies may be used.

Once we agree on a strategy, I am willing to open a PR to address this.

Tested version: @inquirer/select: 2.3.8

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (12 by maintainers)

Most upvoted comments

@matteosacchetto sounds promising to me, let’s try it out đŸ˜„

Interesting… I think a more universal solution would be to modify useKeypress inside the core itself to ignore CTRL+C and CTRL+D (and macOS/linux equivalent.) Otherwise that’ll be a weird edge cases for any prompts forgetting to check for that code.

I wonder if you’d encounter the same issue with a prompt with an async validator? (where there’s a timeout to animate the loading animation.)