Inquirer.js icon indicating copy to clipboard operation
Inquirer.js copied to clipboard

Optionally close session

Open RobinKnipe opened this issue 3 years ago • 2 comments

https://github.com/SBoudrias/Inquirer.js/blob/f14ecd77386edfcb7340c667d804867295cbcfda/packages/inquirer/lib/ui/prompt.js#L66 It would be useful to be able to have nested sessions. Sadly the SIGINT closing method means this isn't possible, as any BaseUI that closes will aggressively try and kill the application rather than letting it reach an end.

RobinKnipe avatar Sep 19 '20 07:09 RobinKnipe

This is really annoying. As a work around, you can supply stream.PassThrough streams to inquirer, overriding the .end() function to prevent the stream from being ended.

const inquirerInput = new PassThrough()
realInput.pipe(inquirerInput)

const inquirerOutput = new PassThrough()
inquirerOutput.pipe(realOutput)

inquirerOutput.end = () => console.log('inquirer tried to end stream')

csont protectedPrompt = inquirer.createPromptModule({input: inquirerInput, output: inquirerOutput})

reubn avatar Jan 29 '22 18:01 reubn

Hey, I'm happy to review this behavior. Would you be willing to send a PR removing this?

This has been in the codebase a long time, so I honestly don't really remember why it is there... What I can tell you though is that early Node version had awfully broken readline; so that might've been there to make sure it didn't leak or duplicated inputs. It is possible (even likely) this isn't required anymore.

SBoudrias avatar Jan 31 '22 18:01 SBoudrias

Hi, the new API now exposes this cleanly. Let me know if it helps! https://github.com/SBoudrias/Inquirer.js#canceling-prompt

I'll close this one as the old API is in maintenance mode only now.

SBoudrias avatar Jun 03 '23 21:06 SBoudrias