/
history.go
63 lines (57 loc) · 1.17 KB
/
history.go
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
58
59
60
61
62
63
package readline
import (
"bufio"
"context"
"io"
)
type IHistory interface {
Len() int
At(int) string
}
type KeyMap struct {
KeyMap map[string]KeyFuncT
}
type Editor struct {
KeyMap
History IHistory
Writer io.Writer
Out *bufio.Writer
Prompt func() (int, error)
Default string
Cursor int
LineFeed func(Result)
}
func keyFuncHistoryUp(ctx context.Context, this *Buffer) Result {
if this.History.Len() <= 0 {
return CONTINUE
}
if this.HistoryPointer <= 0 {
this.HistoryPointer = this.History.Len()
}
this.HistoryPointer -= 1
keyFuncClear(ctx, this)
if this.HistoryPointer >= 0 {
this.InsertString(0, this.History.At(this.HistoryPointer))
this.ViewStart = 0
this.Cursor = 0
keyFuncTail(ctx, this)
}
return CONTINUE
}
func keyFuncHistoryDown(ctx context.Context, this *Buffer) Result {
if this.History.Len() <= 0 {
return CONTINUE
}
if this.HistoryPointer+1 > this.History.Len() {
return CONTINUE
}
this.HistoryPointer += 1
keyFuncClear(ctx, this)
if this.HistoryPointer < this.History.Len() {
this.InsertString(0, this.History.At(this.HistoryPointer))
this.ViewStart = 0
this.Cursor = 0
keyFuncTail(ctx, this)
}
return CONTINUE
}