embark/lib/dashboard/command_history.js

30 lines
553 B
JavaScript
Raw Normal View History

2017-03-30 11:12:39 +00:00
class CommandHistory {
constructor() {
this.history = [];
this.pointer = -1;
}
2017-02-19 17:59:02 +00:00
2017-03-30 11:12:39 +00:00
addCommand(cmd) {
this.history.push(cmd);
this.pointer = this.history.length;
}
2017-02-19 17:59:02 +00:00
2017-03-30 11:12:39 +00:00
getPreviousCommand(cmd) {
if (this.pointer >= 0) {
this.pointer--;
}
return this.history[this.pointer];
2017-02-19 17:59:02 +00:00
}
2017-03-30 11:12:39 +00:00
getNextCommand(cmd) {
if (this.pointer >= this.history.length) {
this.pointer = this.history.length - 1;
return '';
}
this.pointer++;
return this.history[this.pointer];
2017-02-19 17:59:02 +00:00
}
2017-03-30 11:12:39 +00:00
}
2017-02-19 17:59:02 +00:00
module.exports = CommandHistory;