/prompt-list

Adds `list` prompt support to Enquirer.

Primary LanguageJavaScriptMIT LicenseMIT

prompt-list NPM version NPM downloads

List-style prompt. Can be used as a standalone prompt, or with a prompt system like Enquirer.

prompt-list example

Install

Install with npm:

$ npm install --save prompt-list

Example usage

var List = require('prompt-list');
var list = new List({
  type: 'list',
  name: 'order',
  message: 'What would you like to order?',
  choices: [
    'Coke',
    'Diet Coke',
    'Cherry Coke',
    {
      name: 'Sprite',
      disabled: 'Temporarily unavailable'
    },
    'Water'
  ]
});

// promise
list.run()
  .then(function(answer) {
    console.log(answer);
  });

// or async
list.ask(function(answer) {
  console.log(answer);
});

Enquirer usage

var Enquirer = require('enquirer');
var enquirer = new Enquirer();

enquirer.register('list', require('prompt-list'));

var questions = [
  {
    type: 'list',
    name: 'order',
    message: 'What would you like to order?',
    choices: [
      'Coke',
      'Diet Coke',
      'Cherry Coke',
      {
        name: 'Sprite',
        disabled: 'Temporarily unavailable'
      },
      'Water'
    ]
  }
];

enquirer.ask(questions)
  .then(function(answers) {
    console.log(answers);
  })
  .catch(function(err) {
    console.log(err);
  });

Attribution

Based on the list prompt in inquirer.

About

Related projects

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

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.31, on September 21, 2016.