SBoudrias / Inquirer.js

A collection of common interactive command line user interfaces.
MIT License
20.26k stars 1.31k forks source link

InquirerJS in sync mode #168

Closed fuechter closed 10 years ago

fuechter commented 10 years ago

Can run InquirerJS in sync mode?

Example:

var answers = inquirer.prompt([...]);
SBoudrias commented 10 years ago

Nope. As we ask for user input, there's no way to block processing and make it synchronous.

AdrienHorgnies commented 7 years ago

@SBoudrias Why is that ? I don't quite get it, ask user input synchronously is what I'd do in many languages. The case where you wait for user input and cannot do anything without it is pretty common.

SBoudrias commented 7 years ago

@AdrienHorgnies Yeah, common in a lot of languages, but Node.js doesn't have a synchronous Readline module https://nodejs.org/api/readline.html - so unfortunately, this isn't possible.

That being said, you can leverage the await/async functions to get a similar style

const { name } = await inquirer.prompt();
GopherJ commented 1 year ago

https://github.com/heapwolf/prompt-sync is what you are searching