forked from savannahostrowski/tree-bubble
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeymap.go
More file actions
84 lines (74 loc) · 1.57 KB
/
keymap.go
File metadata and controls
84 lines (74 loc) · 1.57 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
84
package tree
import "charm.land/bubbles/v2/key"
// KeyMap holds the key bindings for the table.
type KeyMap struct {
Bottom key.Binding
Top key.Binding
NextChild key.Binding
Parent key.Binding
Down key.Binding
Up key.Binding
Quit key.Binding
ShowFullHelp key.Binding
CloseFullHelp key.Binding
}
// DefaultKeyMap is the default key bindings for the table.
func DefaultKeyMap() KeyMap {
return KeyMap{
Bottom: key.NewBinding(
key.WithKeys("bottom"),
key.WithHelp("end", "bottom"),
),
Top: key.NewBinding(
key.WithKeys("top"),
key.WithHelp("home", "top"),
),
Parent: key.NewBinding(
key.WithKeys("left"),
key.WithHelp("←", "go to parent"),
),
Down: key.NewBinding(
key.WithKeys("down"),
key.WithHelp("↓", "down"),
),
Up: key.NewBinding(
key.WithKeys("up"),
key.WithHelp("↑", "up"),
),
ShowFullHelp: key.NewBinding(
key.WithKeys("?"),
key.WithHelp("?", "help"),
),
CloseFullHelp: key.NewBinding(
key.WithKeys("?"),
key.WithHelp("?", "close help"),
),
Quit: key.NewBinding(
key.WithKeys("q", "esc"),
key.WithHelp("q", "quit"),
),
}
}
func (m Model) helpView() string {
return m.Styles.Help.Render(m.Help.View(m))
}
func (m Model) ShortHelp() []key.Binding {
return []key.Binding{
m.KeyMap.Up,
m.KeyMap.Down,
m.KeyMap.ShowFullHelp,
m.KeyMap.Quit,
}
}
func (m Model) FullHelp() [][]key.Binding {
kb := [][]key.Binding{{
m.KeyMap.Up,
m.KeyMap.Down,
m.KeyMap.Parent,
}}
return append(kb,
[]key.Binding{
m.KeyMap.Quit,
m.KeyMap.CloseFullHelp,
})
}