prompt-base
Base prompt module used for creating custom prompt types for Enquirer.
Install
Install with npm:
$ npm install --save prompt-base
Usage
var Prompt = require('prompt-base');
var prompt = new Prompt({
name: 'color',
message: 'What is your favorite color?'
});
prompt.run()
.then(function(answer) {
console.log(answer);
})
API
Create a new Prompt with the given question
object, answers
and optional instance of readline-ui.
Params
question
{Object}: Plain object or instance of prompt-question.answers
{Object}: Optionally pass an answers object from a prompt manager (like enquirer).ui
{Object}: Optionally pass an instance of readline-ui. If not passed, an instance is created for you.
Example
var prompt = new Prompt({
name: 'color',
message: 'What is your favorite color?'
});
prompt.ask(function(answer) {
console.log(answer);
});
Initialize a prompt and resolve answers. If question.when
returns false,
the prompt will be skipped.
Params
answers
{Object}returns
{Promise}
Render the current prompt input. This can be replaced by custom prompts.
Example
prompt.ui.on('keypress', prompt.render.bind(prompt));
Returns a formatted prompt message.
Getter for getting the choices array from the question.
returns
{Object}: Choices object
Getter that returns question.message
after passing it to format.
returns
{String}: A formatted prompt message.
Getter that returns the prefix to use before question.message
. The
default value is a green ?
.
returns
{String}: The formatted prefix.
Getter that gets the readline-ui
. If a ui
instance is not
returns
{Object}: Choices object
Examples
Instantiate
The main purpose of this library is to be inherited by other libraries to create custom prompt types. However, the main export is a function that can be instantiated to run basic "input" prompts, if you want to see how everything works, run examples, tests, etc.
var Prompt = require('prompt-base');
var prompt = new Prompt({
name: 'first',
message: 'What is your name?'
});
prompt.ask(function(answer) {
console.log(answer);
});
prompt.run()
.then(function(answers) {
console.log(answers);
});
See enquirer-prompt-input for a more complete input
prompt implementation.
Inherit
var Prompt = require('prompt-base');
function CustomPrompt() {
Prompt.apply(this, arguments);
}
util.inherits(CustomPrompt, Prompt);
In the wild
The following custom prompts were created using this library:
About
Related projects
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the contributing guide for avice on opening issues, pull requests, and coding standards.
Building docs
(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)
To generate the readme and API documentation with verb:
$ npm install -g verb verb-generate-readme && verb
Running tests
Install dev dependencies:
$ npm install -d && npm test
Author
Jon Schlinkert
License
Copyright © 2016, Jon Schlinkert.
Released under the MIT license.
This file was generated by verb-generate-readme, v0.1.30, on September 01, 2016.