From c162fe3ce323a7b9f89722df6c00b21051794402 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Fri, 5 Feb 2016 14:49:33 +0100 Subject: [PATCH] Closes #528 - Add cancel interactive prompt functionality --- lib/utils/cli.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/utils/cli.js b/lib/utils/cli.js index 2118995b1..bae94b6f6 100644 --- a/lib/utils/cli.js +++ b/lib/utils/cli.js @@ -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