From 75c58a98c527f7c7b6baf3822e28a3e8e5e5d612 Mon Sep 17 00:00:00 2001 From: Jonathan Channon Date: Sat, 22 Feb 2014 10:57:16 +0000 Subject: [PATCH 01/15] Made last command an array --- html/panel.html | 2 +- main.js | 89 ++++++++++++++++++++++++++----------------------- 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/html/panel.html b/html/panel.html index 4e68898..61a025c 100644 --- a/html/panel.html +++ b/html/panel.html @@ -1,6 +1,6 @@
-
+
Terminal:  diff --git a/main.js b/main.js index b82e41f..ce365a5 100644 --- a/main.js +++ b/main.js @@ -62,12 +62,13 @@ define(function (require, exports, module) { * The ConnectionManager helps to build and run request to execute a file on the serverside */ var ConnectionManager = { - - last: { - command: null, - cwd: null - }, - + + last: [], + // { + // command: null, + // cwd: null + // }, + // /** * Creates a new EventSource * @@ -79,28 +80,32 @@ define(function (require, exports, module) { "new": function (command, useCurrentCwd, cwd) { if (source && source.close) source.close(); - + // Current document var doc = DocumentManager.getCurrentDocument(); - if(!doc.file.isFile) return; - + if (!doc.file.isFile) return; + // Build url var url = "http://" + config.host + ":" + config.port + "/?command=" + encodeURIComponent(command); var dir = null; - if(useCurrentCwd) { + if (useCurrentCwd) { dir = doc.file.parentPath; - } else if(cwd) { + } else if (cwd) { dir = cwd; } - - if(dir !== null) { + + if (dir !== null) { url += "&cwd=" + encodeURIComponent(dir); } - + // Store the last command and cwd - this.last.command = command; - this.last.cwd = dir; - + this.last[0] = { + command: null, + cwd: null + }; + this.last[0].command = command; + this.last[0].cwd = dir; + // Server should be running source = new EventSource(url); @@ -111,50 +116,50 @@ define(function (require, exports, module) { source.close(); Panel.write("Program exited."); }, false); - + Panel.show(command); Panel.clear(); }, - + newNpm: function (command) { - + var npmBin = get("npm"); - if(!npmBin) { + if (!npmBin) { npmBin = "npm"; } else { // Add quotation because windows paths can contain spaces npmBin = '"' + npmBin + '"'; } - + this.new(npmBin + " " + command, true); - + }, - + newNode: function () { - + var nodeBin = get("node"); - if(!nodeBin) { + if (!nodeBin) { nodeBin = "node"; } else { // Add quotation because windows paths can contain spaces nodeBin = '"' + nodeBin + '"'; } - + // Current document var doc = DocumentManager.getCurrentDocument(); - if(!doc.file.isFile) return; - + if (!doc.file.isFile) return; + this.new(nodeBin + ' "' + doc.file.fullPath + '"', true); - + }, - + rerun: function () { - + var last = this.last; - if(last.command === null) return; - - this.new(last.command, false, last.cwd); - + if (last[0].command === null) return; + + this.new(last[0].command, false, last[0].cwd); + }, /** @@ -363,10 +368,10 @@ define(function (require, exports, module) { save = document.querySelector("." + NODE_INSTALL_DIALOG_ID + " .save"); name.focus(); - + } }, - + /** * The exec modal is used to execute a command * HTML: html/modal-install.html @@ -406,7 +411,7 @@ define(function (require, exports, module) { } // Should it be executed in the current working directory - var useCwd = !!cwd.checked; + var useCwd = !! cwd.checked; ConnectionManager.new(command.value, useCwd); @@ -415,7 +420,7 @@ define(function (require, exports, module) { // It's important to get the elements after the modal is rendered but before the done event var command = document.querySelector("." + NODE_EXEC_DIALOG_ID + " .command"), cwd = document.querySelector("." + NODE_EXEC_DIALOG_ID + " .cwd"); - + command.focus(); } @@ -436,7 +441,7 @@ define(function (require, exports, module) { CommandManager.register("Run", RUN_CMD_ID, function () { ConnectionManager.newNode(); }); - CommandManager.register("Execute command", EXEC_CMD_ID, function() { + CommandManager.register("Execute command", EXEC_CMD_ID, function () { Dialog.exec.show(); }); CommandManager.register("Run as npm start", RUN_NPM_START_CMD_ID, function () { @@ -471,4 +476,4 @@ define(function (require, exports, module) { NodeMenu.addMenuDivider(); NodeMenu.addMenuItem(CONFIG_CMD_ID); -}); +}); \ No newline at end of file From 1e6547a3ff3d7e85da816762debfb2b2575a5702 Mon Sep 17 00:00:00 2001 From: Jonathan Channon Date: Sat, 22 Feb 2014 11:23:31 +0000 Subject: [PATCH 02/15] unshifted and popped items in last command array --- main.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index ce365a5..40d6a56 100644 --- a/main.js +++ b/main.js @@ -99,12 +99,13 @@ define(function (require, exports, module) { } // Store the last command and cwd - this.last[0] = { - command: null, - cwd: null + var lastCommand = { + command: command, + cwd: dir }; - this.last[0].command = command; - this.last[0].cwd = dir; + var lastCommandLength = this.last.unshift(lastCommand); + if (lastCommandLength > 10) + this.last.pop(); // Server should be running source = new EventSource(url); From 8e43a47456cdbdadefcb13fbc6da4d56f7764fc4 Mon Sep 17 00:00:00 2001 From: Jonathan Channon Date: Sat, 22 Feb 2014 11:48:29 +0000 Subject: [PATCH 03/15] added textbox to execute commands --- html/panel.html | 2 ++ main.js | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/html/panel.html b/html/panel.html index 61a025c..32da667 100644 --- a/html/panel.html +++ b/html/panel.html @@ -4,6 +4,8 @@
Terminal:  + + »
diff --git a/main.js b/main.js index 40d6a56..c4b90a3 100644 --- a/main.js +++ b/main.js @@ -64,10 +64,7 @@ define(function (require, exports, module) { var ConnectionManager = { last: [], - // { - // command: null, - // cwd: null - // }, + // /** * Creates a new EventSource @@ -261,6 +258,10 @@ define(function (require, exports, module) { document.querySelector("#" + Panel.id + " .action-rerun").addEventListener("click", function () { ConnectionManager.rerun(); }); + document.querySelector("#" + Panel.id + " .action-execute").addEventListener("click", function () { + var cmd = Panel.get(".cmd-value").value; + ConnectionManager.new(cmd, true, null); + }); var Dialog = { /** From 83b56cd1c6c2d38bbd89a9d4f7aba386df4f95e6 Mon Sep 17 00:00:00 2001 From: Jonathan Channon Date: Sat, 22 Feb 2014 12:35:54 +0000 Subject: [PATCH 04/15] add new menu item to show terminal and removed old exec command menu item --- main.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index c4b90a3..6ed10d8 100644 --- a/main.js +++ b/main.js @@ -164,7 +164,9 @@ define(function (require, exports, module) { * Close the current connection if server is started */ exit: function () { - source.close(); + if (source) + source.close(); + Panel.hide(); } }; @@ -439,7 +441,9 @@ define(function (require, exports, module) { RUN_NPM_TEST_CMD_ID = "brackets-nodejs.run_npm_test", RUN_NPM_INSTALL_CMD_ID = "brackets-nodejs.run_npm_install", INSTALL_CMD_ID = "brackets-nodejs.install", - CONFIG_CMD_ID = "brackets-nodejs.config"; + CONFIG_CMD_ID = "brackets-nodejs.config", + SHOW_TERMINAL = "brackets-nodejs.showterminal"; + CommandManager.register("Run", RUN_CMD_ID, function () { ConnectionManager.newNode(); }); @@ -465,9 +469,14 @@ define(function (require, exports, module) { Dialog.settings.show(); }); + CommandManager.register("Show Terminal", SHOW_TERMINAL, function () { + Panel.show(); + Panel.clear(); + }); NodeMenu.addMenuItem(RUN_CMD_ID, "Alt-N"); - NodeMenu.addMenuItem(EXEC_CMD_ID); + //NodeMenu.addMenuItem(EXEC_CMD_ID); + NodeMenu.addMenuItem(SHOW_TERMINAL, "Alt-T"); NodeMenu.addMenuDivider(); NodeMenu.addMenuItem(RUN_NPM_START_CMD_ID); NodeMenu.addMenuItem(RUN_NPM_STOP_CMD_ID); From c55d09da146cd1a1e298ec76c25e5050bca10d7d Mon Sep 17 00:00:00 2001 From: Jonathan Channon Date: Sat, 22 Feb 2014 14:09:28 +0000 Subject: [PATCH 05/15] arrow up key using last command array --- html/panel.html | 2 +- main.js | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/html/panel.html b/html/panel.html index 32da667..2566106 100644 --- a/html/panel.html +++ b/html/panel.html @@ -3,7 +3,7 @@
Terminal:  - + »
diff --git a/main.js b/main.js index 6ed10d8..fac1139 100644 --- a/main.js +++ b/main.js @@ -190,7 +190,7 @@ define(function (require, exports, module) { */ show: function (command) { this.panel.style.display = "block"; - this.commandTitle.textContent = command; + //this.commandTitle.textContent = command; EditorManager.resizeEditor(); }, hide: function () { @@ -231,12 +231,26 @@ define(function (require, exports, module) { Panel.height = Panel.height + (Panel.y - e.pageY); }, - y: 0 + + keyup: function (e) { + if (e.keyCode === 38) { + if (Panel.currentLastIndex >= ConnectionManager.last.length) { + Panel.currentLastIndex = ConnectionManager.last.length - 1; + } + var cmd = ConnectionManager.last[Panel.currentLastIndex].command; + Panel.get(".cmd-value").value = cmd; + Panel.currentLastIndex++; + } else if (e.keyCode === 40) { + + } + }, + y: 0, + currentLastIndex: 0 }; // Still resizing Panel.panel = document.getElementById(Panel.id); - Panel.commandTitle = Panel.get(".cmd"); + //Panel.commandTitle = Panel.get(".cmd"); Panel.pre = Panel.get(".table-container pre"); Panel.get(".resize").addEventListener("mousedown", function (e) { @@ -246,6 +260,9 @@ define(function (require, exports, module) { document.addEventListener("mouseup", Panel.mouseup); }); + Panel.get(".cmd-value").addEventListener("keyup", function (e) { + document.addEventListener("keyup", Panel.keyup); + }); /** * Terminal buttons From ed33b86e5c5791e95ffacabd3bb43442cc77ff14 Mon Sep 17 00:00:00 2001 From: Jonathan Channon Date: Sat, 22 Feb 2014 14:14:49 +0000 Subject: [PATCH 06/15] arrow down key using last command array --- main.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index fac1139..53ae5a2 100644 --- a/main.js +++ b/main.js @@ -237,11 +237,22 @@ define(function (require, exports, module) { if (Panel.currentLastIndex >= ConnectionManager.last.length) { Panel.currentLastIndex = ConnectionManager.last.length - 1; } + if (Panel.currentLastIndex <= 0) { + Panel.currentLastIndex = 0; + } var cmd = ConnectionManager.last[Panel.currentLastIndex].command; Panel.get(".cmd-value").value = cmd; Panel.currentLastIndex++; } else if (e.keyCode === 40) { - + if (Panel.currentLastIndex >= ConnectionManager.last.length) { + Panel.currentLastIndex = ConnectionManager.last.length - 1; + } + if (Panel.currentLastIndex <= 0) { + Panel.currentLastIndex = 0; + } + var cmd = ConnectionManager.last[Panel.currentLastIndex].command; + Panel.get(".cmd-value").value = cmd; + Panel.currentLastIndex--; } }, y: 0, From d46dd33697afb5fb507019f0f93cb7c94ea2aec1 Mon Sep 17 00:00:00 2001 From: Jonathan Channon Date: Sat, 22 Feb 2014 14:21:54 +0000 Subject: [PATCH 07/15] on enter execute command --- main.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 53ae5a2..fbf6cf0 100644 --- a/main.js +++ b/main.js @@ -253,6 +253,8 @@ define(function (require, exports, module) { var cmd = ConnectionManager.last[Panel.currentLastIndex].command; Panel.get(".cmd-value").value = cmd; Panel.currentLastIndex--; + } else if (e.keyCode === 13) { + execute(); } }, y: 0, @@ -289,9 +291,13 @@ define(function (require, exports, module) { ConnectionManager.rerun(); }); document.querySelector("#" + Panel.id + " .action-execute").addEventListener("click", function () { + execute(); + }); + + function execute() { var cmd = Panel.get(".cmd-value").value; ConnectionManager.new(cmd, true, null); - }); + } var Dialog = { /** From f1942ed03a05415c12755edbab8fb3be599af99b Mon Sep 17 00:00:00 2001 From: Jonathan Channon Date: Sat, 22 Feb 2014 16:21:44 +0000 Subject: [PATCH 08/15] Added check for existence of items in last array --- main.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.js b/main.js index fbf6cf0..5409c63 100644 --- a/main.js +++ b/main.js @@ -234,16 +234,24 @@ define(function (require, exports, module) { keyup: function (e) { if (e.keyCode === 38) { + if (ConnectionManager.last.length === 0) { + return; + } if (Panel.currentLastIndex >= ConnectionManager.last.length) { Panel.currentLastIndex = ConnectionManager.last.length - 1; } if (Panel.currentLastIndex <= 0) { Panel.currentLastIndex = 0; } + + var cmd = ConnectionManager.last[Panel.currentLastIndex].command; Panel.get(".cmd-value").value = cmd; Panel.currentLastIndex++; } else if (e.keyCode === 40) { + if (ConnectionManager.last.length === 0) { + return; + } if (Panel.currentLastIndex >= ConnectionManager.last.length) { Panel.currentLastIndex = ConnectionManager.last.length - 1; } From e964260ef15a3f82e833a3494fbed9f13c748908 Mon Sep 17 00:00:00 2001 From: Jonathan Channon Date: Sat, 22 Feb 2014 16:30:22 +0000 Subject: [PATCH 09/15] removed redundant code --- html/modal-exec.html | 12 -------- html/panel.html | 1 - main.js | 73 +++++--------------------------------------- 3 files changed, 7 insertions(+), 79 deletions(-) delete mode 100644 html/modal-exec.html diff --git a/html/modal-exec.html b/html/modal-exec.html deleted file mode 100644 index f28967b..0000000 --- a/html/modal-exec.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - -
- -
- -
\ No newline at end of file diff --git a/html/panel.html b/html/panel.html index 2566106..6520e75 100644 --- a/html/panel.html +++ b/html/panel.html @@ -3,7 +3,6 @@
Terminal:  - »
diff --git a/main.js b/main.js index 5409c63..3cccd01 100644 --- a/main.js +++ b/main.js @@ -160,6 +160,11 @@ define(function (require, exports, module) { }, + execute: function () { + var cmd = Panel.get(".cmd-value").value; + ConnectionManager.new(cmd, true, null); + }, + /** * Close the current connection if server is started */ @@ -262,7 +267,7 @@ define(function (require, exports, module) { Panel.get(".cmd-value").value = cmd; Panel.currentLastIndex--; } else if (e.keyCode === 13) { - execute(); + ConnectionManager.execute(); } }, y: 0, @@ -299,14 +304,9 @@ define(function (require, exports, module) { ConnectionManager.rerun(); }); document.querySelector("#" + Panel.id + " .action-execute").addEventListener("click", function () { - execute(); + ConnectionManager.execute(); }); - function execute() { - var cmd = Panel.get(".cmd-value").value; - ConnectionManager.new(cmd, true, null); - } - var Dialog = { /** * The settings modal is used to configure the path to node's and node's binary @@ -417,67 +417,12 @@ define(function (require, exports, module) { } }, - - /** - * The exec modal is used to execute a command - * HTML: html/modal-install.html - */ - exec: { - - /** - * HTML put inside the dialog - */ - html: require("text!html/modal-exec.html"), - - /** - * Opens up the modal - */ - show: function () { - - Dialogs.showModalDialog( - NODE_EXEC_DIALOG_ID, - "Execute command", - this.html, [{ - className: Dialogs.DIALOG_BTN_CLASS_PRIMARY, - id: Dialogs.DIALOG_BTN_OK, - text: "Run" - }, { - className: Dialogs.DIALOG_BTN_CLASS_NORMAL, - id: Dialogs.DIALOG_BTN_CANCEL, - text: "Cancel" - }] - ).done(function (id) { - - if (id !== "ok") return; - - // Command musn't be empty - if (command.value == "") { - Dialogs.showModalDialog(Dialogs.DIALOG_ID_ERROR, "Error", "Please enter a command"); - return; - } - - // Should it be executed in the current working directory - var useCwd = !! cwd.checked; - - ConnectionManager.new(command.value, useCwd); - - }); - - // It's important to get the elements after the modal is rendered but before the done event - var command = document.querySelector("." + NODE_EXEC_DIALOG_ID + " .command"), - cwd = document.querySelector("." + NODE_EXEC_DIALOG_ID + " .cwd"); - - command.focus(); - - } - } }; /** * Menu */ var RUN_CMD_ID = "brackets-nodejs.run", - EXEC_CMD_ID = "brackets-nodejs.exec", RUN_NPM_START_CMD_ID = "brackets-nodejs.run_npm_start", RUN_NPM_STOP_CMD_ID = "brackets-nodejs.run_npm_stop", RUN_NPM_TEST_CMD_ID = "brackets-nodejs.run_npm_test", @@ -489,9 +434,6 @@ define(function (require, exports, module) { CommandManager.register("Run", RUN_CMD_ID, function () { ConnectionManager.newNode(); }); - CommandManager.register("Execute command", EXEC_CMD_ID, function () { - Dialog.exec.show(); - }); CommandManager.register("Run as npm start", RUN_NPM_START_CMD_ID, function () { ConnectionManager.newNpm("start"); }); @@ -517,7 +459,6 @@ define(function (require, exports, module) { }); NodeMenu.addMenuItem(RUN_CMD_ID, "Alt-N"); - //NodeMenu.addMenuItem(EXEC_CMD_ID); NodeMenu.addMenuItem(SHOW_TERMINAL, "Alt-T"); NodeMenu.addMenuDivider(); NodeMenu.addMenuItem(RUN_NPM_START_CMD_ID); From eb638446bc3909495d5180fe1323fff21daf282d Mon Sep 17 00:00:00 2001 From: Jonathan Channon Date: Sat, 22 Feb 2014 16:36:54 +0000 Subject: [PATCH 10/15] tidied keyup --- main.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.js b/main.js index 3cccd01..f22c828 100644 --- a/main.js +++ b/main.js @@ -276,7 +276,6 @@ define(function (require, exports, module) { // Still resizing Panel.panel = document.getElementById(Panel.id); - //Panel.commandTitle = Panel.get(".cmd"); Panel.pre = Panel.get(".table-container pre"); Panel.get(".resize").addEventListener("mousedown", function (e) { @@ -287,7 +286,7 @@ define(function (require, exports, module) { }); Panel.get(".cmd-value").addEventListener("keyup", function (e) { - document.addEventListener("keyup", Panel.keyup); + return Panel.keyup; }); /** From 4d0b70c81b0cce1213bbcf5e0336c9cf839dafaa Mon Sep 17 00:00:00 2001 From: Jonathan Channon Date: Sat, 22 Feb 2014 17:02:09 +0000 Subject: [PATCH 11/15] added cursor styling for executing command --- html/panel.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/panel.html b/html/panel.html index 6520e75..7e0e329 100644 --- a/html/panel.html +++ b/html/panel.html @@ -4,7 +4,7 @@
Terminal:  - » + »
From dc3fcfdda6554bbd2bd7d74e53418368f5ff7710 Mon Sep 17 00:00:00 2001 From: Jonathan Channon Date: Sat, 22 Feb 2014 17:06:21 +0000 Subject: [PATCH 12/15] tidied keyup again --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index f22c828..c412aee 100644 --- a/main.js +++ b/main.js @@ -286,7 +286,7 @@ define(function (require, exports, module) { }); Panel.get(".cmd-value").addEventListener("keyup", function (e) { - return Panel.keyup; + Panel.keyup(e); }); /** From 06c0a1d4d67764915cfcda409d5c7f3bc8ffb948 Mon Sep 17 00:00:00 2001 From: Jonathan Channon Date: Sat, 22 Feb 2014 17:13:45 +0000 Subject: [PATCH 13/15] removed re-run item and added check for terminating command --- html/panel.html | 1 - main.js | 20 +++++--------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/html/panel.html b/html/panel.html index 7e0e329..2be56e1 100644 --- a/html/panel.html +++ b/html/panel.html @@ -7,7 +7,6 @@ »
- ×
diff --git a/main.js b/main.js index c412aee..a3686b7 100644 --- a/main.js +++ b/main.js @@ -151,15 +151,6 @@ define(function (require, exports, module) { }, - rerun: function () { - - var last = this.last; - if (last[0].command === null) return; - - this.new(last[0].command, false, last[0].cwd); - - }, - execute: function () { var cmd = Panel.get(".cmd-value").value; ConnectionManager.new(cmd, true, null); @@ -168,10 +159,12 @@ define(function (require, exports, module) { /** * Close the current connection if server is started */ - exit: function () { + exit: function (terminate) { if (source) source.close(); - Panel.hide(); + if (terminate) { + Panel.write('Terminal command aborted.') + } } }; @@ -297,10 +290,7 @@ define(function (require, exports, module) { Panel.hide(); }); document.querySelector("#" + Panel.id + " .action-terminate").addEventListener("click", function () { - ConnectionManager.exit(); - }); - document.querySelector("#" + Panel.id + " .action-rerun").addEventListener("click", function () { - ConnectionManager.rerun(); + ConnectionManager.exit(true); }); document.querySelector("#" + Panel.id + " .action-execute").addEventListener("click", function () { ConnectionManager.execute(); From d014e0b6c15f8fd7cffc5f0168e165d2b2713853 Mon Sep 17 00:00:00 2001 From: Jonathan Channon Date: Sat, 22 Feb 2014 17:17:00 +0000 Subject: [PATCH 14/15] removed commented code --- main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/main.js b/main.js index a3686b7..079b93f 100644 --- a/main.js +++ b/main.js @@ -188,7 +188,6 @@ define(function (require, exports, module) { */ show: function (command) { this.panel.style.display = "block"; - //this.commandTitle.textContent = command; EditorManager.resizeEditor(); }, hide: function () { From 0b598dadd8c524676e7445312d7cbd773f04d6c9 Mon Sep 17 00:00:00 2001 From: Jonathan Channon Date: Sun, 23 Feb 2014 17:12:56 +0000 Subject: [PATCH 15/15] tidied keyup and made currentLastIndex private variable --- main.js | 144 +++++++++++++++++++++++++------------------------------- 1 file changed, 64 insertions(+), 80 deletions(-) diff --git a/main.js b/main.js index 079b93f..a2b6609 100644 --- a/main.js +++ b/main.js @@ -172,99 +172,83 @@ define(function (require, exports, module) { * Panel alias terminal */ $(".content").append(require("text!html/panel.html")); - var Panel = { + var Panel = (function () { + var currentLastIndex = 0; + return { + id: "brackets-nodejs-terminal", + panel: null, + commandTitle: null, + height: 201, + + get: function (qs) { + return this.panel.querySelector(qs); + }, - id: "brackets-nodejs-terminal", - panel: null, - commandTitle: null, - height: 201, + /** + * Basic functionality + */ + show: function (command) { + this.panel.style.display = "block"; + EditorManager.resizeEditor(); + }, + hide: function () { + this.panel.style.display = "none"; + EditorManager.resizeEditor(); + }, + clear: function () { + this.pre.innerHTML = null; + }, - get: function (qs) { - return this.panel.querySelector(qs); - }, + /** + * Prints a string into the terminal + * It will be colored and then escape to prohibit XSS (Yes, inside an editor!) + * + * @param: String to be output + */ + write: function (str) { + var e = document.createElement("div"); + e.innerHTML = ansi(str.replace(//g, ">")); + this.pre.appendChild(e); + }, - /** - * Basic functionality - */ - show: function (command) { - this.panel.style.display = "block"; - EditorManager.resizeEditor(); - }, - hide: function () { - this.panel.style.display = "none"; - EditorManager.resizeEditor(); - }, - clear: function () { - this.pre.innerHTML = null; - }, + /** + * Used to enable resizing the panel + */ + mousemove: function (e) { - /** - * Prints a string into the terminal - * It will be colored and then escape to prohibit XSS (Yes, inside an editor!) - * - * @param: String to be output - */ - write: function (str) { - var e = document.createElement("div"); - e.innerHTML = ansi(str.replace(//g, ">")); - this.pre.appendChild(e); - }, + var h = Panel.height + (Panel.y - e.pageY); + Panel.panel.style.height = h + "px"; + EditorManager.resizeEditor(); - /** - * Used to enable resizing the panel - */ - mousemove: function (e) { + }, + mouseup: function (e) { - var h = Panel.height + (Panel.y - e.pageY); - Panel.panel.style.height = h + "px"; - EditorManager.resizeEditor(); + document.removeEventListener("mousemove", Panel.mousemove); + document.removeEventListener("mouseup", Panel.mouseup); - }, - mouseup: function (e) { + Panel.height = Panel.height + (Panel.y - e.pageY); - document.removeEventListener("mousemove", Panel.mousemove); - document.removeEventListener("mouseup", Panel.mouseup); + }, - Panel.height = Panel.height + (Panel.y - e.pageY); + keyup: function (e) { + if (e.keyCode === 38 && currentLastIndex !== ConnectionManager.last.length - 1) { + currentLastIndex++; + var cmd = ConnectionManager.last[currentLastIndex].command; + Panel.get(".cmd-value").value = cmd; - }, + } else if (e.keyCode === 40 && currentLastIndex !== 0) { + currentLastIndex--; + var cmd = ConnectionManager.last[currentLastIndex].command; + Panel.get(".cmd-value").value = cmd; - keyup: function (e) { - if (e.keyCode === 38) { - if (ConnectionManager.last.length === 0) { - return; - } - if (Panel.currentLastIndex >= ConnectionManager.last.length) { - Panel.currentLastIndex = ConnectionManager.last.length - 1; - } - if (Panel.currentLastIndex <= 0) { - Panel.currentLastIndex = 0; + } else if (e.keyCode === 13) { + ConnectionManager.execute(); } + }, + y: 0 + }; - - var cmd = ConnectionManager.last[Panel.currentLastIndex].command; - Panel.get(".cmd-value").value = cmd; - Panel.currentLastIndex++; - } else if (e.keyCode === 40) { - if (ConnectionManager.last.length === 0) { - return; - } - if (Panel.currentLastIndex >= ConnectionManager.last.length) { - Panel.currentLastIndex = ConnectionManager.last.length - 1; - } - if (Panel.currentLastIndex <= 0) { - Panel.currentLastIndex = 0; - } - var cmd = ConnectionManager.last[Panel.currentLastIndex].command; - Panel.get(".cmd-value").value = cmd; - Panel.currentLastIndex--; - } else if (e.keyCode === 13) { - ConnectionManager.execute(); - } - }, - y: 0, - currentLastIndex: 0 - }; + }()); // Still resizing Panel.panel = document.getElementById(Panel.id);