oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
72.82k stars 2.64k forks source link

control + c (`^c`) doesn't exit inquirer interactive prompt #6592

Open xavdid opened 10 months ago

xavdid commented 10 months ago

What version of Bun is running?

1.0.6+969da088f5db3258a803ec186012e30f992829b4

What platform is your computer?

Darwin 22.6.0 arm64 arm

What steps can reproduce the bug?

  1. run bun add @inquirer/prompts
  2. paste the following demo script into index.js:
import { input } from '@inquirer/prompts';

const answer = await input({ message: 'Enter your name' });
  1. run bun run index.js
  2. press ctrl + c to exit the program

What is the expected behavior?

ctrl + c exits the program, probably with an error. This is what happens with node index.js:

node index.js
? Enter your name
file:///Users/david/projects/linear-adder/node_modules/@inquirer/core/dist/esm/lib/create-prompt.mjs:36
                    reject(new Error(`User force closed the prompt with ${code} ${signal}`));
                           ^

Error: User force closed the prompt with 0 null
    at file:///Users/david/projects/linear-adder/node_modules/@inquirer/core/dist/esm/lib/create-prompt.mjs:36:28
    at Emitter.emit (file:///Users/david/projects/linear-adder/node_modules/signal-exit/dist/mjs/index.js:67:19)
    at #processEmit (file:///Users/david/projects/linear-adder/node_modules/signal-exit/dist/mjs/index.js:236:27)
    at #process.emit (file:///Users/david/projects/linear-adder/node_modules/signal-exit/dist/mjs/index.js:187:37)
    at process.callbackTrampoline (node:internal/async_hooks:130:17)

Node.js v18.18.0

What do you see instead?

On the first ctrl + c, nothing happens visually. But, the arrow keys stop working. Instead of moving the cursor, they print escape codes. For example, typing asdf + ^c + left arrow + left arrow prints asdf^[[D^[[D.

On the second ctrl + c, the program actually exits.

Additional information

Notably, if you try and submit input after the first ctrl + c (when you can still type input, but can't use arrow keys), the program will hang.

paperdave commented 8 months ago

note: still an issue after #7650