]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/irc/commandhistory.js
5577b09bc52da9d75296455e56fd87de68b05460
[irc/quakenet/qwebirc.git] / js / irc / commandhistory.js
1 var CommandHistory = new Class({
2 Implements: [Options],
3 options: {
4 lines: 20
5 },
6 initialize: function(options) {
7 this.setOptions(options);
8
9 this.data = [];
10 this.position = -1;
11 },
12 addLine: function(line) {
13 this.data.unshift(line);
14 this.position = -1;
15
16 if(this.data.length > this.options.lines)
17 this.data.pop();
18 },
19 prevLine: function() {
20 if(this.position == 0)
21 return null;
22 this.position = this.position - 1;
23
24 return this.data[this.position];
25 },
26 nextLine: function() {
27 if(this.position >= this.data.length)
28 return null;
29 this.position = this.position + 1;
30
31 return this.data[this.position];
32 }
33 });