File tree Expand file tree Collapse file tree 1 file changed +33
-6
lines changed Expand file tree Collapse file tree 1 file changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -11,15 +11,19 @@ import (
11
11
)
12
12
13
13
func main () {
14
- items := []readline.PrefixCompleterInterface {}
15
- for _ , name := range builtin .Names {
16
- items = append (items , readline .PcItem (name ))
14
+ extra := []string {
15
+ "exit" ,
16
+ "opcodes" ,
17
+ "map" ,
18
+ "filter" ,
19
+ "all" ,
20
+ "any" ,
21
+ "none" ,
22
+ "one" ,
17
23
}
18
- items = append (items , readline .PcItem ("exit" ))
19
- items = append (items , readline .PcItem ("opcodes" ))
20
24
rl , err := readline .NewEx (& readline.Config {
21
25
Prompt : "> " ,
22
- AutoComplete : readline . NewPrefixCompleter ( items ... ) ,
26
+ AutoComplete : completer { append ( builtin . Names , extra ... )} ,
23
27
})
24
28
if err != nil {
25
29
panic (err )
@@ -58,3 +62,26 @@ func main() {
58
62
fmt .Println (output )
59
63
}
60
64
}
65
+
66
+ type completer struct {
67
+ words []string
68
+ }
69
+
70
+ func (c completer ) Do (line []rune , pos int ) ([][]rune , int ) {
71
+ var lastWord string
72
+ for i := pos - 1 ; i >= 0 ; i -- {
73
+ if line [i ] == ' ' {
74
+ break
75
+ }
76
+ lastWord = string (line [i ]) + lastWord
77
+ }
78
+
79
+ var words [][]rune
80
+ for _ , word := range c .words {
81
+ if strings .HasPrefix (word , lastWord ) {
82
+ words = append (words , []rune (strings .TrimPrefix (word , lastWord )))
83
+ }
84
+ }
85
+
86
+ return words , len (lastWord )
87
+ }
You can’t perform that action at this time.
0 commit comments