-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlistKeyMap.go
More file actions
83 lines (77 loc) · 1.73 KB
/
listKeyMap.go
File metadata and controls
83 lines (77 loc) · 1.73 KB
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
package main
import (
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list"
)
type listKeyMap struct {
list.KeyMap
finalizeSelection key.Binding
makeSelection key.Binding
}
func newListKeyMap() *listKeyMap {
km := &listKeyMap{
KeyMap: list.KeyMap{
CursorUp: key.NewBinding(
key.WithKeys("up"),
key.WithHelp("↑", "up"),
),
CursorDown: key.NewBinding(
key.WithKeys("down"),
key.WithHelp("↓", "down"),
),
Quit: key.NewBinding(
key.WithKeys("q"),
key.WithHelp("q", "quit"),
),
// Disable unused bindings
GoToStart: key.NewBinding(),
GoToEnd: key.NewBinding(),
NextPage: key.NewBinding(),
PrevPage: key.NewBinding(),
Filter: key.NewBinding(),
ClearFilter: key.NewBinding(),
},
makeSelection: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("enter", "select"),
),
finalizeSelection: key.NewBinding(
key.WithKeys(" "),
key.WithHelp("space", "continue"),
),
}
return km
}
// ShortHelp returns the help text we want to show
func (k listKeyMap) ShortHelp() []key.Binding {
if currentModel != nil {
if m, ok := currentModel.(model); ok {
switch m.state {
case "selecting":
return []key.Binding{
k.makeSelection,
k.finalizeSelection,
key.NewBinding(
key.WithKeys("backspace"),
key.WithHelp("backspace", "deselect"),
),
}
case "naming":
return []key.Binding{
k.makeSelection,
}
default: // catalog state
return []key.Binding{
k.makeSelection,
}
}
}
}
return []key.Binding{
k.makeSelection,
}
}
// FullHelp returns the help text we want to show
func (k listKeyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{k.ShortHelp()}
}