From b7fcf4781182ffca3c95438762ba8951dc2eef53 Mon Sep 17 00:00:00 2001 From: Jordan Mack Date: Wed, 10 Feb 2016 01:40:50 -0800 Subject: [PATCH] Add hotkeys to dash for select all, select none, select functions, and select endpoints. --- lib/utils/cli.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/utils/cli.js b/lib/utils/cli.js index 063178d7c..5277c1f53 100644 --- a/lib/utils/cli.js +++ b/lib/utils/cli.js @@ -46,6 +46,8 @@ exports.quickHelp = function() { let text = ''; text = text + 'Use the , , , , , and keys to navigate.' + os.EOL; text = text + 'Press to select/deselect, or to select/deselect and move down.' + os.EOL; + text = text + 'Press + a to select all, and + d to deselect all.' + os.EOL; + text = text + 'Press + f to select all functions, and + e to select all endpoints.' + os.EOL; text = text + 'Press + to immediately deploy selected.' + os.EOL; text = text + 'Press to cancel.' + os.EOL; @@ -312,6 +314,42 @@ exports.select = function(message, choices, multi, doneLabel) { return Select._render(); }; + // Select/delselect all choices. + let selectChoicesAll = function(selected) { + // Cycle through all choices. + for(let i = 0; i < Select.state.choices.length; ++i) + { + // If the choice is not a spacer and not an action. + if(!Select.state.choices[i].spacer && !Select.state.choices[i].action) + // Mark the choice as the specified selected state. + Select.state.choices[i].toggled = selected; + } + + // Render + return Select._render(); + }; + + // Select all choices of a specific type. + let selectChoicesAllType = function(type) { + // Cycle through all choices. + for(let i = 0; i < Select.state.choices.length; ++i) + { + // If the choice is not a spacer and not an action. + if(!Select.state.choices[i].spacer && !Select.state.choices[i].action) + { + // If the choice type matches the specified type. + if(Select.state.choices[i].type && Select.state.choices[i].type === type) + { + // Mark as selected. + Select.state.choices[i].toggled = true; + } + } + } + + // Render + return Select._render(); + }; + if( !key ) return Select._render; // Handle ctrl + c. @@ -331,7 +369,18 @@ exports.select = function(message, choices, multi, doneLabel) { selectStateDown(); } else if (key.name == 'pagedown') { selectStateDown(4); - } else if (key.name == 'return' || key.name == 'space' || key.name == 'escape' || key.name == 'enter') { + } else if (key.ctrl && key.name == 'a') { + selectChoicesAll(true); + } else if (key.ctrl && key.name == 'd') { + selectChoicesAll(false); + } else if (key.ctrl && key.name == 'e') { + selectChoicesAllType('endpoint'); + } else if (key.ctrl && key.name == 'f') { + selectChoicesAllType('function'); + } else if (key.name == 'return' || + key.name == 'space' || + key.name == 'escape' || + key.name == 'enter') { // Check if "cancel" option, "done" option or ctrl was pressed. if (Select.state.choices[Select.state.index - 1].action