/
keybindings.go
66 lines (55 loc) · 1.36 KB
/
keybindings.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
package keybindings
import (
"github.com/nsf/termbox-go"
"github.com/sebashwa/vixl44/modes"
commonActions "github.com/sebashwa/vixl44/actions"
paintActions "github.com/sebashwa/vixl44/actions/paint"
commandActions "github.com/sebashwa/vixl44/actions/command"
)
func CommandMode(Ch rune, Key termbox.Key) bool {
if Ch != 0 {
commandActions.Append(Ch)
}
switch Key {
case termbox.KeyBackspace, termbox.KeyBackspace2:
commandActions.Truncate()
case termbox.KeySpace:
commandActions.Append(' ')
case termbox.KeyEnter:
shouldQuit, hint, err := commandActions.Execute()
if err != nil {
commonActions.SetError(err.Error())
} else if shouldQuit {
return true
} else if hint != "" {
commonActions.SetHint(hint)
}
commandActions.Set("")
commonActions.SetMode(modes.NormalMode)
default:
ModeSelection('0', Key)
}
return false
}
func ModeSelection(Ch rune, Key termbox.Key) {
switch Key {
case termbox.KeyCtrlV:
commonActions.SetMode(modes.VisualBlockMode)
case termbox.KeyEsc:
commonActions.SetMode(modes.NormalMode)
}
switch Ch {
case ':':
commonActions.SetMode(modes.CommandMode)
case 'c':
commonActions.SetMode(modes.PaletteMode)
}
}
func Common(Ch rune) {
switch Ch {
case 'J':
paintActions.AdjustColor(+1)
case 'K':
paintActions.AdjustColor(-1)
}
}