Prompts Improved
Node.js prompts like you always wanted. Style them to your heart's content using Chalk, an amazing CLI package for colors and text styling. Features include:
- Default options
- Boolean questions (simple y/n answers get converted to true/false)
- Input validation (using regex's or functions)
- Input filters (both before validation and after)
- Required fields
- Input attempt limits (think limiting password tries)
- Ask single or multiple questions
- When asking multiple questions, subsequent questions can be dependant on previous input. Allows for simple logic in prompt path.
- Configurable prefixs and suffixes
- Override defaults at runtime (
overrideDefaults: {key: value}
) - Custom error messaging
- Confirmation prompt for input of multiple questions
- Input timeouts
- Per-prompt configuration
- Convient error handeling
- (Coming Soon) Multiple choice questions
Examples
Just ask your user a question:
var Prompt = ; var prompt = // Some options for all prompts prefix: '[?] ' prefixTheme: Promptchalkgreen; prompt; // Outputs: [?] Where in the world is Carmen Sandiego?:
Options can be provided for all prompts or overridden on a per-prompt basis:
var Prompt = ; var prompt = suffix: '? '; prompt; // Outputs: How is your day going beautiful?
Asking multiple questions:
var Prompt = ;var prompt = ;prompt;
Full example will all options:
var Prompt = ; // These are all the defaultsvar prompt = prefix : '' suffix : ': ' defaultPrefix : ' (' defaultSuffix : ')' textTheme : Promptchalkbold prefixTheme : Promptchalkwhite suffixTheme : Promptchalkwhite defaultTheme : Promptchalkwhite inputError : 'Error encountered, try again.' requiredError : 'Required! Try again.' invalidError : 'Invalid input: ' attemptsError : 'Maximum attempts reached!' stdin : processstdin stdout : processstdout stderr : processstderr timeout : null; // Each question can have it's own optionsprompt;
Tests
Unit tests and test coverage are available:
// runs the tests and watches for file changes
$ grunt
// Runs the coverage generator and opens your borwser to the results
$ grunt coverage
Contributions
Please contribute. Make pull requests against the develop branch.