Inquirer.js
Inquirer.js copied to clipboard
How do I stop Inquirer / close its readline?
My issue is essentially this https://github.com/SBoudrias/Inquirer.js/issues/894 but sort of in reverse.
I am using Inquirer as well as another cli/terminal library (blessed) in the same program.
I want to use inquirer just for the first part of my app then switch fully to blessed. The problem is that I don't know how to close the readline input started from Inquirers prompt()
method. It remains open for whatever reason and causes trouble (characters double up) when typing in the input prompt made by the blessed library.
I've tried wrapping my init call in a setTimeout
to try and let Inquirer "finish" but that hasn't worked.
I hope that's all clear.
same issue
same. Inquirer does not seem to play nice with other CLI systems, for example using readline.createInterface.prompt() as your CLI interface will get stuck if you try to use inquirer inside of it as an option for users.
Yeah, I'm trying to use readline, even though I don't want to, and am only doing so because they never fixed the bug in #214, and it won't work. It outputs the readline prompt, and then exits the script before I can type anything in. This is the only problem stopping me from having a finished project.
honestly, just wtf
I have the same issue but i want to use blessed for an intro and then switch to inquirer, so i get double key input.
ooof, yeah Inquirer doesn't work well with competitors. Just imagine like Windows & Linux.
sorry, you'll probably have to choose one.
I just encountered the same issue and I can close/exit an Inquirer prompt by calling ui.close()
method like this, I don't know if it will solve your issue.
Here is an example :
// Exit the inquirer prompt
function exit () {
prompt.ui.close();
}
// close inquirer input if user press "escape" key
process.stdin.on('keypress', (_, key) => {
if (key.name === "escape") {
exit();
}
});
// Declare your prompt and save it
const prompt = inquirer.prompt({
name: "myInput",
type: "input",
// ...
});
// Listen when the user submit a value
prompt.then( (values) => {
console.log( values['myInput'] );
// ...
})
nice, thank you!
I just encountered the same issue and I can close/exit an Inquirer prompt by calling
ui.close()
method like this, I don't know if it will solve your issue.Here is an example :
// Exit the inquirer prompt function exit () { prompt.ui.close(); } // close inquirer input if user press "escape" key process.stdin.on('keypress', (_, key) => { if (key.name === "escape") { exit(); } });
@arthur-eudeline Thank you for this code. I just wanted to give the user the option to exit out of the Command Line Prompts by pressing the esc key and your code above did just this!!! THANK YOU 🥇
The new API has a cleaner & documented way to cancel a prompt. Details on the README
I'll close this ticket as there's multiple solution in the thread for the previous API, and this version is now only in maintenance mode.