From 0930c37675928ad3abe9c963d776f711dcd0ea92 Mon Sep 17 00:00:00 2001 From: Joe Walker Date: Fri, 3 Dec 2010 15:38:35 +0000 Subject: [PATCH] Rename Input to Cli. Extract CliUi as an interface. Add knowledge of cursor positioning to convert INCOMPLETE hints to INVALID if the cursor isnt in that hint. Many tidyups and tweaks as we create a test suite --- plugins/pilot/lib/cli.js | 169 +++++++++++++++++++++++++++------------ 1 file changed, 117 insertions(+), 52 deletions(-) diff --git a/plugins/pilot/lib/cli.js b/plugins/pilot/lib/cli.js index a747678f..b7bb1419 100644 --- a/plugins/pilot/lib/cli.js +++ b/plugins/pilot/lib/cli.js @@ -97,7 +97,7 @@ oop.inherits(ConversionHint, Hint); * @constructor */ function Argument(text, start, end, priorSpace) { - this.text = text; + this.setText(text); this.start = start; this.end = end; this.priorSpace = priorSpace; @@ -114,26 +114,55 @@ Argument.prototype = { }, setText: function(text) { + if (text == null) { + throw new Error('Illegal text for Argument: ' + text); + } this.text = text; } }; /** * Merge an array of arguments into a single argument. */ -Argument.mergeAll = function(argArray) { +Argument.merge = function(argArray, start, end) { + start = (start === undefined) ? 0 : start; + end = (end === undefined) ? argArray.length : end; + var joined; - argArray.forEach(function(arg) { + for (var i = start; i < end; i++) { + var arg = argArray[i]; if (!joined) { joined = arg; } else { joined = joined.merge(arg); } - }); + } return joined; }; +/** + * CLI / UI Interface + * The Cli interacts with the UI via an instance of CliUi. + * This implementation is designed as a template rather than to be used. + * It is expected that we will have a number of implementations of this: + * - A firebug/webkit inspector cli shim + * - A simple input[type=text] version + * - A possible Cloud9 UI version + * - A possible Skywriter UI version + * This class will probably need refactoring as time goes on. + * + * TODO: Who should own the Requisition? + */ +function CliUi() { +} +CliUi.prototype = { + getSelection: function() {}, + setHints: function() {}, + setRequisition: function() {} +}; + + /** * An object used during command line parsing to hold the various intermediate * data steps. @@ -143,7 +172,7 @@ Argument.mergeAll = function(argArray) { *

The other output value is input.requisition which gives access to an * args object for use in executing the final command. * - * The majority of the functions in this class are called in sequence by the + *

The majority of the functions in this class are called in sequence by the * constructor. Their task is to add to hints fill out the requisition. *

The general sequence is: