Comparing version 1.1.3 to 1.2.1
@@ -102,2 +102,5 @@ 'use strict'; | ||
}; | ||
Choices.prototype.find = function (func) { | ||
return _.find(this.choices, func); | ||
}; | ||
Choices.prototype.push = function () { | ||
@@ -104,0 +107,0 @@ var objs = _.map(arguments, function (val) { |
@@ -92,2 +92,4 @@ /** | ||
}); | ||
}, function (err) { | ||
return {isValid: err}; | ||
}); | ||
@@ -94,0 +96,0 @@ }).share(); |
@@ -69,2 +69,4 @@ /** | ||
events.spaceKey.takeUntil(validation.success).forEach(this.onSpaceKey.bind(this)); | ||
events.aKey.takeUntil(validation.success).forEach(this.onAllKey.bind(this)); | ||
events.iKey.takeUntil(validation.success).forEach(this.onInverseKey.bind(this)); | ||
@@ -89,3 +91,3 @@ // Init the prompt | ||
if (!this.spaceKeyPressed) { | ||
message += '(Press <space> to select)'; | ||
message += '(Press ' + chalk.cyan.bold('<space>') + ' to select, ' + chalk.cyan.bold('<a>') + ' to toggle all, ' + chalk.cyan.bold('<i>') + ' to inverse selection)'; | ||
} | ||
@@ -163,2 +165,26 @@ | ||
Prompt.prototype.onAllKey = function () { | ||
var shouldBeChecked = Boolean(this.opt.choices.find(function (choice) { | ||
return choice.type !== 'separator' && !choice.checked; | ||
})); | ||
this.opt.choices.forEach(function (choice) { | ||
if (choice.type !== 'separator') { | ||
choice.checked = shouldBeChecked; | ||
} | ||
}); | ||
this.render(); | ||
}; | ||
Prompt.prototype.onInverseKey = function () { | ||
this.opt.choices.forEach(function (choice) { | ||
if (choice.type !== 'separator') { | ||
choice.checked = !choice.checked; | ||
} | ||
}); | ||
this.render(); | ||
}; | ||
Prompt.prototype.toggleChoice = function (index) { | ||
@@ -165,0 +191,0 @@ var checked = this.opt.choices.getChoice(index).checked; |
@@ -10,2 +10,3 @@ /** | ||
var observe = require('../utils/events'); | ||
var rx = require('rx'); | ||
@@ -36,7 +37,10 @@ /** | ||
// Once user confirm (enter key) | ||
this.editorResult = new rx.Subject(); | ||
// Open Editor on "line" (Enter Key) | ||
var events = observe(this.rl); | ||
var submit = events.line.map(this.startExternalEditor.bind(this)); | ||
events.line.forEach(this.startExternalEditor.bind(this)); | ||
var validation = this.handleSubmitEvents(submit); | ||
// Trigger Validation when editor closes | ||
var validation = this.handleSubmitEvents(this.editorResult); | ||
validation.success.forEach(this.onEnd.bind(this)); | ||
@@ -82,7 +86,18 @@ validation.error.forEach(this.onError.bind(this)); | ||
Prompt.prototype.startExternalEditor = function () { | ||
this.currentText = ExternalEditor.edit(this.currentText); | ||
return this.currentText; | ||
// Pause Readline to prevent stdin and stdout from being modified while the editor is showing | ||
this.rl.pause(); | ||
ExternalEditor.editAsync(this.currentText, this.endExternalEditor.bind(this)); | ||
}; | ||
Prompt.prototype.endExternalEditor = function (error, result) { | ||
this.rl.resume(); | ||
if (error) { | ||
this.editorResult.onError(error); | ||
} else { | ||
this.editorResult.onNext(result); | ||
} | ||
}; | ||
Prompt.prototype.onEnd = function (state) { | ||
this.editorResult.dispose(); | ||
this.answer = state.value; | ||
@@ -89,0 +104,0 @@ this.status = 'answered'; |
@@ -63,2 +63,4 @@ /** | ||
var self = this; | ||
var events = observe(this.rl); | ||
@@ -71,3 +73,7 @@ events.normalizedUpKey.takeUntil(events.line).forEach(this.onUpKey.bind(this)); | ||
.map(this.getCurrentValue.bind(this)) | ||
.flatMap(runAsync(this.opt.filter)) | ||
.flatMap(function (value) { | ||
return runAsync(self.opt.filter)(value).catch(function (err) { | ||
return err; | ||
}); | ||
}) | ||
.forEach(this.onSubmit.bind(this)); | ||
@@ -74,0 +80,0 @@ |
@@ -35,4 +35,12 @@ 'use strict'; | ||
return e.key && e.key.name === 'space'; | ||
}).share(), | ||
aKey: keypress.filter(function (e) { | ||
return e.key && e.key.name === 'a'; | ||
}).share(), | ||
iKey: keypress.filter(function (e) { | ||
return e.key && e.key.name === 'i'; | ||
}).share() | ||
}; | ||
}; |
{ | ||
"name": "inquirer", | ||
"version": "1.1.3", | ||
"version": "1.2.1", | ||
"description": "A collection of common interactive command line user interfaces.", | ||
@@ -29,3 +29,3 @@ "author": "Simon Boudrias <admin@simonboudrias.com>", | ||
"cli-width": "^2.0.0", | ||
"external-editor": "^1.0.1", | ||
"external-editor": "^1.1.0", | ||
"figures": "^1.3.5", | ||
@@ -32,0 +32,0 @@ "lodash": "^4.3.0", |
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
68108
1823
Updatedexternal-editor@^1.1.0