diff --git a/ChangeLog b/ChangeLog index de3e9509..392b18d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -80,6 +80,8 @@ getJSONfromFileTable. * fix(socket) log level: debug -> info +* feature(console) jquery-terminal -> jq-console + 2012.04.22, v0.2.0 diff --git a/json/modules.json b/json/modules.json index 95fbefaa..e491a6b5 100644 --- a/json/modules.json +++ b/json/modules.json @@ -3,8 +3,7 @@ "menu", "view", "help", - "jq_console", - "terminal", { + "console", { "name": "storage", "data": [{ "name": "DropBox", diff --git a/lib/client/console.js b/lib/client/console.js index 9ba73d4e..9fd4281e 100644 --- a/lib/client/console.js +++ b/lib/client/console.js @@ -6,16 +6,20 @@ var CloudCmd, Util, DOM, $; function ConsoleProto(CloudCmd, Util, DOM){ var Name = 'Console', + Element, Key = CloudCmd.Key, Images = DOM.Images, Console = this; this.init = function(pCallBack){ + var lViewFunc = CloudCmd.View.show || CloudCmd.View; + Util.loadOnLoad([ Console.show, load, - CloudCmd.View, + lViewFunc, DOM.jqueryLoad, + DOM.socketLoad ]); DOM.Events.addKey(listener); @@ -24,31 +28,42 @@ var CloudCmd, Util, DOM, $; }; this.show = function(){ - var lElement; + var jqconsole; Images.showLoad({top:true}); - lElement = DOM.anyload({ - name : 'div', - className : 'console' - }); + if (!Element) { + Element = DOM.anyload({ + name : 'div', + className : 'console' + }); - $(lElement).console({ - promptLabel: '# ', - commandValidate : function(line){ - var lRet = line !== ""; - - return lRet; - }, - commandHandle : function(line){ - return line; - }, - autofocus : true, - animateScroll : false, - promptHistory : true, - }); + Console.jqconsole = + jqconsole = $(Element).jqconsole('', '# '); + // Abort prompt on Ctrl+Z. + jqconsole.RegisterShortcut('Z', function() { + jqconsole.AbortPrompt(); + handler(); + }); + + // Handle a command. + var handler = function(command) { + if (command) + CloudCmd.Socket.send(command); + + jqconsole.Prompt(true, handler); + }; + + // Initiate the first prompt. + handler(); + } - CloudCmd.View.show(lElement); + CloudCmd.View.show(Element, function(){ + var lEvent = DOM.Events.create('mouseup'), + lElement = $('.jqconsole-prompt')[0]; + + DOM.Events.dispatch(lEvent, lElement); + }); }; @@ -59,10 +74,11 @@ var CloudCmd, Util, DOM, $; function load(pCallBack){ Util.time(Name + ' load'); - var lDir = CloudCmd.LIBDIRCLIENT + 'terminal/jquery-console/', + var lDir = CloudCmd.LIBDIRCLIENT + 'terminal/jq-console/', lFiles = [ - lDir + 'jquery.console.js', - lDir + 'jquery.console.css' + lDir + 'jqconsole.js', + lDir + 'jqconsole.css', + CloudCmd.LIBDIRCLIENT + 'terminal/jquery-terminal/jquery-migrate-1.0.0.js' ]; DOM.anyLoadInParallel(lFiles, function(){ diff --git a/lib/client/jq_console.js b/lib/client/jq_console.js deleted file mode 100644 index 4e5d9c24..00000000 --- a/lib/client/jq_console.js +++ /dev/null @@ -1,138 +0,0 @@ -var CloudCmd, Util, DOM, $; -(function(CloudCmd, Util, DOM){ - 'use strict'; - - CloudCmd.Jq_console = new ConsoleProto(CloudCmd, Util, DOM); - - function ConsoleProto(CloudCmd, Util, DOM){ - var Name = 'Console', - Element, - Key = CloudCmd.Key, - Images = DOM.Images, - Console = this; - - this.init = function(pCallBack){ - var lViewFunc = CloudCmd.View.show || CloudCmd.View; - - Util.loadOnLoad([ - Console.show, - load, - lViewFunc, - DOM.jqueryLoad, - ]); - - DOM.Events.addKey(listener); - - delete Console.init; - }; - - this.show = function(){ - var jqconsole; - - Images.showLoad({top:true}); - - if (!Element) { - Element = DOM.anyload({ - name : 'div', - className : 'console' - }); - - jqconsole = $(Element).jqconsole('header', 'JS> '); - // Abort prompt on Ctrl+Z. - jqconsole.RegisterShortcut('Z', function() { - jqconsole.AbortPrompt(); - handler(); - }); - - // Move to line start Ctrl+A. - jqconsole.RegisterShortcut('A', function() { - jqconsole.MoveToStart(); - handler(); - }); - - // Move to line end Ctrl+E. - jqconsole.RegisterShortcut('E', function() { - jqconsole.MoveToEnd(); - handler(); - }); - - jqconsole.RegisterMatching('{', '}', 'brace'); - jqconsole.RegisterMatching('(', ')', 'paran'); - jqconsole.RegisterMatching('[', ']', 'bracket'); - // Handle a command. - var handler = function(command) { - if (command) { - try { - jqconsole.Write('==> ' + window.eval(command) + '\n'); - } catch (e) { - jqconsole.Write('ERROR: ' + e.message + '\n'); - } - } - jqconsole.Prompt(true, handler, function(command) { - // Continue line if can't compile the command. - try { - Function(command); - } catch (e) { - if (/[\[\{\(]$/.test(command)) { - return 1; - } else { - return 0; - } - } - return false; - }); - }; - - // Initiate the first prompt. - handler(); - } - - CloudCmd.View.show(Element, function(){ - var lEvent = DOM.Events.create('mouseup'), - lElement = $('.jqconsole-prompt')[0]; - - DOM.Events.dispatch(lEvent, lElement); - }); - }; - - - this.hide = function(){ - CloudCmd.View.hide(); - }; - - function load(pCallBack){ - Util.time(Name + ' load'); - - var lDir = CloudCmd.LIBDIRCLIENT + 'terminal/jq-console/', - lFiles = [ - lDir + 'jqconsole.js', - lDir + 'jqconsole.css', - CloudCmd.LIBDIRCLIENT + 'terminal/jquery-terminal/jquery-migrate-1.0.0.js' - ]; - - DOM.anyLoadInParallel(lFiles, function(){ - console.timeEnd(Name + ' load'); - - Util.exec(pCallBack); - }); - } - - function listener(pEvent){ - var lF10 = Key.F10, - lESC = Key.ESC, - lIsBind = Key.isBind(), - lKey = pEvent.keyCode; - - switch(lKey){ - case lF10: - Console.show(); - break; - case lESC: - Console.hide(); - break; - } - - } - } - -})(CloudCmd, Util, DOM); \ No newline at end of file diff --git a/lib/client/jquery-console.js b/lib/client/jquery-console.js new file mode 100644 index 00000000..9ba73d4e --- /dev/null +++ b/lib/client/jquery-console.js @@ -0,0 +1,93 @@ +var CloudCmd, Util, DOM, $; +(function(CloudCmd, Util, DOM){ + 'use strict'; + + CloudCmd.Console = new ConsoleProto(CloudCmd, Util, DOM); + + function ConsoleProto(CloudCmd, Util, DOM){ + var Name = 'Console', + Key = CloudCmd.Key, + Images = DOM.Images, + Console = this; + + this.init = function(pCallBack){ + Util.loadOnLoad([ + Console.show, + load, + CloudCmd.View, + DOM.jqueryLoad, + ]); + + DOM.Events.addKey(listener); + + delete Console.init; + }; + + this.show = function(){ + var lElement; + + Images.showLoad({top:true}); + + lElement = DOM.anyload({ + name : 'div', + className : 'console' + }); + + $(lElement).console({ + promptLabel: '# ', + commandValidate : function(line){ + var lRet = line !== ""; + + return lRet; + }, + commandHandle : function(line){ + return line; + }, + autofocus : true, + animateScroll : false, + promptHistory : true, + }); + + CloudCmd.View.show(lElement); + }; + + + this.hide = function(){ + CloudCmd.View.hide(); + }; + + function load(pCallBack){ + Util.time(Name + ' load'); + + var lDir = CloudCmd.LIBDIRCLIENT + 'terminal/jquery-console/', + lFiles = [ + lDir + 'jquery.console.js', + lDir + 'jquery.console.css' + ]; + + DOM.anyLoadInParallel(lFiles, function(){ + console.timeEnd(Name + ' load'); + + Util.exec(pCallBack); + }); + } + + function listener(pEvent){ + var lF10 = Key.F10, + lESC = Key.ESC, + lIsBind = Key.isBind(), + lKey = pEvent.keyCode; + + switch(lKey){ + case lF10: + Console.show(); + break; + case lESC: + Console.hide(); + break; + } + + } + } + +})(CloudCmd, Util, DOM); \ No newline at end of file diff --git a/lib/client/key.js b/lib/client/key.js index 6428b2fe..751cdfdb 100644 --- a/lib/client/key.js +++ b/lib/client/key.js @@ -170,7 +170,7 @@ var CloudCmd, Util, DOM; case Key.TRA: DOM.Images.showLoad({top: true}); - Util.exec(CloudCmd.Terminal); + Util.exec(CloudCmd.Console); break; case Key.SPACE: diff --git a/lib/client/socket.js b/lib/client/socket.js index 32041b78..fc5f7dca 100644 --- a/lib/client/socket.js +++ b/lib/client/socket.js @@ -1,5 +1,5 @@ /* module make possible connectoin thrue socket.io on a client */ -var CloudCmd, Util, DOM, io; +var CloudCmd, Util, DOM, jqconsole, io; (function(CloudCmd, Util, DOM){ 'use strict'; @@ -50,13 +50,23 @@ var CloudCmd, Util, DOM, io; }); } }); - + function outToTerminal(pMsg){ var lResult, lTerm; Terminal = getTerminal(); if(Terminal) lTerm = Terminal.Term; + else { + var lEcho = function(pResult){ + CloudCmd.Console.jqconsole.Write(pResult); + }; + + lTerm = { + echo : lEcho, + error : lEcho + }; + } if(lTerm){ var lStdout,