Maybe I'm missing this in the docs, but I have my own CLI that reads input/output, and I want to use inquirer just for certain prompts (e.g., choices). The problem is that when the inquirer workflow ends, the process exits, so my CLI stops and returns me to the command prompt. Is there something I need to do with the 'line' or 'close' events to prevent this?
You should not have to. If your program still have listeners actives or JS code running, the process shouldn't exit automatically.
Are you sure this is not an issue in your own code?
I already have a readline instance reading the line of user input (read.on('line')). Throughout my workflow, the back and forth between console and user is fine. If the user types in a specific keyword, I launch the prompt via:
prompt('activePrompt').then((answers) => console.log(`Got: ${answers['activePrompt']}`));
The logging is just me testing...
This successful puts me into the prompt, but when the prompt is over the command line program exists entirely, not just the prompt. It doesn't pass control back.
Am I missing an event capture somewhere?
This might be because we need to call:
this.rl.output.end();
this.rl.pause();
this.rl.close();
When ending the prompt. You can see this inside https://github.com/SBoudrias/Inquirer.js/blob/master/packages/inquirer/lib/ui/baseUI.js
The problem is that Node doesn't really work well with multiple readline instances running at the same time (I'm not too familiar with the internal implementation anymore, but a while ago it was pretty much a singleton). The problem, if inquirer don't close its readline instance, then the prompt stays hanging forever and control will no go back to the user.
Maybe an option could be to by-pass closing the readline and leaving this responsibility to the user if they pass the readline instance as an argument; or the an stdin instance (or maybe simpler if we just add an option keepAlive that will not close the readline after running). This would also happen in baseUI if you'd like to take a stab at it.
Ok. Go ahead and assign this to me, and I'll try to tackle it when I come back around to the utility. Thanks!
any news on this one?
Most helpful comment
Ok. Go ahead and assign this to me, and I'll try to tackle it when I come back around to the utility. Thanks!