Merge pull request #572 from pmuens/add-cancel-interactive-prompt-functionality

Closes #528 - Add cancel interactive prompt functionality
This commit is contained in:
Austen 2016-02-05 06:56:52 -08:00
commit 8b6faf97e4

View File

@ -332,8 +332,11 @@ exports.select = function(message, choices, multi, doneLabel) {
selectStateDown(4);
} else if (key.name == 'return' || key.name == 'space' || key.name == 'enter') {
// Check if "done" option or ctrl was pressed.
if ((Select.state.choices[Select.state.index - 1].action
// Check if "cancel" option, "done" option or ctrl was pressed.
if (Select.state.choices[Select.state.index - 1].action
&& Select.state.choices[Select.state.index - 1].action.toLowerCase() === 'cancel') {
process.exit();
} else if ((Select.state.choices[Select.state.index - 1].action
&& Select.state.choices[Select.state.index - 1].action.toLowerCase() === 'done') || key.name == 'enter') {
process.stdin.removeListener('keypress', keypressHandler);
return Select._close();
@ -380,7 +383,12 @@ exports.select = function(message, choices, multi, doneLabel) {
{
action: 'Done',
label: Select.state.doneLabel,
});
},
{
action: 'Cancel',
label: 'Cancel'
}
);
}
// Log Message