added basic terminal command history
use up/down keys to navigate through command history.
This commit is contained in:
parent
b115b6f66c
commit
036e0af960
2 changed files with 16 additions and 2 deletions
|
|
@ -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])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -516,7 +516,7 @@
|
|||
</div>
|
||||
|
||||
<div class="input-append" style="display: none;" data-bind="visible: loginState.isUser">
|
||||
<input type="text" id="terminal-command" data-bind="value: command, event: { keyup: function(d,e) { handleEnter(e); } }, enable: isOperational() && loginState.isUser()">
|
||||
<input type="text" id="terminal-command" data-bind="value: command, event: { keyup: function(d,e) { handleKeys(e); } }, enable: isOperational() && loginState.isUser()">
|
||||
<button class="btn" type="button" id="terminal-send" data-bind="click: sendCommand, enable: isOperational() && loginState.isUser()">Send</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue