1package keymap
2
3import "github.com/charmbracelet/bubbles/v2/key"
4
5// KeyMap is a map of key bindings for the UI.
6type KeyMap struct {
7 Quit key.Binding
8 Up key.Binding
9 Down key.Binding
10 UpDown key.Binding
11 LeftRight key.Binding
12 Arrows key.Binding
13 GotoTop key.Binding
14 GotoBottom key.Binding
15 Select key.Binding
16 Section key.Binding
17 Back key.Binding
18 PrevPage key.Binding
19 NextPage key.Binding
20 Help key.Binding
21
22 SelectItem key.Binding
23 BackItem key.Binding
24
25 Copy key.Binding
26}
27
28// DefaultKeyMap returns the default key map.
29func DefaultKeyMap() *KeyMap {
30 km := new(KeyMap)
31
32 km.Quit = key.NewBinding(
33 key.WithKeys(
34 "q",
35 "ctrl+c",
36 ),
37 key.WithHelp(
38 "q",
39 "quit",
40 ),
41 )
42
43 km.Up = key.NewBinding(
44 key.WithKeys(
45 "up",
46 "k",
47 ),
48 key.WithHelp(
49 "↑",
50 "up",
51 ),
52 )
53
54 km.Down = key.NewBinding(
55 key.WithKeys(
56 "down",
57 "j",
58 ),
59 key.WithHelp(
60 "↓",
61 "down",
62 ),
63 )
64
65 km.UpDown = key.NewBinding(
66 key.WithKeys(
67 "up",
68 "down",
69 "k",
70 "j",
71 ),
72 key.WithHelp(
73 "↑↓",
74 "navigate",
75 ),
76 )
77
78 km.LeftRight = key.NewBinding(
79 key.WithKeys(
80 "left",
81 "h",
82 "right",
83 "l",
84 ),
85 key.WithHelp(
86 "←→",
87 "navigate",
88 ),
89 )
90
91 km.Arrows = key.NewBinding(
92 key.WithKeys(
93 "up",
94 "right",
95 "down",
96 "left",
97 "k",
98 "j",
99 "h",
100 "l",
101 ),
102 key.WithHelp(
103 "↑←↓→",
104 "navigate",
105 ),
106 )
107
108 km.GotoTop = key.NewBinding(
109 key.WithKeys(
110 "home",
111 "g",
112 ),
113 key.WithHelp(
114 "g/home",
115 "goto top",
116 ),
117 )
118
119 km.GotoBottom = key.NewBinding(
120 key.WithKeys(
121 "end",
122 "G",
123 ),
124 key.WithHelp(
125 "G/end",
126 "goto bottom",
127 ),
128 )
129
130 km.Select = key.NewBinding(
131 key.WithKeys(
132 "enter",
133 ),
134 key.WithHelp(
135 "enter",
136 "select",
137 ),
138 )
139
140 km.Section = key.NewBinding(
141 key.WithKeys(
142 "tab",
143 "shift+tab",
144 ),
145 key.WithHelp(
146 "tab",
147 "section",
148 ),
149 )
150
151 km.Back = key.NewBinding(
152 key.WithKeys(
153 "esc",
154 ),
155 key.WithHelp(
156 "esc",
157 "back",
158 ),
159 )
160
161 km.PrevPage = key.NewBinding(
162 key.WithKeys(
163 "pgup",
164 "b",
165 "u",
166 ),
167 key.WithHelp(
168 "pgup",
169 "prev page",
170 ),
171 )
172
173 km.NextPage = key.NewBinding(
174 key.WithKeys(
175 "pgdown",
176 "f",
177 "d",
178 ),
179 key.WithHelp(
180 "pgdn",
181 "next page",
182 ),
183 )
184
185 km.Help = key.NewBinding(
186 key.WithKeys(
187 "?",
188 ),
189 key.WithHelp(
190 "?",
191 "toggle help",
192 ),
193 )
194
195 km.SelectItem = key.NewBinding(
196 key.WithKeys(
197 "l",
198 "right",
199 ),
200 key.WithHelp(
201 "→/l",
202 "select",
203 ),
204 )
205
206 km.BackItem = key.NewBinding(
207 key.WithKeys(
208 "h",
209 "left",
210 "backspace",
211 ),
212 key.WithHelp(
213 "←/h",
214 "back",
215 ),
216 )
217
218 km.Copy = key.NewBinding(
219 key.WithKeys(
220 "c",
221 "ctrl+c",
222 ),
223 key.WithHelp(
224 "c",
225 "copy text",
226 ),
227 )
228
229 return km
230}