mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-09 13:36:14 +00:00
30 lines
547 B
JavaScript
30 lines
547 B
JavaScript
class CommandHistory {
|
|
constructor() {
|
|
this.history = [];
|
|
this.pointer = -1;
|
|
}
|
|
|
|
addCommand(cmd) {
|
|
this.history.push(cmd);
|
|
this.pointer = this.history.length;
|
|
}
|
|
|
|
getPreviousCommand() {
|
|
if (this.pointer >= 0) {
|
|
this.pointer--;
|
|
}
|
|
return this.history[this.pointer];
|
|
}
|
|
|
|
getNextCommand() {
|
|
if (this.pointer >= this.history.length) {
|
|
this.pointer = this.history.length - 1;
|
|
return '';
|
|
}
|
|
this.pointer++;
|
|
return this.history[this.pointer];
|
|
}
|
|
}
|
|
|
|
module.exports = CommandHistory;
|