]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/irc/commandhistory.js
175ac19b6e9504ecc96815e3027d2e9d9d6420ae
[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 = 0;
11 },
12 addLine: function(line, moveUp) {
13 if((this.data.length == 0) || (line != this.data[0]))
14 this.data.unshift(line);
15
16 if(moveUp) {
17 this.position = 0;
18 } else {
19 this.position = -1;
20 }
21
22 if(this.data.length > this.options.lines)
23 this.data.pop();
24 },
25 upLine: function() {
26 if(this.data.length == 0)
27 return null;
28
29 if(this.position >= this.data.length)
30 return null;
31
32 this.position = this.position + 1;
33
34 return this.data[this.position];
35 },
36 downLine: function() {
37 if(this.position == -1)
38 return null;
39
40 this.position = this.position - 1;
41
42 if(this.position == -1)
43 return null;
44
45 return this.data[this.position];
46 }
47 });