From 036e0af960fc85a4867b361a87970a84c7bcfca0 Mon Sep 17 00:00:00 2001 From: Chris Kosmakos Date: Thu, 20 Feb 2014 10:46:22 +0000 Subject: [PATCH] added basic terminal command history use up/down keys to navigate through command history. --- .../static/js/app/viewmodels/terminal.js | 16 +++++++++++++++- src/octoprint/templates/index.jinja2 | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/terminal.js b/src/octoprint/static/js/app/viewmodels/terminal.js index d739ea0e..076ae607 100644 --- a/src/octoprint/static/js/app/viewmodels/terminal.js +++ b/src/octoprint/static/js/app/viewmodels/terminal.js @@ -21,6 +21,10 @@ function TerminalViewModel(loginStateViewModel, settingsViewModel) { self.filters = self.settings.terminalFilters; self.filterRegex = undefined; + self.cmdHistory = []; + self.cmdHistoryCnt = 0; + self.cmdHistoryIdx = -1; + self.activeFilters = ko.observableArray([]); self.activeFilters.subscribe(function(e) { self.updateFilterRegex(); @@ -105,13 +109,23 @@ function TerminalViewModel(loginStateViewModel, settingsViewModel) { contentType: "application/json; charset=UTF-8", data: JSON.stringify({"command": command}) }); + self.cmdHistory[self.cmdHistoryCnt++] = command + self.cmdHistoryIdx = self.cmdHistoryCnt self.command(""); } } - self.handleEnter = function(event) { + self.handleKeys = function(event) { if (event.keyCode == 13) { self.sendCommand(); + } else if (event.keyCode == 38) { + if (self.cmdHistoryIdx >= 0) { + self.command(self.cmdHistory[--self.cmdHistoryIdx]) + } + } else if (event.keyCode == 40) { + if (self.cmdHistoryIdx < self.cmdHistoryCnt) { + self.command(self.cmdHistory[++self.cmdHistoryIdx]) + } } } diff --git a/src/octoprint/templates/index.jinja2 b/src/octoprint/templates/index.jinja2 index 17f25b44..f74ec4ab 100644 --- a/src/octoprint/templates/index.jinja2 +++ b/src/octoprint/templates/index.jinja2 @@ -516,7 +516,7 @@