Socket
Socket
Sign inDemoInstall

inquirer

Package Overview
Dependencies
Maintainers
1
Versions
179
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inquirer - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

8

lib/objects/choice.js

@@ -23,3 +23,3 @@ /**

function Choice( val ) {
function Choice( val, answers ) {

@@ -40,2 +40,8 @@ // Don't process Choice and Separator object

}
if ( _.isFunction(val.disabled) ) {
this.disabled = val.disabled( answers );
} else {
this.disabled = val.disabled;
}
}

10

lib/objects/choices.js

@@ -25,3 +25,3 @@ /**

function Choices( choices ) {
function Choices( choices, answers ) {
this.choices = _.map( choices, function( val ) {

@@ -31,6 +31,10 @@ if ( val.type === "separator" ) {

}
return new Choice( val );
return new Choice( val, answers );
});
this.realChoices = this.choices.filter(Separator.exclude);
this.realChoices = this.choices
.filter(Separator.exclude)
.filter(function( item ) {
return !item.disabled;
});

@@ -37,0 +41,0 @@ Object.defineProperty( this, "length", {

@@ -8,3 +8,3 @@ /**

var clc = require("cli-color");
var ansiTrim = require("cli-color/lib/trim");
var ansiTrim = require("cli-color/trim");
var readline = require("readline");

@@ -27,3 +27,3 @@ var utils = require("../utils/utils");

function Prompt( question, rl ) {
function Prompt( question, rl, answers ) {

@@ -53,3 +53,3 @@ // Setup instance defaults property

if ( _.isArray(this.opt.choices) ) {
this.opt.choices = new Choices( this.opt.choices );
this.opt.choices = new Choices( this.opt.choices, answers );
}

@@ -190,3 +190,3 @@

// Append the default if available, and if question isn't answered
if ( this.opt.default && this.status !== "answered" ) {
if ( this.opt.default != null && this.status !== "answered" ) {
message += "("+ this.opt.default + ") ";

@@ -193,0 +193,0 @@ }

@@ -198,5 +198,12 @@ /**

var isSelected = (i - separatorOffset === pointer);
output += isSelected ? clc.cyan(utils.getPointer()) : " ";
output += utils.getCheckbox( choice.checked, choice.name );
if ( choice.disabled ) {
separatorOffset++;
output += " - " + choice.name;
output += " (" + (_.isString(choice.disabled) ? choice.disabled : "Disabled") + ")";
} else {
var isSelected = (i - separatorOffset === pointer);
output += isSelected ? clc.cyan(utils.getPointer()) : " ";
output += utils.getCheckbox( choice.checked, choice.name );
}
output += "\n";

@@ -203,0 +210,0 @@ }.bind(this));

@@ -69,17 +69,21 @@ /**

Prompt.prototype.onSubmit = function( input ) {
var value = input || this.opt.default || "";
var value = input;
if ( !value ) {
var value = this.opt.default != null ? this.opt.default : "";
}
this.validate( value, function( isValid ) {
if ( isValid === true ) {
this.status = "answered";
this.filter( value, function( value ) {
this.status = "answered";
// Re-render prompt
this.clean(1).render();
// Re-render prompt
this.clean(1).render();
// Render answer
this.write( clc.cyan(value) + "\n" );
// Render answer
this.write( clc.cyan(value) + "\n" );
this.rl.removeAllListeners("line");
this.done( value );
this.rl.removeAllListeners("line");
this.done( value );
}.bind(this));
} else {

@@ -86,0 +90,0 @@ this.error( isValid ).clean().render();

@@ -73,5 +73,7 @@ /**

Prompt.prototype.onSubmit = function( input ) {
var value = input;
if ( !value ) {
var value = this.opt.default != null ? this.opt.default : "";
}
var value = input || this.opt.default || "";
this.rl.output.unmute();

@@ -88,3 +90,3 @@ this.write("\n"); // manually output the line return as the readline was muted

// Mask answer
var mask = new Array( value.length + 1 ).join("*");
var mask = new Array( value.toString().length + 1 ).join("*");

@@ -91,0 +93,0 @@ // Render answer

@@ -31,2 +31,3 @@ /**

this.rl.on( "SIGINT", this.onForceClose );
process.on( "exit", this.onForceClose );

@@ -58,6 +59,7 @@ // Propagate keypress events directly on the readline

process.stdin.removeListener( "keypress", this.onKeypress );
process.removeListener( "exit", this.onForceClose );
// Restore prompt functionnalities
this.rl.output.unmute();
process.stdout.write("\033[?25h"); // show cursor
process.stdout.write("\x1B[?25h"); // show cursor

@@ -64,0 +66,0 @@ // Close the readline

@@ -82,7 +82,7 @@ /**

var prompt = new inquirer.prompts[question.type]( question, this.rl );
var prompt = new inquirer.prompts[question.type]( question, this.rl, this.answers );
// Check if prompt should be runned (if `when` return true)
utils.runAsync( prompt.opt.when, function( continu ) {
if( continu ) {
if ( continu ) {
prompt.run( after );

@@ -89,0 +89,0 @@ } else {

@@ -81,3 +81,3 @@ /**

tty.hideCursor = function() {
return this.write("\033[?25l");
return this.write("\x1B[?25l");
};

@@ -92,3 +92,3 @@

tty.showCursor = function() {
return this.write("\033[?25h");
return this.write("\x1B[?25h");
};

@@ -95,0 +95,0 @@

{
"name": "inquirer",
"version": "0.4.1",
"version": "0.5.0",
"description": "A collection of common interactive command line user interfaces.",

@@ -22,21 +22,21 @@ "main": "lib/inquirer.js",

"dependencies": {
"async": "~0.8.0",
"cli-color": "~0.3.2",
"lodash": "~2.4.1",
"async": "~0.2.8",
"cli-color": "~0.2.2",
"mute-stream": "0.0.4",
"through": "~2.3.4",
"readline2": "~0.1.0"
"readline2": "~0.1.0",
"through": "~2.3.4"
},
"devDependencies": {
"chai": "~1.9.0",
"cmdify": "0.0.4",
"grunt": "~0.4.1",
"grunt-cli": "~0.1.8",
"mocha": "~1.17.1",
"chai": "~1.9.0",
"grunt-contrib-jshint": "~0.8.0",
"sinon": "~1.7.2",
"grunt-release": "~0.6.0",
"grunt-contrib-jshint": "~0.10.0",
"grunt-mocha-test": "~0.10.2",
"grunt-release": "~0.7.0",
"mocha": "~1.18.2",
"mockery": "~1.4.0",
"grunt-mocha-test": "~0.9.0",
"cmdify": "0.0.4"
"sinon": "~1.9.1"
}
}

@@ -1,26 +0,23 @@

Inquirer.js [![Build Status](https://travis-ci.org/SBoudrias/Inquirer.js.png?branch=master)](http://travis-ci.org/SBoudrias/Inquirer.js)
=====================
Inquirer.js
===========
[![npm](https://badge.fury.io/js/inquirer.svg)](http://badge.fury.io/js/inquirer) [![tests](https://travis-ci.org/SBoudrias/Inquirer.js.svg?branch=master)](http://travis-ci.org/SBoudrias/Inquirer.js) [![dependencies](https://david-dm.org/SBoudrias/Inquirer.js.svg?theme=shields.io)](https://david-dm.org/SBoudrias/Inquirer.js)
A collection of common interactive command line user interfaces.
Goal and philosophy
---------------------
## Goal and philosophy
We strive at providing easily embeddable and beautiful command line interface for Node.js ;
some hope in becoming the CLI Xanadu.
We strive at providing easily embeddable and beautiful command line interface for Node.js; some hope in becoming the CLI Xanadu.
_Inquirer_ should ease the process of asking end user **questions**, **parsing**, **validating** answers, managing **hierarchical prompts** and providing **error feedback**.
_**Inquirer**_ should ease the process of asking end user **questions**, **parsing**, **validating** answers, managing **hierarchical prompts** and providing **error feedback**.
_Inquirer_ provide the user interface, and the inquiry session flow. If you're searching for a full blown command line program utility, then check out [Commander.js](https://github.com/visionmedia/commander.js) (inspired by) or [Cli-color](https://github.com/medikoo/cli-color) (used internally).
_**Inquirer**_ provide the user interface, and the inquiry session flow. If you're searching for a full blown command line program utility, then check out [Commander.js](https://github.com/visionmedia/commander.js) (inspired by) or [cli-color](https://github.com/medikoo/cli-color) (used internally).
Documentation
=====================
## Documentation
### Installation
Installation
---------------------
``` prompt
``` shell
npm install inquirer

@@ -37,40 +34,37 @@ ```

Examples (Run it and see it)
---------------------
### Examples (Run it and see it)
Checkout the `examples/` folder for code and interface examples.
``` prompt
``` shell
node examples/pizza.js
# etc
node examples/checkbox.js
# etc...
```
Methods
---------------------
### Methods
### `inquirer.prompt( questions, callback )`
`inquirer.prompt( questions, callback )`
Launch the prompt interface (inquiry session)
+ **questions** (Array) containing [Question Object](#question)
+ **callback** (Function) first parameter is the [Answers Object](#answers)
- **questions** (Array) containing [Question Object](#question)
- **callback** (Function) first parameter is the [Answers Object](#answers)
Objects
---------------------
### Objects
### Question
#### Question
A question object is a `hash` containing question related values:
+ **type**: (String) Type of the prompt. Defaults: `input` - Possible values: `input`, `confirm`,
- **type**: (String) Type of the prompt. Defaults: `input` - Possible values: `input`, `confirm`,
`list`, `rawlist`
+ **name**: (String) The name to use when storing the answer in the anwers hash.
+ **message**: (String) The question to print.
+ **default**: (String|Number|Array|Function) Default value(s) to use if nothing is entered, or a function that returns the default value(s). If defined as a function, the first parameter will be the current inquirer session answers.
+ **choices**: (Array|Function) Choices array or a function returning a choices array. If defined as a function, the first parameter will be the current inquirer session answers.
- **name**: (String) The name to use when storing the answer in the anwers hash.
- **message**: (String) The question to print.
- **default**: (String|Number|Array|Function) Default value(s) to use if nothing is entered, or a function that returns the default value(s). If defined as a function, the first parameter will be the current inquirer session answers.
- **choices**: (Array|Function) Choices array or a function returning a choices array. If defined as a function, the first parameter will be the current inquirer session answers.
Array values can be simple `strings`, or `objects` containing a `name` (to display) and a `value` properties (to save in the answers hash). Values can also be [a `Separator`](#separator).
+ **validate**: (Function) Receive the user input and should return `true` if the value is valid, and an error message (`String`) otherwise. If `false` is returned, a default error message is provided.
+ **filter**: (Function) Receive the user input and return the filtered value to be used inside the program. The value returned will be added to the _Answers_ hash.
+ **when**: (Function) Receive the current user answers hash and should return `true` or `false` depending on whether or not this question should be asked.
- **validate**: (Function) Receive the user input and should return `true` if the value is valid, and an error message (`String`) otherwise. If `false` is returned, a default error message is provided.
- **filter**: (Function) Receive the user input and return the filtered value to be used inside the program. The value returned will be added to the _Answers_ hash.
- **when**: (Function) Receive the current user answers hash and should return `true` or `false` depending on whether or not this question should be asked.

@@ -103,7 +97,7 @@ `validate`, `filter` and `when` functions can be asynchronously using `this.async()`. You just have to pass the value you'd normally return to the callback option.

+ **Key** The `name` property of the _question_ object
+ **Value** (Depends on the prompt)
+ `confirm`: (Boolean)
+ `input` : User input (filtered if `filter` is defined) (String)
+ `rawlist`, `list` : Selected choice value (or name if no value specified) (String)
- **Key** The `name` property of the _question_ object
- **Value** (Depends on the prompt)
- `confirm`: (Boolean)
- `input` : User input (filtered if `filter` is defined) (String)
- `rawlist`, `list` : Selected choice value (or name if no value specified) (String)

@@ -133,5 +127,5 @@ ### Separator

_allowed options written inside square brackets (`[]`) are optional. Others are required._
> **Note:**: _allowed options written inside square brackets (`[]`) are optional. Others are required._
### List - `{ type: "list" }`
#### List - `{ type: "list" }`

@@ -143,11 +137,15 @@ Take `type`, `name`, `message`, `choices`[, `default`, `filter`] properties. (Note that

### Raw List - `{ type: "rawlist" }`
---
#### Raw List - `{ type: "rawlist" }`
Take `type`, `name`, `message`, `choices`[, `default`, `filter`] properties. (Note that
default must the choice `index` in the array)
![Raw list prompt](https://dl.dropboxusercontent.com/u/59696254/inquirer/rawlist-prompt.png)
![Raw list prompt](https://i.cloudup.com/LcRGpXI0CX-3000x3000.png)
### Expand - `{ type: "expand" }`
---
#### Expand - `{ type: "expand" }`
Take `type`, `name`, `message`, `choices`[, `default`, `filter`] properties. (Note that

@@ -163,4 +161,5 @@ default must be the choice `index` in the array)

---
### Checkbox - `{ type: "checkbox" }`
#### Checkbox - `{ type: "checkbox" }`

@@ -171,6 +170,10 @@ Take `type`, `name`, `message`, `choices`[, `filter`, `validate`, `default`] properties. `default` is expected to be an Array of the checked choices value.

Choices who're property `disabled` is truthy will be unselectable. If `disabled` is a string, then the string will be outputed next to the disabled choice, otherwise it'll default to `"Disabled"`. The `disabled` property can also be a synchronous function receiving the current answers as argument and returning a boolean or a string.
![Checkbox prompt](https://dl.dropboxusercontent.com/u/59696254/inquirer/checkbox-prompt.png)
### Confirm - `{ type: "confirm" }`
---
#### Confirm - `{ type: "confirm" }`
Take `type`, `name`, `message`[, `default`] properties. `default` is expected to be a boolean if used.

@@ -180,4 +183,6 @@

### Input - `{ type: "input" }`
---
#### Input - `{ type: "input" }`
Take `type`, `name`, `message`[, `default`, `filter`, `validate`] properties.

@@ -187,4 +192,6 @@

### Password - `{ type: "password" }`
---
#### Password - `{ type: "password" }`
Take `type`, `name`, `message`[, `default`, `filter`, `validate`] properties.

@@ -194,12 +201,11 @@

User Interfaces and layouts
---------------------
## User Interfaces and layouts
Along with the prompts, Inquirer offers some basic text UI.
### Bottom Bar - `inquirer.ui.BottomBar`
#### Bottom Bar - `inquirer.ui.BottomBar`
This UI present a fixed text at the bottom of a free text zone. This is useful to keep a message to the bottom of the screen while outputting command outputs on the higher section.
```
```javascript
var ui = new inquirer.ui.BottomBar();

@@ -219,3 +225,3 @@

### Prompt - `inquirer.ui.Prompt`
#### Prompt - `inquirer.ui.Prompt`

@@ -225,4 +231,3 @@ This is UI layout used to run prompt. This layout is returned by `inquirer.prompt` and you should probably always use `inquirer.prompt` to interface with this UI.

Support (OS - terminals)
=====================
## Support (OS Terminals)

@@ -243,4 +248,3 @@ You should expect mostly good support for the CLI below. This does not mean we won't

News on the march (Release notes)
=====================
## News on the march (Release notes)

@@ -250,12 +254,17 @@ Please refer to the [Github releases section for the changelog](https://github.com/SBoudrias/Inquirer.js/releases)

Contributing
=====================
## Contributing
**Style Guide**: Please base yourself on [Idiomatic.js](https://github.com/rwldrn/idiomatic.js) style guide with two space indent
**Unit test**: Unit test are wrote in Mocha. Please add a unit test for every new feature
or bug fix. `npm test` to run the test suite.
**Documentation**: Add documentation for every API change. Feel free to send corrections
**Style Guide**
Please brief yourself on [Idiomatic.js](https://github.com/rwldrn/idiomatic.js) style guide with two space indent
**Unit test**
Unit test are written in [Mocha](http://visionmedia.github.io/mocha/). Please add a unit test for every new feature or bug fix. `npm test` to run the test suite.
**Documentation**
Add documentation for every API change. Feel free to send corrections
or better docs!
**Pull Requests**: Send _fixes_ PR on the `master` branch. Any new features should be send on the `wip`branch.
**Pull Requests**
Send _fixes_ PR on the `master` branch. Any new features should be send on the `wip`branch.
We're looking to offer good support for multiple prompts and environments. If you want to

@@ -266,6 +275,5 @@ help, we'd like to keep a list of testers for each terminal/OS so we can contact you and

License
=====================
## License
Copyright (c) 2012 Simon Boudrias (twitter: @vaxilart)
Licensed under the MIT license.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc