prompt-actions
Advanced tools
Comparing version 2.0.2 to 3.0.0
107
index.js
@@ -6,13 +6,12 @@ 'use strict'; | ||
/** | ||
* Create an instance of `Actions`, optionally with an instance | ||
* of [prompt-choices][]. Any of the methods may be overridden in custom | ||
* prompts. | ||
* Create an instance of `Actions` with an instance of [prompt-base][]. | ||
* Any of the methods may be overridden in custom prompts. | ||
* | ||
* ```js | ||
* var Actions = require('prompt-actions'); | ||
* var Choices = require('prompt-choices'); | ||
* var choices = new Choices(['foo', 'bar']); | ||
* var actions = new Actions(choices); | ||
* var Base = require('prompt-base'); | ||
* var prompt = new Prompt('Favorite flavor?' ['chocolate', 'vanilla']); | ||
* var actions = new Actions(prompt); | ||
* ``` | ||
* @param {Object} `choices` Instance of [prompt-choices][]. This can alternatively be set by doing `actions.choices = new Choices(['foo', 'bar'])` after instantiation. | ||
* @param {Object} `prompt` Instance of [prompt-base][]. | ||
* @api public | ||
@@ -24,6 +23,7 @@ */ | ||
this.prompt = prompt; | ||
this.options = this.prompt.options; | ||
} | ||
/** | ||
* Handle `number` keypress events. Toggles the choice at | ||
* Handle <kbd>number</kbd> keypress events. Toggles the choice at | ||
* corresponding row, starting at `1`. Because of this (1-based index) | ||
@@ -47,3 +47,3 @@ * we need to decrement the returned position by `1`, so that | ||
/** | ||
* Handle `space` keypress events. Toggles the choice at the | ||
* Handle <kbd>space</kbd> keypress events. Toggles the choice at the | ||
* current position (e.g. on the same row as the pointer). | ||
@@ -62,3 +62,4 @@ * | ||
/** | ||
* Identity function that simply returns the cursor position | ||
* Handle <kbd>tab</kbd> keypress events. By default, this is | ||
* just an identity function that returns the cursor position | ||
* on `tab` keypress events. This may be overridden in custom | ||
@@ -88,3 +89,3 @@ * prompts. | ||
/** | ||
* Handle `a` keypress events. If all choices are already checked, | ||
* Handle <kbd>a</kbd> keypress events. If all choices are already checked, | ||
* this will disable all choices. If zero to any other number of | ||
@@ -104,3 +105,6 @@ * choices is checked, this will enable all choices. | ||
/** | ||
* Handle `i` keypress events. The `i` keypress toggles all choices. | ||
* Handle <kbd>i</kbd> keypress events. The <kbd>i</kbd> | ||
* keypress toggles all choices. If the pointer is inside a | ||
* choice group, only choices in that group will be toggled. | ||
* | ||
* @return {Number} Returns `choices.position` | ||
@@ -117,3 +121,5 @@ * @api public | ||
/** | ||
* Handle `down` keypress events. Moves the cursor down one row. | ||
* Handle <kdb>down</kdb> keypress events. <kdb>down</kdb> moves the | ||
* cursor down one row, and <kdb>shift</kdb>+<kdb>down</kdb> will | ||
* increase the number of rows visible in the terminal by one row. | ||
* | ||
@@ -126,2 +132,8 @@ * @return {Number} Returns the updated `choices.position`. | ||
pos = this.position(pos); | ||
if (key && key.shift === true) { | ||
if (this.options.expandChoices !== false) { | ||
return this.addRow(); | ||
} | ||
this.moveDown(pos); | ||
} | ||
return (pos < this.choices.length - 1) ? pos + 1 : 0; | ||
@@ -131,3 +143,5 @@ }; | ||
/** | ||
* Handle `up` keypress events. Moves the cursor up one row. | ||
* Handle <kdb>up</kdb> keypress events. <kdb>up</kdb> moves the | ||
* cursor up one row, and <kdb>shift</kdb>+<kdb>up</kdb> will | ||
* reduce the number of rows visible in the terminal by one row. | ||
* | ||
@@ -140,2 +154,8 @@ * @return {Number} Returns the updated `choices.position`. | ||
pos = this.position(pos); | ||
if (key && key.shift === true) { | ||
if (this.options.expandChoices !== false) { | ||
return this.removeRow(); | ||
} | ||
this.moveUp(pos); | ||
} | ||
return (pos > 0) ? pos - 1 : this.choices.length - 1; | ||
@@ -145,6 +165,55 @@ }; | ||
/** | ||
* Identity function for handling `enter` keypress events. This | ||
* is effectively a noop, since `enter` keypress events are typically | ||
* ignored to allow the `line` event to be handled when an answer is | ||
* submitted. | ||
* Move the currently selected item up. | ||
*/ | ||
Actions.prototype.moveUp = function(pos) { | ||
var len = this.choices.length; | ||
pos = this.position(pos); | ||
if (pos > 0) { | ||
this.choices.swap(pos - 1, pos); | ||
} else { | ||
this.choices.swap(pos, len - 1); | ||
} | ||
return pos; | ||
}; | ||
/** | ||
* Move the currently selected item down. | ||
*/ | ||
Actions.prototype.moveDown = function(pos) { | ||
var len = this.choices.length; | ||
pos = this.position(pos); | ||
if (pos < len - 1) { | ||
this.choices.swap(pos + 1, pos); | ||
} else { | ||
this.choices.swap(pos, 0); | ||
} | ||
return pos; | ||
}; | ||
/** | ||
* Move the currently selected item up. | ||
*/ | ||
Actions.prototype.addRow = function() { | ||
if (this.choices.options.limit < this.choices.length) { | ||
this.choices.options.limit++; | ||
} | ||
}; | ||
/** | ||
* Move the currently selected item up. | ||
*/ | ||
Actions.prototype.removeRow = function() { | ||
if (this.choices.options.limit > 0) { | ||
this.choices.options.limit--; | ||
} | ||
}; | ||
/** | ||
* Handle <kbd>enter</kbd> keypress events. By default this is a | ||
* noop since <kbd>enter</kbd> keypress events are typically ignored | ||
* to allow the `line` event to be handled when an answer is submitted. | ||
* | ||
@@ -160,3 +229,3 @@ * @return {Number} Returns `choices.position` | ||
/** | ||
* Helper for getting the current position. | ||
* Helper for getting the current corsor position. | ||
* | ||
@@ -163,0 +232,0 @@ * @param {Number} `pos` (optional) Current position |
{ | ||
"name": "prompt-actions", | ||
"description": "Action manager for prompt-base.", | ||
"version": "2.0.2", | ||
"version": "3.0.0", | ||
"homepage": "https://github.com/enquirer/prompt-actions", | ||
@@ -22,2 +22,15 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
}, | ||
"dependencies": { | ||
"debug": "^2.6.8" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^3.4.1", | ||
"is-windows": "^1.0.1", | ||
"prompt-choices": "^3.0.2", | ||
"gulp": "^3.9.1", | ||
"gulp-mocha": "^3.0.1", | ||
"gulp-istanbul": "^1.1.1", | ||
"gulp-eslint": "^3.0.1", | ||
"gulp-format-md": "^0.1.12" | ||
}, | ||
"keywords": [ | ||
@@ -40,26 +53,15 @@ "actions", | ||
"prompt-base", | ||
"prompt-choices" | ||
"prompt-choices", | ||
"prompt-sort", | ||
"prompt-grid" | ||
] | ||
}, | ||
"lint": { | ||
"reflinks": true | ||
}, | ||
"reflinks": [ | ||
"base-prompt", | ||
"prompt-base" | ||
] | ||
}, | ||
"devDependencies": { | ||
"mocha": "^3.4.1", | ||
"is-windows": "^1.0.1", | ||
"prompt-choices": "^3.0.2", | ||
"gulp": "^3.9.1", | ||
"gulp-mocha": "^3.0.1", | ||
"gulp-istanbul": "^1.1.1", | ||
"gulp-eslint": "^3.0.1", | ||
"gulp-format-md": "^0.1.12" | ||
}, | ||
"dependencies": { | ||
"debug": "^2.6.8" | ||
], | ||
"lint": { | ||
"reflinks": true | ||
} | ||
} | ||
} |
@@ -35,4 +35,6 @@ # prompt-actions [![NPM version](https://img.shields.io/npm/v/prompt-actions.svg?style=flat)](https://www.npmjs.com/package/prompt-actions) [![NPM monthly downloads](https://img.shields.io/npm/dm/prompt-actions.svg?style=flat)](https://npmjs.org/package/prompt-actions) [![NPM total downloads](https://img.shields.io/npm/dt/prompt-actions.svg?style=flat)](https://npmjs.org/package/prompt-actions) [![Linux Build Status](https://img.shields.io/travis/enquirer/prompt-actions.svg?style=flat&label=Travis)](https://travis-ci.org/enquirer/prompt-actions) | ||
* [enquirer](https://www.npmjs.com/package/enquirer): Intuitive, plugin-based prompt system for node.js. Much faster and lighter alternative to Inquirer, with all… [more](https://github.com/enquirer/enquirer) | [homepage](https://github.com/enquirer/enquirer "Intuitive, plugin-based prompt system for node.js. Much faster and lighter alternative to Inquirer, with all the same prompt types and more, but without the bloat.") | ||
* [prompt-base](https://www.npmjs.com/package/prompt-base): Base prompt module used for creating custom prompt types for Enquirer. | [homepage](https://github.com/enquirer/prompt-base "Base prompt module used for creating custom prompt types for Enquirer.") | ||
* [prompt-base](https://www.npmjs.com/package/prompt-base): Base prompt module used for creating custom prompts. | [homepage](https://github.com/enquirer/prompt-base "Base prompt module used for creating custom prompts.") | ||
* [prompt-choices](https://www.npmjs.com/package/prompt-choices): Create an array of multiple choice objects for use in prompts. | [homepage](https://github.com/enquirer/prompt-choices "Create an array of multiple choice objects for use in prompts.") | ||
* [prompt-grid](https://www.npmjs.com/package/prompt-grid): Prompt that allows the user to re-arrange the cells in a grid in the terminal. | [homepage](https://github.com/enquirer/prompt-grid "Prompt that allows the user to re-arrange the cells in a grid in the terminal.") | ||
* [prompt-sort](https://www.npmjs.com/package/prompt-sort): Prompt that allows the user to re-order items in a list of choices. | [homepage](https://github.com/enquirer/prompt-sort "Prompt that allows the user to re-order items in a list of choices.") | ||
@@ -77,2 +79,2 @@ ### Contributing | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 23, 2017._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 28, 2017._ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12380
223
78