-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReplHistory.js
58 lines (45 loc) · 997 Bytes
/
ReplHistory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"use strict";
(class ReplHistory extends Base {
initPrototype () {
this.newSlot("entries", null)
this.newSlot("maxEntries", 10000)
this.newSlot("index", 0)
}
init () {
super.init()
this.setEntries([])
this.addEntry("")
}
// --- WasmLoader protocol ---
addEntry (s) {
this.entries().unshift(s)
if (this.entries().length > this.maxEntries()) {
this.entries().pop()
}
this.resetIndex()
return this
}
updateCurrentEntry (s) {
this.entries().shift()
this.entries().unshift(s)
return this
}
resetIndex () {
this.setIndex(0)
return this
}
currentEntry () {
const i = this.index()
return this.entries()[i]
}
previous () {
const i = Math.min(this.index() + 1, this.entries().length - 1)
this.setIndex(i)
return this.currentEntry()
}
next () {
const i = Math.max(this.index() - 1, 0)
this.setIndex(i)
return this.currentEntry()
}
}.initThisClass());