-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyBindings.go
136 lines (119 loc) · 2.73 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package main
import "github.com/charmbracelet/bubbles/key"
// Key bindings for the home view.
var keysHome = HomeKeyMap()
func HomeKeyMap() keyMap {
keys := newKeyMap()
keys.Full = [][]key.Binding{
{keys.Up, keys.Down},
{keys.Quit, keys.Enter, keys.Help},
}
return keys
}
// Key bindings for the vault view.
var keysVault = VaultKeyMap()
func VaultKeyMap() keyMap {
keys := newKeyMap()
keys.Full = [][]key.Binding{
{keys.Up, keys.Down, keys.Back},
{keys.Quit, keys.Enter, keys.Help},
{keys.Create, keys.Delete},
}
return keys
}
// Key bindings for the create secret view.
var keysCreateSecret = CreateSecretKeyMap()
func CreateSecretKeyMap() keyMap {
keys := newKeyMap()
keys.Full = [][]key.Binding{
{keys.Up, keys.Down, keys.Back},
{keys.Quit, keys.Enter, keys.Help},
}
return keys
}
// Key bindings for the create vault view.
var keysCreateVault = CreateVaultKeyMap()
func CreateVaultKeyMap() keyMap {
keys := newKeyMap()
keys.Full = [][]key.Binding{
{keys.Up, keys.Down, keys.Back},
{keys.Quit, keys.Enter, keys.Help},
}
return keys
}
// Key bindings for the enter vault view.
var keysEnterVault = EnterVaultKeyMap()
func EnterVaultKeyMap() keyMap {
keys := newKeyMap()
keys.Full = [][]key.Binding{
{keys.Up, keys.Down, keys.Back},
{keys.Quit, keys.Enter, keys.Help},
}
return keys
}
// Key bindings for the vaults view.
var keysVaults = VaultsKeyMap()
func VaultsKeyMap() keyMap {
keys := newKeyMap()
keys.Full = [][]key.Binding{
{keys.Up, keys.Down, keys.Back},
{keys.Quit, keys.Enter, keys.Help},
{keys.Delete},
}
return keys
}
// Define a generic key map struct
type keyMap struct {
Up key.Binding
Down key.Binding
Quit key.Binding
Help key.Binding
Enter key.Binding
Back key.Binding
Create key.Binding
Delete key.Binding
Full [][]key.Binding
}
func (k keyMap) ShortHelp() []key.Binding {
return []key.Binding{k.Help, k.Quit}
}
func (k keyMap) FullHelp() [][]key.Binding {
return k.Full
}
// General bindings
func newKeyMap() keyMap {
return keyMap{
Up: key.NewBinding(
key.WithKeys("up"),
key.WithHelp("↑", "move up"),
),
Down: key.NewBinding(
key.WithKeys("down"),
key.WithHelp("↓", "move down"),
),
Quit: key.NewBinding(
key.WithKeys("esc", "ctrl+c"),
key.WithHelp("esc/ctrl+c", "quit program"),
),
Help: key.NewBinding(
key.WithKeys("?"),
key.WithHelp("?", "toggle help"),
),
Enter: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("enter", "enter"),
),
Back: key.NewBinding(
key.WithKeys("left"),
key.WithHelp("←", "go back"),
),
Delete: key.NewBinding(
key.WithKeys("d"),
key.WithHelp("d", "delete secret"),
),
Create: key.NewBinding(
key.WithKeys("c"),
key.WithHelp("c", "create secret"),
),
}
}