See the changelog for detailed release history.
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:
See the examples folder for additional usage examples.
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:
var prompt = require('{%= name %}')('What is your favorite color?');
prompt.run()
.then(function(answer) {
console.log(answer);
})
Inherit
var Prompt = require('{%= name %}');
function CustomPrompt(/*question, answers, rl*/) {
Prompt.apply(this, arguments);
}
Prompt.extend(CustomPrompt);
{%= apidocs("index.js") %}
Emitted when a prompt (plugin) is instantiated, after the readline interface is created, but before the actual "question" is asked.
Example usage
enquirer.on('prompt', function(prompt) {
// do stuff with "prompt" instance
});
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):
enquirer.on('ask', function(prompt) {
prompt.rl.input.emit('keypress', 'foo');
prompt.rl.input.emit('keypress', '\n');
});
Change the prompt message:
enquirer.on('ask', function(prompt) {
prompt.message = 'I..\'m Ron Burgundy...?';
});
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
enquirer.on('answer', function(answer) {
// do stuff with answer
});
The following custom prompts were created using this library:
{%= related(verb.related.prompts) %}