-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.go
51 lines (41 loc) · 871 Bytes
/
commands.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
package main
import "fmt"
type ArgList []interface{}
type Command int
const (
ComQuit Command = iota
ComSaveToFile
ComLoadFile
ComInsertRune
ComLogMessage
ComMoveCursor
)
func (c Command) Exec(args ...interface{}) {
CommandAction[c](args)
}
var CommandAction = map[Command]func(ArgList) {
ComQuit: quit,
ComSaveToFile: saveToFile,
ComLoadFile: loadFile,
ComInsertRune: insertRune,
ComLogMessage: logMessage,
ComMoveCursor: moveCursor,
}
// no args
func quit(args ArgList) {
editor.shouldQuit = true
}
// args[0] - filename string
func saveToFile(args ArgList) {}
// args[0] - filename string
func loadFile(args ArgList) {}
// args[0] - char rune
func insertRune(args ArgList) {
}
// args[0] - dir rune {'u', 'd', 'l', 'r'}
func moveCursor(args ArgList) {
}
func logMessage(args ArgList) {
arg := fmt.Sprintf("%s\n", args[0])
log(arg)
}