forked from lmorg/readline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabfind.go
57 lines (47 loc) · 1.3 KB
/
tabfind.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
package readline
import "regexp"
func (rl *Instance) backspaceTabFind() {
if len(rl.tfLine) > 0 {
rl.tfLine = rl.tfLine[:len(rl.tfLine)-1]
}
rl.updateTabFind([]rune{})
}
func (rl *Instance) updateTabFind(r []rune) {
rl.tfLine = append(rl.tfLine, r...)
rl.hintText = append([]rune("regexp find: "), rl.tfLine...)
defer func() {
rl.clearHelpers()
rl.initTabCompletion()
rl.renderHelpers()
}()
if len(rl.tfLine) == 0 {
rl.tfSuggestions = append(rl.tcSuggestions, []string{}...)
return
}
rx, err := regexp.Compile("(?i)" + string(rl.tfLine))
if err != nil {
rl.tfSuggestions = []string{err.Error()}
return
}
rl.tfSuggestions = make([]string, 0)
for i := range rl.tcSuggestions {
if rx.MatchString(rl.tcSuggestions[i]) {
rl.tfSuggestions = append(rl.tfSuggestions, rl.tcSuggestions[i])
} else if rl.tcDisplayType == TabDisplayList && rx.MatchString(rl.tcDescriptions[rl.tcSuggestions[i]]) {
// this is a list so lets also check the descriptions
rl.tfSuggestions = append(rl.tfSuggestions, rl.tcSuggestions[i])
}
}
}
func (rl *Instance) resetTabFind() {
rl.modeTabFind = false
rl.tfLine = []rune{}
if rl.modeAutoFind {
rl.hintText = []rune{}
} else {
rl.hintText = []rune("Cancelled regexp suggestion find.")
}
rl.clearHelpers()
rl.initTabCompletion()
rl.renderHelpers()
}