-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathkeys.go
215 lines (202 loc) · 5.08 KB
/
keys.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package full
import "github.com/charmbracelet/bubbles/key"
type CustomKeyMap struct {
Home struct {
Up, Down, Next,
Prev, Add, Delete,
Details, Deselect,
Help, Quit CustomKey
}
AddPrompt struct {
Quit, Back,
Forward CustomKey
} `toml:"add-prompt"`
}
type CustomKey struct {
Key, Icon, Desc string
}
// isZero checks if a CustomKey object is of nil value.
func (k CustomKey) isZero() bool {
return k.Key == "" && k.Icon == "" && k.Desc == ""
}
type homeKeyMap struct {
up, down, next,
prev, add, delete,
details, deselect,
help, quit key.Binding
}
// ShortHelp returns the key bindings for the help and quit actions in
// the home screen.
func (k homeKeyMap) ShortHelp() []key.Binding {
return []key.Binding{k.help, k.quit}
}
// FullHelp returns the key bindings for all actions in the home
// screen.
func (k homeKeyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{k.up, k.down},
{k.next, k.prev},
{k.add, k.delete},
{k.details, k.deselect},
{k.help, k.quit},
}
}
// Define the key bindings and help symbols for each action in the home
// screen.
var homeKeys = homeKeyMap{
up: key.NewBinding(
key.WithKeys("k", "up"),
key.WithHelp("k/↑", "up"),
),
down: key.NewBinding(
key.WithKeys("j", "down"),
key.WithHelp("j/↓", "down"),
),
next: key.NewBinding(
key.WithKeys("l", "right"),
key.WithHelp("l/→", "next page"),
),
prev: key.NewBinding(
key.WithKeys("h", "left"),
key.WithHelp("h/←", "prev page"),
),
add: key.NewBinding(
key.WithKeys("a"),
key.WithHelp("a", "add torrent"),
),
delete: key.NewBinding(
key.WithKeys("d", "backspace"),
key.WithHelp("d/⌦ ", "delete"),
),
deselect: key.NewBinding(
key.WithKeys("esc"),
key.WithHelp("⎋", "deselect"),
),
details: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("↵", "torrent details"),
),
help: key.NewBinding(
key.WithKeys("?"),
key.WithHelp("?", "toggle help"),
),
quit: key.NewBinding(
key.WithKeys("q"),
key.WithHelp("q", "quit"),
),
}
type addPromptKeyMap struct {
quit, back, forward key.Binding
}
// ShortHelp returns the key bindings for the forward, back, and quit
// actions in the the add prompt screen.
func (k addPromptKeyMap) ShortHelp() []key.Binding {
return []key.Binding{k.forward, k.back, k.quit}
}
// FullHelp returns the key bindings for all actions in the the add
// prompt screen.
func (k addPromptKeyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{k.forward},
{k.back},
{k.quit},
}
}
// Define the key bindings and help symbols for each action in the add
// prompt screen.
var addPromptKeys = addPromptKeyMap{
quit: key.NewBinding(
key.WithKeys("esc"),
key.WithHelp("⎋", "home"),
),
back: key.NewBinding(
key.WithKeys("shift+tab"),
key.WithHelp("⇧ ↹", "previous"),
),
forward: key.NewBinding(
key.WithKeys("enter", "tab"),
key.WithHelp("↵", "next"),
),
}
// ToKeys changes the default homeKeys and addPromptKeys key bindings
// if there is user configuration.
func (c CustomKeyMap) ToKeys() {
if !c.Home.Up.isZero() {
homeKeys.up = key.NewBinding(
key.WithKeys(c.Home.Up.Key),
key.WithHelp(c.Home.Up.Icon, c.Home.Up.Desc),
)
}
if !c.Home.Down.isZero() {
homeKeys.down = key.NewBinding(
key.WithKeys(c.Home.Down.Key),
key.WithHelp(c.Home.Down.Icon, c.Home.Down.Desc),
)
}
if !c.Home.Next.isZero() {
homeKeys.next = key.NewBinding(
key.WithKeys(c.Home.Next.Key),
key.WithHelp(c.Home.Next.Icon, c.Home.Next.Desc),
)
}
if !c.Home.Prev.isZero() {
homeKeys.prev = key.NewBinding(
key.WithKeys(c.Home.Prev.Key),
key.WithHelp(c.Home.Prev.Icon, c.Home.Prev.Desc),
)
}
if !c.Home.Add.isZero() {
homeKeys.add = key.NewBinding(
key.WithKeys(c.Home.Add.Key),
key.WithHelp(c.Home.Add.Icon, c.Home.Add.Desc),
)
}
if !c.Home.Delete.isZero() {
homeKeys.delete = key.NewBinding(
key.WithKeys(c.Home.Delete.Key),
key.WithHelp(c.Home.Delete.Icon, c.Home.Delete.Desc),
)
}
if !c.Home.Deselect.isZero() {
homeKeys.deselect = key.NewBinding(
key.WithKeys(c.Home.Deselect.Key),
key.WithHelp(c.Home.Deselect.Icon, c.Home.Deselect.Desc),
)
}
if !c.Home.Details.isZero() {
homeKeys.details = key.NewBinding(
key.WithKeys(c.Home.Details.Key),
key.WithHelp(c.Home.Details.Icon, c.Home.Details.Desc),
)
}
if !c.Home.Help.isZero() {
homeKeys.help = key.NewBinding(
key.WithKeys(c.Home.Help.Key),
key.WithHelp(c.Home.Help.Icon, c.Home.Help.Desc),
)
}
if !c.Home.Quit.isZero() {
homeKeys.quit = key.NewBinding(
key.WithKeys(c.Home.Quit.Key),
key.WithHelp(c.Home.Quit.Icon, c.Home.Quit.Desc),
)
}
if !c.AddPrompt.Quit.isZero() {
addPromptKeys.quit = key.NewBinding(
key.WithKeys(c.AddPrompt.Quit.Key),
key.WithHelp(c.AddPrompt.Quit.Icon, c.AddPrompt.Quit.Desc),
)
}
if !c.AddPrompt.Back.isZero() {
addPromptKeys.back = key.NewBinding(
key.WithKeys(c.AddPrompt.Back.Key),
key.WithHelp(c.AddPrompt.Back.Icon, c.AddPrompt.Back.Desc),
)
}
if !c.AddPrompt.Forward.isZero() {
addPromptKeys.forward = key.NewBinding(
key.WithKeys(c.AddPrompt.Forward.Key),
key.WithHelp(c.AddPrompt.Forward.Icon, c.AddPrompt.Forward.Desc),
)
}
}