move command history to its own module

This commit is contained in:
Iuri Matias 2017-02-19 12:59:02 -05:00
parent 1868788342
commit 07d1631d9d
2 changed files with 29 additions and 26 deletions

View File

@ -0,0 +1,28 @@
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];
};
module.exports = CommandHistory;

View File

@ -1,32 +1,7 @@
/*jshint esversion: 6 */
var blessed = require("blessed");
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];
};
var CommandHistory = require('./command_history.js');
function Dashboard(options) {
var title = (options && options.title) || "Embark 2.3.0";