From ef8b02375a60bae70acb92d7974b1ea397511a12 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 11 Feb 2014 06:33:00 -0500 Subject: [PATCH] feature(console) update to v2.10.0 --- lib/client/console/ChangeLog | 8 + lib/client/console/README.md | 12 +- lib/client/console/jqconsole.jquery.json | 2 +- lib/client/console/karma.conf.js | 12 +- lib/client/console/lib/jqconsole.js | 20 +- lib/client/console/package.json | 5 +- lib/client/console/src/jqconsole.coffee | 432 ++++++++++--------- lib/client/console/test/matching-test.coffee | 29 ++ lib/client/console/test/misc-test.coffee | 65 +++ lib/client/console/test/prompt-test.coffee | 10 +- 10 files changed, 368 insertions(+), 227 deletions(-) create mode 100644 lib/client/console/test/matching-test.coffee create mode 100644 lib/client/console/test/misc-test.coffee diff --git a/lib/client/console/ChangeLog b/lib/client/console/ChangeLog index d566ccc0..bf4f4ec2 100644 --- a/lib/client/console/ChangeLog +++ b/lib/client/console/ChangeLog @@ -74,3 +74,11 @@ info. * Remove browser sniffing. Fix #37 #42 #53 * Update android support. Fix #41 * Add wrapper div for padding/styling of console. Fix #40 + +2014.2.8 Version 2.9.0 +* Fixed `GetColumn` method to return the column number up until the cursor. +* `Dump`: Add header contents in console dump and remove extra spaces. + +2014.2.8 Version 2.10.0 +* Add `Clear` method to clear the console + diff --git a/lib/client/console/README.md b/lib/client/console/README.md index 7b668e94..9ad7b073 100644 --- a/lib/client/console/README.md +++ b/lib/client/console/README.md @@ -15,10 +15,11 @@ queueing. The plugin has been tested on the following browsers: * IE 9+ -* Chrome 10+ -* Firefox 4+ -* Opera 11+ -* iOS 4+ +* Chrome +* Firefox +* Opera +* iOS Safari and Chrome +* Android Chrome ##Getting Started @@ -468,6 +469,9 @@ Resets the character matching configuration. Resets the shortcut configuration. +###jqconsole.Clear +Clears the console's content excluding the current prompt + ##Default Key Config The console responds to the followind keys and key combinations by default: diff --git a/lib/client/console/jqconsole.jquery.json b/lib/client/console/jqconsole.jquery.json index ad1331df..c3919fef 100644 --- a/lib/client/console/jqconsole.jquery.json +++ b/lib/client/console/jqconsole.jquery.json @@ -19,4 +19,4 @@ "dependencies": { "jquery": ">=1.5" } -} \ No newline at end of file +} diff --git a/lib/client/console/karma.conf.js b/lib/client/console/karma.conf.js index df3028a8..48c021ac 100644 --- a/lib/client/console/karma.conf.js +++ b/lib/client/console/karma.conf.js @@ -10,14 +10,24 @@ module.exports = function(config) { 'test/prompt-test.coffee', 'test/shortcuts-test.coffee', 'test/history-test.coffee', + 'test/matching-test.coffee', + 'test/misc-test.coffee', ], browsers: ['Chrome'], - reporters: ['dots'], + reporters: ['dots', 'coverage'], + preprocessors: { + 'lib/*.js': ['coverage'], + 'test/*.coffee': ['coffee'] + }, coffeePreprocessor: { // options passed to the coffee compiler options: { bare: false, } }, + coverageReporter: { + type : 'html', + dir : 'coverage/' + } }); }; diff --git a/lib/client/console/lib/jqconsole.js b/lib/client/console/lib/jqconsole.js index 80836fd9..96a16f4f 100644 --- a/lib/client/console/lib/jqconsole.js +++ b/lib/client/console/lib/jqconsole.js @@ -466,9 +466,11 @@ Licensed under the MIT license JQConsole.prototype.GetColumn = function() { var lines; + this.$prompt_right.detach(); this.$prompt_cursor.text(''); lines = this.$console.text().split(NEWLINE); this.$prompt_cursor.html(' '); + this.$prompt_cursor.after(this.$prompt_right); return lines[lines.length - 1].length; }; @@ -659,7 +661,7 @@ Licensed under the MIT license JQConsole.prototype.Dump = function() { var $elems, elem; - $elems = this.$console.find("." + CLASS_HEADER).nextUntil("." + CLASS_PROMPT); + $elems = this.$console.find("." + CLASS_HEADER).nextUntil("." + CLASS_PROMPT).addBack(); return ((function() { var _i, _len, _results; _results = []; @@ -672,7 +674,7 @@ Licensed under the MIT license } } return _results; - })()).join(' '); + })()).join(''); }; JQConsole.prototype.GetState = function() { @@ -708,6 +710,12 @@ Licensed under the MIT license return void 0; }; + JQConsole.prototype.Clear = function() { + this.$console.find("." + CLASS_HEADER).nextUntil("." + CLASS_PROMPT).addBack().text(''); + this.$prompt_cursor.detach(); + return this.$prompt_after.before(this.$prompt_cursor); + }; + /*------------------------ Private Methods -------------------------------*/ @@ -1277,14 +1285,6 @@ Licensed under the MIT license } }; - JQConsole.prototype._outerHTML = function($elem) { - if (document.body.outerHTML) { - return $elem.get(0).outerHTML; - } else { - return $(EMPTY_DIV).append($elem.eq(0).clone()).html(); - } - }; - JQConsole.prototype._Wrap = function($elem, index, cls) { var html, text; text = $elem.html(); diff --git a/lib/client/console/package.json b/lib/client/console/package.json index 369274ea..8b4e6b28 100644 --- a/lib/client/console/package.json +++ b/lib/client/console/package.json @@ -1,6 +1,6 @@ { "name": "jq-console", - "version": "2.8.0", + "version": "2.10.0", "description": "Feature complete web terminal", "main": "jqconsole.min.js", "directories": { @@ -35,6 +35,7 @@ "karma-requirejs": "~0.2.1", "karma-phantomjs-launcher": "~0.1.1", "karma": "~0.10.9", - "karma-mocha": "~0.1.1" + "karma-mocha": "~0.1.1", + "karma-coverage": "~0.1.5" } } diff --git a/lib/client/console/src/jqconsole.coffee b/lib/client/console/src/jqconsole.coffee index 0230629c..bbbcc0e3 100644 --- a/lib/client/console/src/jqconsole.coffee +++ b/lib/client/console/src/jqconsole.coffee @@ -48,21 +48,21 @@ DEFAULT_PROMPT_CONINUE_LABEL = '... ' # The default number of spaces inserted when indenting. DEFAULT_INDENT_WIDTH = 2 -CLASS_ANSI = "#{CLASS_PREFIX}ansi-" +CLASS_ANSI = "#{CLASS_PREFIX}ansi-" ESCAPE_CHAR = '\x1B' ESCAPE_SYNTAX = /\[(\d*)(?:;(\d*))*m/ class Ansi COLORS: ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'] - + constructor: -> @klasses = []; - + _append: (klass) => klass = "#{CLASS_ANSI}#{klass}" if @klasses.indexOf(klass) is -1 @klasses.push klass - + _remove: (klasses...) => for klass in klasses if klass in ['fonts', 'color', 'background-color'] @@ -70,15 +70,15 @@ class Ansi else klass = "#{CLASS_ANSI}#{klass}" @klasses = (cls for cls in @klasses when cls isnt klass) - + _color: (i) => @COLORS[i] - + _style: (code) => code = 0 if code == '' code = parseInt code - + return if isNaN code - + switch code when 0 then @klasses = [] when 1 then @_append 'bold' @@ -113,27 +113,27 @@ class Ansi when 53 then @_append 'overline' when 54 then @_remove 'framed' when 55 then @_remove 'overline' - + getClasses: => @klasses.join ' ' - + _openSpan: (text) => "#{text}" _closeSpan: (text) => "#{text}" - + stylize: (text) => text = @_openSpan text - + i = 0 while (i = text.indexOf(ESCAPE_CHAR ,i)) and i isnt -1 if d = text[i...].match ESCAPE_SYNTAX @_style code for code in d[1...] text = @_closeSpan(text[0...i]) + @_openSpan text[i + 1 + d[0].length...] else i++ - - return @_closeSpan text - + + return @_closeSpan text + # Helper functions spanHtml = (klass, content) -> "#{content or ''}" - + class JQConsole # Creates a console. # @arg container: The DOM element into which the console is inserted. @@ -143,21 +143,21 @@ class JQConsole # Defaults to DEFAULT_PROMPT_LABEL. # @arg prompt_continue: The label to show before continuation lines of the # command prompt. Optional. Defaults to DEFAULT_PROMPT_CONINUE_LABEL. - constructor: (@container, header, prompt_label, prompt_continue_label) -> + constructor: (outer_container, header, prompt_label, prompt_continue_label) -> # Mobile devices supported sniff. @isMobile = !!navigator.userAgent.match /iPhone|iPad|iPod|Android/i @isIos = !!navigator.userAgent.match /iPhone|iPad|iPod/i @isAndroid = !!navigator.userAgent.match /Android/i - + @$window = $(window) - + # The header written when the console is reset. @header = header or '' # The prompt label used by Prompt(). @prompt_label_main = if typeof prompt_label == 'string' - prompt_label - else + prompt_label + else DEFAULT_PROMPT_LABEL @prompt_label_continue = (prompt_continue_label or DEFAULT_PROMPT_CONINUE_LABEL) @@ -193,60 +193,76 @@ class JQConsole # A table of custom shortcuts, mapping character codes to callbacks. @shortcuts = {} - + + @$container = $('
').appendTo outer_container + @$container.css + 'top': 0 + 'left': 0 + 'right': 0 + 'bottom': 0 + 'position': 'absolute' + 'overflow': 'auto' + # The main console area. Everything else happens inside this. - @$console = $('
').appendTo @container
-    @$console.css 
-      position: 'absolute'
-      top: 0
-      bottom: 0
-      right: 0
-      left: 0
-      margin: 0
-      overflow: 'auto'
+    @$console = $('
').appendTo @$container
+    @$console.css
+      'margin': 0
+      'position': 'relative'
+      'min-height': '100%'
+      'box-sizing': 'border-box'
+      '-moz-box-sizing': 'border-box'
+      '-webkit-box-sizing': 'border-box'
 
     # Whether the console currently has focus.
     @$console_focused = true
-    
+
     # On screen somehow invisible textbox for input.
     # Copied from codemirror2, this works for both mobile and desktop browsers.
-    @$input_container = $(EMPTY_DIV).appendTo @container
+    @$input_container = $(EMPTY_DIV).appendTo @$container
     @$input_container.css
-      position: 'relative'
+      position: 'absolute'
       width: 1
       height: 0
       overflow: 'hidden'
-    @$input_source = $('