All Projects → enquirer → Prompt Checkbox

enquirer / Prompt Checkbox

Licence: mit
This repository has been archived, use Enquirer instead.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Prompt Checkbox

Generate
A new command line tool and developer framework for scaffolding out GitHub projects. Generate offers the robustness and configurability of Yeoman, the expressiveness and simplicity of Slush, and more powerful flow control and composability than either.
Stars: ✭ 238 (+1033.33%)
Mutual labels:  generate, generator, yeoman
Vxe Table
🐬 vxe-table vue 表格解决方案
Stars: ✭ 4,242 (+20100%)
Mutual labels:  radio, select, checkbox
Project Name
Get the name of a project from package.json, git config, or basename of the current working directory.
Stars: ✭ 8 (-61.9%)
Mutual labels:  generate, generator, yeoman
Flutter smart select
SmartSelect allows you to easily convert your usual form select or dropdown into dynamic page, popup dialog, or sliding bottom sheet with various choices input such as radio, checkbox, switch, chips, or even custom input. Supports single and multiple choice.
Stars: ✭ 179 (+752.38%)
Mutual labels:  radio, select, checkbox
enquirer
Stylish, intuitive and user-friendly prompts, for Node.js. Used by eslint, webpack, yarn, pm2, pnpm, RedwoodJS, FactorJS, salesforce, Cypress, Google Lighthouse, Generate, tencent cloudbase, lint-staged, gluegun, hygen, hardhat, AWS Amplify, GitHub Actions Toolkit, @airbnb/nimbus, and many others! Please follow Enquirer's author: https://github.…
Stars: ✭ 6,523 (+30961.9%)
Mutual labels:  yeoman, prompt, readline
Yo
CLI tool for running Yeoman generators
Stars: ✭ 3,421 (+16190.48%)
Mutual labels:  generator, yeoman
Console
The Hoa\Console library.
Stars: ✭ 354 (+1585.71%)
Mutual labels:  terminal, readline
Typewritten
A minimal, lightweight, informative zsh prompt theme
Stars: ✭ 442 (+2004.76%)
Mutual labels:  terminal, prompt
Readline Sync
Synchronous Readline for interactively running to have a conversation with the user via a console(TTY).
Stars: ✭ 601 (+2761.9%)
Mutual labels:  prompt, readline
Github Activity Generator
A script that helps generate a rich GitHub Contribution Graph for your account
Stars: ✭ 259 (+1133.33%)
Mutual labels:  generate, generator
Formbase
Better default styles for common input elements.
Stars: ✭ 560 (+2566.67%)
Mutual labels:  select, checkbox
Iconizer
Create Xcode asset catalogs swift and painless. Generate images for macOS and iOS app icons, launch images and image sets.
Stars: ✭ 751 (+3476.19%)
Mutual labels:  generate, generator
Trueline
Fast and extensible bash powerline prompt with true color and fancy icon support
Stars: ✭ 271 (+1190.48%)
Mutual labels:  terminal, prompt
Go Prompt
Building powerful interactive prompts in Go, inspired by python-prompt-toolkit.
Stars: ✭ 4,255 (+20161.9%)
Mutual labels:  terminal, prompt
Generator Plugin Wp
Yeoman WordPress Plugin Generator
Stars: ✭ 270 (+1185.71%)
Mutual labels:  generator, yeoman
Bootstrap Switch
Turn checkboxes and radio buttons in toggle switches.
Stars: ✭ 5,132 (+24338.1%)
Mutual labels:  radio, checkbox
Dotfiles
Configurations for the tools I use every day
Stars: ✭ 898 (+4176.19%)
Mutual labels:  terminal, prompt
Laravel Bootstrap Table List
Bootstrap table list generator for Laravel.
Stars: ✭ 16 (-23.81%)
Mutual labels:  generate, generator
Generator Modular Angular
A truly modular yeoman generator for AngularJS all device apps.
Stars: ✭ 23 (+9.52%)
Mutual labels:  generator, yeoman
nest-js-boilerplate
Nest.js boilerplate
Stars: ✭ 79 (+276.19%)
Mutual labels:  generator, yeoman

prompt-checkbox NPM version NPM monthly downloads NPM total downloads Linux Build Status

Multiple-choice/checkbox prompt. Can be used standalone or with a prompt system like Enquirer.

prompt-checkbox example

Install

Install with npm:

$ npm install --save prompt-checkbox

Usage

var Prompt = require('prompt-checkbox');
var prompt = new Prompt({
  name: 'colors',
  message: 'What are your favorite colors?',
  choices: [
    'red',
    'blue',
    'yellow'
  ]
});

// promises
prompt.run()
  .then(function(answers) {
    console.log(answers)
  })
  .catch(function(err) {
    console.log(err)
  })

// async
prompt.ask(function(answers) {
  console.log(answers)
});

Special features

Features you won't find with other prompts!

Choices function

Define choices as a function. This allows you to dynamically generate the choices when the question is asked.

