-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkeymap.go
66 lines (54 loc) · 1.22 KB
/
keymap.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
66
package skeleton
import (
teakey "github.com/charmbracelet/bubbles/key"
"sync"
)
type keyMap struct {
SwitchTabRight teakey.Binding
SwitchTabLeft teakey.Binding
Quit teakey.Binding
}
const (
keymapSwitchTabRight = "ctrl+right"
keymapSwitchTabLeft = "ctrl+left"
keymapQuit = "ctrl+c"
)
var (
onceKeyMap sync.Once
varKeyMap *keyMap
)
func newKeyMap() *keyMap {
onceKeyMap.Do(func() {
varKeyMap = &keyMap{
SwitchTabRight: teakey.NewBinding(
teakey.WithKeys(keymapSwitchTabRight),
),
SwitchTabLeft: teakey.NewBinding(
teakey.WithKeys(keymapSwitchTabLeft),
),
Quit: teakey.NewBinding(
teakey.WithKeys(keymapQuit),
),
}
})
return varKeyMap
}
// --------------------------------------------
func (k *keyMap) SetKeyNextTab(keybinding teakey.Binding) {
k.SwitchTabRight = keybinding
}
func (k *keyMap) SetKeyPrevTab(keybinding teakey.Binding) {
k.SwitchTabLeft = keybinding
}
func (k *keyMap) SetKeyQuit(keybinding teakey.Binding) {
k.Quit = keybinding
}
func (k *keyMap) GetKeyNextTab() teakey.Binding {
return k.SwitchTabRight
}
func (k *keyMap) GetKeyPrevTab() teakey.Binding {
return k.SwitchTabLeft
}
func (k *keyMap) GetKeyQuit() teakey.Binding {
return k.Quit
}