mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-25 17:25:20 +03:00
cleanup cli history
This commit is contained in:
parent
799fc76c8e
commit
a8e19a6956
1 changed files with 23 additions and 30 deletions
53
tabs/cli.js
53
tabs/cli.js
|
@ -2,39 +2,14 @@
|
||||||
var CLI_active = false;
|
var CLI_active = false;
|
||||||
var CLI_valid = false;
|
var CLI_valid = false;
|
||||||
|
|
||||||
var CliHistory = function () {
|
tabs.cli = {};
|
||||||
this.history = [];
|
|
||||||
this.index = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
CliHistory.prototype = {
|
|
||||||
add: function (str) {
|
|
||||||
this.history.push(str);
|
|
||||||
this.index = this.history.length;
|
|
||||||
},
|
|
||||||
prev: function () {
|
|
||||||
if (this.index > 0) this.index -= 1;
|
|
||||||
return this.history[this.index];
|
|
||||||
},
|
|
||||||
next: function () {
|
|
||||||
if (this.index < this.history.length) this.index += 1;
|
|
||||||
return this.history[this.index - 1];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
cli_history = new CliHistory();
|
|
||||||
|
|
||||||
tabs.cli = function() {
|
|
||||||
};
|
|
||||||
|
|
||||||
tabs.cli.initialize = function(callback) {
|
tabs.cli.initialize = function(callback) {
|
||||||
|
var self = this;
|
||||||
GUI.active_tab_ref = this;
|
GUI.active_tab_ref = this;
|
||||||
GUI.active_tab = 'cli';
|
GUI.active_tab = 'cli';
|
||||||
ga_tracker.sendAppView('CLI Page');
|
ga_tracker.sendAppView('CLI Page');
|
||||||
|
|
||||||
// remove any active interval for delayed command
|
|
||||||
MSP.callbacks_cleanup();
|
|
||||||
|
|
||||||
$('#content').load("./tabs/cli.html", function() {
|
$('#content').load("./tabs/cli.html", function() {
|
||||||
// translate to user-selected language
|
// translate to user-selected language
|
||||||
localize();
|
localize();
|
||||||
|
@ -57,7 +32,7 @@ tabs.cli.initialize = function(callback) {
|
||||||
|
|
||||||
var out_string = textarea.val();
|
var out_string = textarea.val();
|
||||||
var out_arr = out_string.split("\n");
|
var out_arr = out_string.split("\n");
|
||||||
cli_history.add(out_string.trim());
|
self.history.add(out_string.trim());
|
||||||
|
|
||||||
var timeout_needle = 0;
|
var timeout_needle = 0;
|
||||||
for (var i = 0; i < out_arr.length; i++) {
|
for (var i = 0; i < out_arr.length; i++) {
|
||||||
|
@ -72,10 +47,10 @@ tabs.cli.initialize = function(callback) {
|
||||||
var keyUp = { 38: true }, keyDown = { 40: true };
|
var keyUp = { 38: true }, keyDown = { 40: true };
|
||||||
|
|
||||||
if (event.keyCode in keyUp)
|
if (event.keyCode in keyUp)
|
||||||
textarea.val(cli_history.prev());
|
textarea.val(self.history.prev());
|
||||||
|
|
||||||
if (event.keyCode in keyDown)
|
if (event.keyCode in keyDown)
|
||||||
textarea.val(cli_history.next());
|
textarea.val(self.history.next());
|
||||||
});
|
});
|
||||||
|
|
||||||
// give input element user focus
|
// give input element user focus
|
||||||
|
@ -85,6 +60,24 @@ tabs.cli.initialize = function(callback) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
tabs.cli.history = {
|
||||||
|
history: [],
|
||||||
|
index: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
tabs.cli.history.add = function(str) {
|
||||||
|
this.history.push(str);
|
||||||
|
this.index = this.history.length;
|
||||||
|
};
|
||||||
|
tabs.cli.history.prev = function() {
|
||||||
|
if (this.index > 0) this.index -= 1;
|
||||||
|
return this.history[this.index];
|
||||||
|
};
|
||||||
|
tabs.cli.history.next = function() {
|
||||||
|
if (this.index < this.history.length) this.index += 1;
|
||||||
|
return this.history[this.index - 1];
|
||||||
|
};
|
||||||
|
|
||||||
tabs.cli.cleanup = function(callback) {
|
tabs.cli.cleanup = function(callback) {
|
||||||
var bufferOut = new ArrayBuffer(5);
|
var bufferOut = new ArrayBuffer(5);
|
||||||
var bufView = new Uint8Array(bufferOut);
|
var bufView = new Uint8Array(bufferOut);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue