mirror of https://github.com/embarklabs/embark.git
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 blessed = require("blessed");
|
||||||
|
|
||||||
//var formatOutput = require("../utils/format-output.js");
|
var CommandHistory = function() {
|
||||||
//var formatModules = require("../utils/format-modules.js");
|
this.history = [];
|
||||||
//var formatAssets = require("../utils/format-assets.js");
|
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) {
|
function Dashboard(options) {
|
||||||
var title = options && options.title || "Embark 2.0";
|
var title = options && options.title || "Embark 2.0";
|
||||||
this.env = options.env;
|
this.env = options.env;
|
||||||
this.console = options.console;
|
this.console = options.console;
|
||||||
|
this.history = new CommandHistory();
|
||||||
|
|
||||||
this.color = options && options.color || "green";
|
this.color = options && options.color || "green";
|
||||||
this.minimal = options && options.minimal || false;
|
this.minimal = options && options.minimal || false;
|
||||||
|
@ -316,8 +339,21 @@ Dashboard.prototype.layoutCmd = function() {
|
||||||
process.exit(0);
|
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) {
|
this.input.on('submit', function(data) {
|
||||||
if (data !== '') {
|
if (data !== '') {
|
||||||
|
self.history.addCommand(data);
|
||||||
self.logText.log('console> ' + data);
|
self.logText.log('console> ' + data);
|
||||||
self.console.executeCmd(data, function(result) {
|
self.console.executeCmd(data, function(result) {
|
||||||
self.logText.log(result);
|
self.logText.log(result);
|
||||||
|
|
Loading…
Reference in New Issue