-
Notifications
You must be signed in to change notification settings - Fork 4
/
keys.go
216 lines (201 loc) · 4.55 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
216
package main
import "github.com/charmbracelet/bubbles/key"
func (u User) ShortHelp() []key.Binding {
return []key.Binding{u.KeyMap.Help, u.KeyMap.Quit}
}
func (u User) FullHelp() [][]key.Binding {
return [][]key.Binding{
{u.KeyMap.Help, u.KeyMap.Up, u.KeyMap.Down, u.KeyMap.Gpt},
{u.KeyMap.New, u.KeyMap.Open, u.KeyMap.Edit, u.KeyMap.Review},
}
}
func (f Form) ShortHelp() []key.Binding {
return []key.Binding{f.keyMap.Enter, f.keyMap.Tab, f.keyMap.Back}
}
func (f Form) FullHelp() [][]key.Binding {
return [][]key.Binding{
{f.keyMap.Enter, f.keyMap.Tab, f.keyMap.Back},
}
}
func (d Deck) ShortHelp() []key.Binding {
return []key.Binding{d.keyMap.Again, d.keyMap.Good, d.keyMap.Easy}
}
func (d Deck) FullHelp() [][]key.Binding {
return [][]key.Binding{
{d.keyMap.New, d.keyMap.Edit, d.keyMap.Delete, d.keyMap.Up},
{d.keyMap.Down, d.keyMap.Enter, d.keyMap.Help, d.keyMap.Quit},
{d.keyMap.Back, d.keyMap.Tab, d.keyMap.Review},
}
}
func (c Card) ShortHelp() []key.Binding {
return []key.Binding{cardKeyMap.Open, cardKeyMap.Back}
}
func (c Card) FullHelp() [][]key.Binding {
return [][]key.Binding{
{cardKeyMap.Open, cardKeyMap.Back},
}
}
type keyMap struct {
New key.Binding
Edit key.Binding
Delete key.Binding
Up key.Binding
Down key.Binding
Enter key.Binding
Help key.Binding
Quit key.Binding
Back key.Binding
Tab key.Binding
Review key.Binding
Open key.Binding
Easy key.Binding
Good key.Binding
Again key.Binding
Search key.Binding
Undo key.Binding
Gpt key.Binding
ShowFullHelp key.Binding
CloseFullHelp key.Binding
}
var cardKeyMap = keyMap{
Back: key.NewBinding(
key.WithKeys("esc"),
key.WithHelp("esc", "exit review"),
),
Open: key.NewBinding(
key.WithKeys("o"),
key.WithHelp("o", "show back"),
),
}
func DeckKeyMap() keyMap {
return keyMap{
New: key.NewBinding(
key.WithKeys("n"),
key.WithHelp("n", "new card"),
),
Edit: key.NewBinding(
key.WithKeys("e"),
key.WithHelp("e", "edit card"),
),
Back: key.NewBinding(
key.WithKeys("esc"),
key.WithHelp("esc", "home page"),
),
Open: key.NewBinding(
key.WithKeys("o"),
key.WithHelp("o", "show back"),
),
Again: key.NewBinding(
key.WithKeys("1"),
key.WithHelp("1", "again"),
),
Good: key.NewBinding(
key.WithKeys("2"),
key.WithHelp("2", "good"),
),
Easy: key.NewBinding(
key.WithKeys("3"),
key.WithHelp("3", "easy"),
),
Delete: key.NewBinding(
key.WithKeys("d"),
key.WithHelp("d", "delete card"),
),
Search: key.NewBinding(
key.WithKeys("/"),
key.WithHelp("/", "filter cards"),
),
Enter: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("enter", "search"),
),
Undo: key.NewBinding(
key.WithKeys("u"),
key.WithHelp("u", "undo delete"),
),
Quit: key.NewBinding(
key.WithKeys("q", "ctrl+c"),
key.WithHelp("q/ctrl+c", "quit"),
),
}
}
func FormKeyMap() keyMap {
return keyMap{
Enter: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("enter", "next field/submit"),
),
Tab: key.NewBinding(
key.WithKeys("tab"),
key.WithHelp("tab", "prev field"),
),
Back: key.NewBinding(
key.WithKeys("esc"),
key.WithHelp("esc", "prev page"),
),
}
}
func DefaultKeyMap() keyMap {
return keyMap{
New: key.NewBinding(
key.WithKeys("N"),
key.WithHelp("N", "new deck"),
),
Edit: key.NewBinding(
key.WithKeys("e"),
key.WithHelp("e", "edit deck name"),
),
Delete: key.NewBinding(
key.WithKeys("d"),
key.WithHelp("d", "delete deck"),
),
Up: key.NewBinding(
key.WithKeys("up", "k"),
key.WithHelp("↑/k", "move up"),
),
Down: key.NewBinding(
key.WithKeys("down", "j"),
key.WithHelp("↓/j", "move down"),
),
Enter: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("enter", "enter"),
),
Help: key.NewBinding(
key.WithKeys("?"),
key.WithHelp("?", "toggle help"),
),
Quit: key.NewBinding(
key.WithKeys("q", "ctrl+c"),
key.WithHelp("q/ctrl+c", "quit"),
),
Back: key.NewBinding(
key.WithKeys("esc"),
key.WithHelp("esc", "back to prev page"),
),
Tab: key.NewBinding(
key.WithKeys("tab"),
key.WithHelp("tab", "move focus"),
),
Review: key.NewBinding(
key.WithKeys("r"),
key.WithHelp("r", "review deck"),
),
Open: key.NewBinding(
key.WithKeys("o"),
key.WithHelp("o", "view deck"),
),
ShowFullHelp: key.NewBinding(
key.WithKeys("?"),
key.WithHelp("?", "more"),
),
CloseFullHelp: key.NewBinding(
key.WithKeys("?"),
key.WithHelp("?", "close help"),
),
Gpt: key.NewBinding(
key.WithKeys("G"),
key.WithHelp("G", "query gpt"),
),
}
}