prompt-actions
Advanced tools
Comparing version 1.0.0 to 1.1.0
49
index.js
@@ -30,8 +30,9 @@ 'use strict'; | ||
Actions.prototype.number = function(pos) { | ||
if (pos <= this.choices.length && pos >= 0) { | ||
this.choices.position = pos - 1; | ||
Actions.prototype.number = function(pos, key) { | ||
pos = key ? Number(key.value) : this.position(pos); | ||
if (pos >= 0 && pos <= this.choices.length) { | ||
this.position(--pos); | ||
this.choices.radio(); | ||
} | ||
return pos - 1; | ||
return pos; | ||
}; | ||
@@ -48,2 +49,3 @@ | ||
Actions.prototype.space = function(pos) { | ||
pos = this.position(pos); | ||
this.choices.radio(); | ||
@@ -75,3 +77,3 @@ return pos; | ||
Actions.prototype.tab = function(pos) { | ||
return pos; | ||
return this.position(pos); | ||
}; | ||
@@ -88,6 +90,6 @@ | ||
Actions.prototype.a = function() { | ||
Actions.prototype.a = function(pos) { | ||
this.choices[this.choices.all ? 'uncheck' : 'check'](); | ||
this.choices.update(); | ||
return this.choices.position; | ||
return this.position(pos); | ||
}; | ||
@@ -101,5 +103,6 @@ | ||
Actions.prototype.i = function() { | ||
Actions.prototype.i = function(pos) { | ||
this.choices.toggle(); | ||
return this.choices.position; | ||
this.choices.update(); | ||
return this.position(pos); | ||
}; | ||
@@ -114,3 +117,4 @@ | ||
Actions.prototype.down = function(pos) { | ||
Actions.prototype.down = function(pos, key) { | ||
pos = this.position(pos); | ||
return (pos < this.choices.length - 1) ? pos + 1 : 0; | ||
@@ -126,3 +130,4 @@ }; | ||
Actions.prototype.up = function(pos) { | ||
Actions.prototype.up = function(pos, key) { | ||
pos = this.position(pos); | ||
return (pos > 0) ? pos - 1 : this.choices.length - 1; | ||
@@ -141,7 +146,25 @@ }; | ||
Actions.prototype.enter = function(pos) { | ||
return pos; | ||
Actions.prototype.enter = function(pos, key) { | ||
return this.position(pos); | ||
}; | ||
/** | ||
* Helper for getting the current position. | ||
* | ||
* @param {Number} `pos` (optional) Current position | ||
* @return {Number} Returns given `pos` or `choices.position` | ||
* @api public | ||
*/ | ||
Actions.prototype.position = function(pos) { | ||
if (typeof pos === 'number') { | ||
if (pos >= 0 && pos <= this.choices.length) { | ||
this.choices.position = pos; | ||
} | ||
return pos; | ||
} | ||
return this.choices.position; | ||
}; | ||
/** | ||
* Expose `Actions` | ||
@@ -148,0 +171,0 @@ */ |
{ | ||
"name": "prompt-actions", | ||
"description": "Action manager for prompt-base.", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"homepage": "https://github.com/enquirer/prompt-actions", | ||
@@ -6,0 +6,0 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", |
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
9630
143