-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkeymap.go
More file actions
78 lines (72 loc) · 1.83 KB
/
keymap.go
File metadata and controls
78 lines (72 loc) · 1.83 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
package tui
import (
"github.com/charmbracelet/bubbles/key"
)
// DefaultKeyMap defines a set of keybindings. To work for Help it must satisfy
// key.Map. It could also very easily be a map[string]key.Binding.
type DefaultKeyMap struct {
Up key.Binding
Down key.Binding
Left key.Binding
Right key.Binding
Help key.Binding
Quit key.Binding
Console key.Binding
}
// ShortHelp returns keybindings to be shown in the mini Help view. It's part
// of the key.Map interface.
func (k DefaultKeyMap) ShortHelp() []key.Binding {
return []key.Binding{k.Help, k.Quit}
}
// FullHelp returns keybindings for the expanded Help view. It's part of the
// key.Map interface.
func (k DefaultKeyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{k.Up, k.Down, k.Left, k.Right}, // first column
{k.Help, k.Quit}, // second column
}
}
var DefaultKeys = DefaultKeyMap{
Up: key.NewBinding(
key.WithKeys("up", "k"),
key.WithHelp("↑/k", "move up"),
),
Down: key.NewBinding(
key.WithKeys("down", "j"),
key.WithHelp("↓/j", "move down"),
),
Left: key.NewBinding(
key.WithKeys("left", "h"),
key.WithHelp("←/h", "move left"),
),
Right: key.NewBinding(
key.WithKeys("right", "l"),
key.WithHelp("→/l", "move right"),
),
Help: key.NewBinding(
key.WithKeys("?"),
key.WithHelp("?", "toggle Help"),
),
Quit: key.NewBinding(
key.WithKeys("ctrl+q", "esc", "ctrl+c"),
key.WithHelp("ctrl+q", "quit"),
),
Console: key.NewBinding(
key.WithKeys(":"),
key.WithHelp(":", "input command"),
),
}
var DefaultShortKeys = DefaultKeyMap{
Help: key.NewBinding(
key.WithKeys("?"),
key.WithHelp("?", "toggle Help"),
),
Quit: key.NewBinding(
key.WithKeys("ctrl+q", "esc", "ctrl+c"),
key.WithHelp("ctrl+q", "quit"),
),
Console: key.NewBinding(
key.WithKeys(":"),
key.WithHelp(":", "input command"),
),
}