2017-02-19 17:59:02 +00:00
|
|
|
|
2017-03-29 17:50:05 +00:00
|
|
|
let CommandHistory = function() {
|
2017-02-19 17:59:02 +00:00
|
|
|
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;
|