-
Notifications
You must be signed in to change notification settings - Fork 0
/
keys.go
153 lines (136 loc) · 2.8 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
package ui
import (
"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list"
)
func DefaultKeyMap() KeyMap {
defaultRootKeyMap := RootKeyMap{
Quit: key.NewBinding(
key.WithKeys("esc", "ctrl+c"),
key.WithHelp("esc, ctrl+c", "quit"),
),
}
return KeyMap{
RootKeyMap: defaultRootKeyMap,
TableKeyMap: TableKeyMap{
RootKeyMap: defaultRootKeyMap,
Search: key.NewBinding(
key.WithKeys("/"),
key.WithHelp("/", "search"),
),
Describe: key.NewBinding(
key.WithKeys("d"),
key.WithHelp("d", "describe"),
),
Logs: key.NewBinding(
key.WithKeys("l"),
key.WithHelp("l", "logs"),
),
Delete: key.NewBinding(
key.WithKeys("x"),
key.WithHelp("x", "delete"),
),
Actions: key.NewBinding(
key.WithKeys("t"),
key.WithHelp("t", "actions"),
),
ToggleAltView: key.NewBinding(
key.WithKeys("g"),
key.WithHelp("g", "view ids"),
),
},
ConfirmKeyMap: ConfirmKeyMap{
RootKeyMap: defaultRootKeyMap,
Confirm: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("enter", "to confirm deletion"),
),
},
ActionsKeyMap: ActionsKeyMap{
RootKeyMap: defaultRootKeyMap,
Do: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("enter", "to execute action"),
),
ListKeyMap: list.DefaultKeyMap(),
},
}
}
type KeyMap struct {
RootKeyMap
TableKeyMap
ConfirmKeyMap
ActionsKeyMap
}
func (m KeyMap) Get(focused Focused) help.KeyMap {
switch focused {
case TableFocused:
return m.TableKeyMap
case ConfirmFocused:
return m.ConfirmKeyMap
case ActionsFocused:
return m.ActionsKeyMap
default:
return m.RootKeyMap
}
}
// Those are the keybindings that are available in all scenes.
type RootKeyMap struct {
Quit key.Binding
}
func (m RootKeyMap) ShortHelp() []key.Binding {
return []key.Binding{m.Quit}
}
func (m RootKeyMap) FullHelp() [][]key.Binding {
return nil
}
type TableKeyMap struct {
RootKeyMap
Search key.Binding
Describe key.Binding
Logs key.Binding
Delete key.Binding
Actions key.Binding
ToggleAltView key.Binding
}
func (m TableKeyMap) ShortHelp() []key.Binding {
return []key.Binding{
m.Search,
m.Describe,
m.Logs,
m.Delete,
m.Actions,
m.ToggleAltView,
m.Quit,
}
}
func (m TableKeyMap) FullHelp() [][]key.Binding {
return nil
}
type ConfirmKeyMap struct {
RootKeyMap
Confirm key.Binding
}
func (m ConfirmKeyMap) ShortHelp() []key.Binding {
return []key.Binding{
m.Confirm,
m.Quit,
}
}
func (m ConfirmKeyMap) FullHelp() [][]key.Binding {
return nil
}
type ActionsKeyMap struct {
RootKeyMap
Do key.Binding
ListKeyMap list.KeyMap
}
func (m ActionsKeyMap) ShortHelp() []key.Binding {
return []key.Binding{
m.Do,
m.ListKeyMap.CursorUp,
m.ListKeyMap.CursorDown,
m.Quit,
}
}