list-selector-cli
v0.0.3
Published
(Hopefully) useful little commandline interface for selecting items from a list, inspired by the git-add interactive interface.
Downloads
84
Maintainers
Readme
Git-style interactive list selector for Node CLI apps
Does one thing: Lets the users of your NodeJS app interactively select/de-select items from a list by indices and ranges on the commandline.
Familiar "UI" -- to GitHubbers at least! Same interface as the trusty "git add --interactive"
Brain-dead simple to use in your project
Options can be any array of toString-able things
Get the user's response in a callback OR a jQuery-style promise
Example: Let's make a sandwich
Probably better for selecting filepaths, but I'm hungry right now so...
Let's choose the toppings on your sandwich via CLI.
What you do
- Install from NPM:
npm install list-selector-cli`
- Require it in your project:
var cliselect = require("list-selector-cli");
- Pick an array of options:
var options = ["lettuce", "tomatoes", "spinach", "ham"];
- Create your list:
var sandwichChoice = new cliselect(options);
Prompt the user:
console.log("What would you like on your sandwich?")
Let them interactively choose their options and handle their response
- In a callback:
sandwichChoice.prompt(function(selection) { /** do something **/ });
- Or with a promise:
var promise = sandwichChoice.prompt();
promise.done(function(selection) { /** do something **/ });
What you get
$ node examples/sandwich.js
What would you like on your sandwich?
0: lettuce
1: tomatoes
2: spinach
3: avocado
4: ham
5: bacon
6: oil
7: vinegar
Update selection (blank to accept)>>:
Hmm... All the veggies and some oil, please.
Update selection (blank to accept)>>: 0-4,6
*0: lettuce
*1: tomatoes
*2: spinach
*3: avocado
*4: ham
5: bacon
*6: oil
7: vinegar
Update selection (blank to accept)>>:
Crap, I don't eat ham. De-ham the sandwich, plz.
Update selection (blank to accept)>>:-4
-4
*0: lettuce
*1: tomatoes
*2: spinach
*3: avocado
4: ham
5: bacon
*6: oil
7: vinegar
Update selection (blank to accept)>>:
Eat-able? Yes. <Enter>
[ 'lettuce', 'tomatoes', 'spinach', 'avocado', 'oil' ]
Totally pitching a commandline interface to Subway...
Maybe ssh.subway.com
: "open 8am to 9pm and 24 hrs a day on port 22..." :-)