Prompt that autocompletes as you type. Can be used standalone or with a prompt system like enquirer
Install with npm:
$ npm install --save prompt-autocompletion
var states = ['Alabama', 'Alaska', 'American Samoa', ...];
var AutoComplete = require('prompt-autocompletion');
var autocomplete = new AutoComplete({
type: 'autocomplete',
name: 'from',
message: 'Select a state to travel from',
source: searchStates
});
// promise
autocomplete.run()
.then(function(answer) {
console.log(answer);
});
// or async
autocomplete
.ask(function(answer) {
console.log(answer);
});
function searchStates(answers, input) {
return new Promise(function(resolve) {
resolve(states.filter(filter(input)));
});
}
function filter(input) {
return function(state) {
return new RegExp(input, 'i').exec(state) !== null;
};
}
var states = ['Alabama', 'Alaska', 'American Samoa', ...];
var Enquirer = require('enquirer');
var enquirer = new Enquirer();
enquirer.register('autocomplete', require('prompt-autocompletion'));
var questions = [
{
type: 'autocomplete',
name: 'from',
message: 'Select a state to travel from',
source: searchStates
},
{
type: 'autocomplete',
name: 'to',
message: 'Select a state to travel to',
source: searchStates
}
];
enquirer.ask(questions)
.then(function(answers) {
console.log(answers);
})
.catch(function(err) {
console.log(err);
});
function searchStates(answers, input) {
return new Promise(function(resolve) {
resolve(states.filter(filter(input)));
});
}
function filter(input) {
return function(state) {
return new RegExp(input, 'i').exec(state) !== null;
};
}
Other prompt modules:
- prompt-checkbox: Multiple-choice/checkbox prompt. Can be used standalone or with a prompt system like Enquirer. | homepage
- prompt-confirm: Confirm (yes/no) prompt. Can be used standalone or with a prompt system like Enquirer. | homepage
- prompt-editor: Editor prompt. Opens your text editor and waits for you to save your input during… more | homepage
- prompt-expand: Expand prompt. Can be used as a standalone prompt, or with a prompt system like… more | homepage
- prompt-list: List-style prompt. Can be used as a standalone prompt, or with a prompt system like… more | homepage
- prompt-password: Password prompt. Can be used as a standalone prompt, or with a prompt system like… more | homepage
- prompt-radio: Radio prompt. This prompt behaves like other radio-button interfaces, where only one choice is enabled… more | homepage
- prompt-rawlist: Rawlist prompt. Can be used as a standalone prompt, or with a prompt system like… more | homepage
This is entirely based on https://www.npmjs.com/package/inquirer-autocomplete-prompt Copyright (c) 2015, Martin Hansen martin@martinhansen.no
Thanks, Martin!
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.
Install dev dependencies:
$ npm install -d && npm test
Jon Schlinkert
Copyright © 2016, Jon Schlinkert. Released under the MIT license.
This file was generated by verb-generate-readme, v0.1.31, on October 13, 2016.