var prompt = new Prompt({
  name: 'colors',
  message: 'What are your favorite colors?',
  choices: function() {
    // dynamically build choices 
    return ['red', 'blue', 'green'];
  }
});

Choice groups

Choices groups

Easy to configure!

Just pass an object of arrays on choices, and each key in the object will be used as the group "toggle":

var Prompt = require('prompt-checkbox');
var prompt = new Prompt({
  name: 'install',
  message: 'Which packages do you want to install?',
  choices: {
    dependencies: ['generate', 'micromatch'],
    devDependencies: ['mocha', 'kind-of']
  }
});

Radio choices

Adds all and none choices, which select or deselect all choices, respectively. Named "radio choices" since it acts like a hybrid between checkboxes and radio buttons.


radio choices

Code example

var Prompt = require('prompt-checkbox');
var prompt = new Prompt({
  name: 'install',
  message: 'Which packages do you want to install?',
  radio: true,
  choices: ['foo', 'bar', 'baz']
});

Radio groups

Use "radio" choices with choice groups.


radio groups

var Prompt = require('prompt-checkbox');
var prompt = new Prompt({
  name: 'install',
  message: 'Which packages do you want to install?',
  radio: true,
  choices: {
    dependencies: ['generate', 'micromatch'],
    devDependencies: ['mocha', 'kind-of']
  }
});

options

The following options are either specific to prompt-checkbox, or have behavior that differs in some way from the built-in options from prompt-base. (Any other options from prompt-base may be used as well.)

options.default

Type: string|number|array

Default: undefined

Specify the "default" choices to check when the prompt is initialized. Default can be a choice name (string), index (number), or an array of choice names or indices.

Examples

Specify default as a string (choice name):

var prompt = new Prompt({
  name: 'colors',
  message: 'Best flavor?',
  default: 'chocolate',
  choices: ['chocolate'] // <= hmm, I wonder what they'll choose?
});

Specify an array of defaults (choice names or indices):

var prompt = new Prompt({
  name: 'colors',
  message: 'Favorite colors?',
  default: [1, 'blue'],
  choices: ['red', 'blue', 'yellow']
});

options.radio

Type: boolean

Default: undefined

Enable hybrid radio-checkbox support, which adds all and none radio options for toggling all options on and off.

var Prompt = require('prompt-checkbox');
var prompt = new Prompt({
  name: 'colors',
  message: 'What are your favorite colors?',
  radio: true,
  choices: [
    'red',
    'blue',
    'yellow'
  ]
});

options.transform

Type: function

Default: undefined

Modify answer values before they're returned.

Example

Use options.transform and the prompt.choices.get() method to convert answers (checked choices) to an array of objects (versus of an array of strings).

var Prompt = require('prompt-checkbox');
var prompt = new Prompt({
  name: 'colors',
  message: 'What are your favorite colors?',
  choices: ['red', 'blue', 'yellow'],
  transform: function(answer) {
    // - "this" is the prompt instance
    // - "this.choices.get()" returns the choice object for each choice
    return answer ? answer.map(this.choices.get.bind(this.choices)) : [];
  }
});

Keypresses

In addition to the keypresses that are supported by prompt-base, the following keypress offer different behavior that is specific to checklists:

  • down - move the pointer (cursor) down one row for each keypress
  • up - move the pointer (cursor) up one row for each keypress
  • i - toggle all choices to the opposite of their current state.
  • a - enable or disable all choices
  • space - toggle a choice
  • number - toggle the choice at the given index (starting at 1)

Usage with enquirer

Register the prompt with enquirer:

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

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

Enquirer examples

For formatting questions, enquirer supports either:

  • declarative, inquirer-style question format
  • functional format using the .question method.

Inquirer-style questions

Declarative questions format, similar to inquirer.

var questions = [
  {
    name: 'color',
    message: 'What is your favorite color?',
    type: 'checkbox',
    default: 'blue',
    choices: ['red', 'yellow', 'blue']
  }
];

enquirer.prompt(questions)
  .then(function(answers) {
    console.log(answers)
  });

Or:

enquirer.prompt({
    name: 'color',
    message: 'What is your favorite color?',
    type: 'checkbox',
    default: 'blue',
    choices: ['red', 'yellow', 'blue']
  })
  .then(function(answers) {
    console.log(answers)
  });

Functional-style questions

Use the .question method to pre-register questions, so they can be called later. Also, the message may be passed as the second argument, or as a property on the question options.

enquirer.question('letter', 'What are your favorite letters?', {
  type: 'checkbox', //<= specify the prompt type
  choices: ['a', 'b', 'c']
});

enquirer.question('numbers', {
  type: 'checkbox', //<= specify the prompt type
  message: 'What are your favorite numbers?',
  choices: ['1', '2', '3']
});

// pass the name(s) or questions to ask
enquirer.prompt(['letters', 'numbers'])
  .then(function(answers) {
    console.log(answers)
  });

About

Related projects

Contributing

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

Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on July 08, 2017.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].