-
Notifications
You must be signed in to change notification settings - Fork 4
/
help.go
73 lines (68 loc) · 1.51 KB
/
help.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
package ui
import "github.com/charmbracelet/bubbles/key"
type KeyMap struct {
Up key.Binding
Down key.Binding
Left key.Binding
Right key.Binding
TabUp key.Binding
TabDown key.Binding
Select key.Binding
Copy key.Binding
Quit key.Binding
Help key.Binding
}
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"),
),
Left: key.NewBinding(
key.WithKeys("left"),
key.WithHelp("←", "move left"),
),
Right: key.NewBinding(
key.WithKeys("right"),
key.WithHelp("→", "move right"),
),
TabUp: key.NewBinding(
key.WithKeys("shift+tab"),
key.WithHelp("⇧ + tab", "prev section"),
),
TabDown: key.NewBinding(
key.WithKeys("tab/space"),
key.WithHelp("tab/space", "next section"),
),
Select: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("enter", "select"),
),
Copy: key.NewBinding(
key.WithKeys("ctrl+c"),
key.WithHelp("ctrl+c", "copy command"),
),
Quit: key.NewBinding(
key.WithKeys("q", "esc"),
key.WithHelp("q", "quit"),
),
Help: key.NewBinding(
key.WithKeys("?"),
key.WithHelp("?", "toggle help"),
),
}
}
func (k KeyMap) ShortHelp() []key.Binding {
return []key.Binding{k.Help, k.Quit}
}
func (k KeyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{k.Up, k.Down, k.Left, k.Right},
{k.TabDown, k.TabUp, k.Select, k.Copy},
{k.Help, k.Quit},
}
}