add command line history and navigation to the console
This commit is contained in:
parent
9e61009942
commit
556c799869
|
@ -3,14 +3,37 @@
|
|||
|
||||
var blessed = require("blessed");
|
||||
|
||||
//var formatOutput = require("../utils/format-output.js");
|
||||
//var formatModules = require("../utils/format-modules.js");
|
||||
//var formatAssets = require("../utils/format-assets.js");
|
||||
var CommandHistory = function() {
|
||||
this.history = [];
|
||||
this.pointer = -1;
|
||||
};
|
||||
|
||||
CommandHistory.prototype.addCommand = function(cmd) {
|
||||
this.history.push(cmd);
|
||||
this.pointer = this.history.length;
|
||||
};
|
||||
|
||||
CommandHistory.prototype.getPreviousCommand = function(cmd) {
|
||||
if (this.pointer >= 0) {
|
||||
this.pointer--;
|
||||
}
|
||||
return this.history[this.pointer];
|
||||
};
|
||||
|
||||
CommandHistory.prototype.getNextCommand = function(cmd) {
|
||||
if (this.pointer >= this.history.length) {
|
||||
this.pointer = this.history.length - 1;
|
||||
return '';
|
||||
}
|
||||
this.pointer++;
|
||||
return this.history[this.pointer];
|
||||
};
|
||||
|
||||
function Dashboard(options) {
|
||||
var title = options && options.title || "Embark 2.0";
|
||||
this.env = options.env;
|
||||
this.console = options.console;
|
||||
this.history = new CommandHistory();
|
||||
|
||||
this.color = options && options.color || "green";
|
||||
this.minimal = options && options.minimal || false;
|
||||
|
@ -316,8 +339,21 @@ Dashboard.prototype.layoutCmd = function() {
|
|||
process.exit(0);
|
||||
});
|
||||
|
||||
this.input.key(["up"], function() {
|
||||
var cmd = self.history.getPreviousCommand();
|
||||
self.input.setValue(cmd);
|
||||
self.input.focus();
|
||||
});
|
||||
|
||||
this.input.key(["down"], function() {
|
||||
var cmd = self.history.getNextCommand();
|
||||
self.input.setValue(cmd);
|
||||
self.input.focus();
|
||||
});
|
||||
|
||||
this.input.on('submit', function(data) {
|
||||
if (data !== '') {
|
||||
self.history.addCommand(data);
|
||||
self.logText.log('console> ' + data);
|
||||
self.console.executeCmd(data, function(result) {
|
||||
self.logText.log(result);
|
||||
|
|
Loading…
Reference in New Issue