-
Notifications
You must be signed in to change notification settings - Fork 3
/
prompt.go
63 lines (52 loc) · 1.47 KB
/
prompt.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 main
import (
"strings"
"github.com/gdamore/tcell"
)
var (
editorIsPromptActive = false
editorPrompt = ""
editorPromptValue = ""
editorPromptCallbackFn func([]string) = nil
editorPromptCompletionFn func(string) []string = nil
)
func prompt(prompt string, compFn func(string) []string, cbFn func([]string)) {
editorPrompt = prompt
editorPromptValue = ""
editorPromptCallbackFn = cbFn
editorPromptCompletionFn = compFn
enterMode("prompt")
}
func noopComplete(prefix string) []string {
return []string{}
}
func promptUpdateCompletion() {
// TODO
}
func promptCancel(vt *ViewTree, b *Buffer, kl *KeyList) {
enterMode("normal")
}
func promptFinish(vt *ViewTree, b *Buffer, kl *KeyList) {
enterMode("normal")
// TODO better args parsing
editorPromptCallbackFn(strings.Split(editorPromptValue, " "))
}
func promptBackspace(vt *ViewTree, b *Buffer, kl *KeyList) {
if len(editorPromptValue) > 0 {
editorPromptValue = editorPromptValue[:len(editorPromptValue)-1]
promptUpdateCompletion()
}
}
func promptInsert(vt *ViewTree, b *Buffer, kl *KeyList) {
k := kl.keys[len(kl.keys)-1]
if k.Key == tcell.KeyRune && k.Mod == 0 {
editorPromptValue += string(k.Chr)
promptUpdateCompletion()
}
}
func promptCommand(vt *ViewTree, b *Buffer, kl *KeyList) {
prompt(":", func(prefix string) []string {
// TODO provide command suggestions
return []string{}
}, runCommand)
}