forked from lmorg/readline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtab.go
92 lines (75 loc) · 2.14 KB
/
tab.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package readline
// TabDisplayType defines how the autocomplete suggestions display
type TabDisplayType int
const (
// TabDisplayGrid is the default. It's where the screen below the prompt is
// divided into a grid with each suggestion occupying an individual cell.
TabDisplayGrid = iota
// TabDisplayList is where suggestions are displayed as a list with a
// description. The suggestion gets highlighted but both are searchable (ctrl+f)
TabDisplayList
// TabDisplayMap is where suggestions are displayed as a list with a
// description however the description is what gets highlighted and only
// that is searchable (ctrl+f). The benefit of TabDisplayMap is when your
// autocomplete suggestions are IDs rather than human terms.
TabDisplayMap
)
func (rl *Instance) getTabCompletion() {
rl.tcOffset = 0
if rl.TabCompleter == nil {
return
}
rl.tcPrefix, rl.tcSuggestions, rl.tcDescriptions, rl.tcDisplayType = rl.TabCompleter(rl.line, rl.pos)
if len(rl.tcSuggestions) == 0 {
return
}
if len(rl.tcDescriptions) == 0 {
// probably not needed, but just in case someone doesn't initialise the
// map in their API call.
rl.tcDescriptions = make(map[string]string)
}
/*if len(rl.tcSuggestions) == 1 && !rl.modeTabCompletion {
if len(rl.tcSuggestions[0]) == 0 || rl.tcSuggestions[0] == " " || rl.tcSuggestions[0] == "\t" {
return
}
rl.insert([]byte(rl.tcSuggestions[0]))
return
}*/
rl.initTabCompletion()
}
func (rl *Instance) initTabCompletion() {
if rl.tcDisplayType == TabDisplayGrid {
rl.initTabGrid()
} else {
rl.initTabMap()
}
}
func (rl *Instance) moveTabCompletionHighlight(x, y int) {
if rl.tcDisplayType == TabDisplayGrid {
rl.moveTabGridHighlight(x, y)
} else {
rl.moveTabMapHighlight(x, y)
}
}
func (rl *Instance) writeTabCompletion() {
if !rl.modeTabCompletion {
return
}
switch rl.tcDisplayType {
case TabDisplayGrid:
rl.writeTabGrid()
case TabDisplayMap:
rl.writeTabMap()
case TabDisplayList:
rl.writeTabMap()
default:
rl.writeTabGrid()
}
}
func (rl *Instance) resetTabCompletion() {
rl.modeTabCompletion = false
rl.tcOffset = 0
rl.tcUsedY = 0
rl.modeTabFind = false
rl.tfLine = []rune{}
}