## Release history See [the changelog](changelog.md) for detailed release history. ## What is this? prompt-base is a node.js library for creating command line prompts. You can use prompt-base directly for simple input prompts, or as a "base" for creating [custom prompts](#in-the-wild): ## Usage See the [examples folder](./examples) for additional usage examples. ```js var Prompt = require('{%= name %}'); var prompt = new Prompt({ name: 'color', message: 'What is your favorite color?' }); // promise prompt.run() .then(function(answer) { console.log(answer); //=> 'blue' }) // or async prompt.ask(function(answer) { console.log(answer); //=> 'blue' }); ``` You can also pass a string directly to the main export: ```js var prompt = require('{%= name %}')('What is your favorite color?'); prompt.run() .then(function(answer) { console.log(answer); }) ``` ## Custom prompts **Inherit** ```js var Prompt = require('{%= name %}'); function CustomPrompt(/*question, answers, rl*/) { Prompt.apply(this, arguments); } Prompt.extend(CustomPrompt); ``` ## API {%= apidocs("index.js") %} ## Events ### prompt Emitted when a prompt (plugin) is instantiated, _after the readline interface is created, but before the actual "question" is asked_. **Example usage** ```js enquirer.on('prompt', function(prompt) { // do stuff with "prompt" instance }); ``` ### ask Emitted when the actual "question" is asked. **Example usage** Emit `keypress` events to supply the answer (and potentially skip the prompt if the answer is valid): ```js enquirer.on('ask', function(prompt) { prompt.rl.input.emit('keypress', 'foo'); prompt.rl.input.emit('keypress', '\n'); }); ``` Change the prompt message: ```js enquirer.on('ask', function(prompt) { prompt.message = 'I..\'m Ron Burgundy...?'; }); ``` ### answer Emitted when the final (valid) answer is submitted, and custom validation function (if defined) returns true. _(An "answer" is the final input value that's captured when the `readline` emits a `line` event; e.g. when the user hits `enter`)_ **Example usage** ```js enquirer.on('answer', function(answer) { // do stuff with answer }); ``` ## In the wild The following custom prompts were created using this library: {%= related(verb.related.prompts) %} [rl]: https://nodejs.org/api/readline.html#readline_rl_write_data_key [resume]: https://nodejs.org/api/readline.html#readline_rl_resume