Skip to content
Myr

key.go

This file

Path

key.go

371 lines · 10.0 KiB · Go

Last changed by

fix(key): map media record to ultraviolet code (#1757)Ricardo-M-Lbefore adoptiondc4b017

History of this file

Take it

The walk stopped after 200 commits: lines older than 3dfbcd9 point at it.

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 1–5why, one step back
1package tea
23import (4 "fmt"5

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 6why, one step back
6 uv "github.com/charmbracelet/ultraviolet"

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 7–9why, one step back
7)
89const (

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 10–12why, one step back
10 // KeyExtended is a special key code used to signify that a key event
11 // contains multiple runes.12 KeyExtended = uv.KeyExtended

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 13–14why, one step back
13)
14

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 15why, one step back
15// Special key symbols.

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 16–17why, one step back
16const (
17

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 18why, one step back
18 // Special keys.

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 19why, one step back
19

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 20–32why, one step back
20 KeyUp = uv.KeyUp
21 KeyDown = uv.KeyDown22 KeyRight = uv.KeyRight23 KeyLeft = uv.KeyLeft24 KeyBegin = uv.KeyBegin25 KeyFind = uv.KeyFind26 KeyInsert = uv.KeyInsert27 KeyDelete = uv.KeyDelete28 KeySelect = uv.KeySelect29 KeyPgUp = uv.KeyPgUp30 KeyPgDown = uv.KeyPgDown31 KeyHome = uv.KeyHome32 KeyEnd = uv.KeyEnd

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 33why, one step back
33

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 34why, one step back
34 // Keypad keys.

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 35why, one step back
35

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 36–53why, one step back
36 KeyKpEnter = uv.KeyKpEnter
37 KeyKpEqual = uv.KeyKpEqual38 KeyKpMultiply = uv.KeyKpMultiply39 KeyKpPlus = uv.KeyKpPlus40 KeyKpComma = uv.KeyKpComma41 KeyKpMinus = uv.KeyKpMinus42 KeyKpDecimal = uv.KeyKpDecimal43 KeyKpDivide = uv.KeyKpDivide44 KeyKp0 = uv.KeyKp045 KeyKp1 = uv.KeyKp146 KeyKp2 = uv.KeyKp247 KeyKp3 = uv.KeyKp348 KeyKp4 = uv.KeyKp449 KeyKp5 = uv.KeyKp550 KeyKp6 = uv.KeyKp651 KeyKp7 = uv.KeyKp752 KeyKp8 = uv.KeyKp853 KeyKp9 = uv.KeyKp9

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 54why, one step back
54

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 55–68why, one step back
55 // The following are keys defined in the Kitty keyboard protocol.
56 // XXX: Investigate the names of these keys.57 KeyKpSep = uv.KeyKpSep58 KeyKpUp = uv.KeyKpUp59 KeyKpDown = uv.KeyKpDown60 KeyKpLeft = uv.KeyKpLeft61 KeyKpRight = uv.KeyKpRight62 KeyKpPgUp = uv.KeyKpPgUp63 KeyKpPgDown = uv.KeyKpPgDown64 KeyKpHome = uv.KeyKpHome65 KeyKpEnd = uv.KeyKpEnd66 KeyKpInsert = uv.KeyKpInsert67 KeyKpDelete = uv.KeyKpDelete68 KeyKpBegin = uv.KeyKpBegin

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 69why, one step back
69

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 70why, one step back
70 // Function keys.

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 71why, one step back
71

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 72–134why, one step back
72 KeyF1 = uv.KeyF1
73 KeyF2 = uv.KeyF274 KeyF3 = uv.KeyF375 KeyF4 = uv.KeyF476 KeyF5 = uv.KeyF577 KeyF6 = uv.KeyF678 KeyF7 = uv.KeyF779 KeyF8 = uv.KeyF880 KeyF9 = uv.KeyF981 KeyF10 = uv.KeyF1082 KeyF11 = uv.KeyF1183 KeyF12 = uv.KeyF1284 KeyF13 = uv.KeyF1385 KeyF14 = uv.KeyF1486 KeyF15 = uv.KeyF1587 KeyF16 = uv.KeyF1688 KeyF17 = uv.KeyF1789 KeyF18 = uv.KeyF1890 KeyF19 = uv.KeyF1991 KeyF20 = uv.KeyF2092 KeyF21 = uv.KeyF2193 KeyF22 = uv.KeyF2294 KeyF23 = uv.KeyF2395 KeyF24 = uv.KeyF2496 KeyF25 = uv.KeyF2597 KeyF26 = uv.KeyF2698 KeyF27 = uv.KeyF2799 KeyF28 = uv.KeyF28100 KeyF29 = uv.KeyF29101 KeyF30 = uv.KeyF30102 KeyF31 = uv.KeyF31103 KeyF32 = uv.KeyF32104 KeyF33 = uv.KeyF33105 KeyF34 = uv.KeyF34106 KeyF35 = uv.KeyF35107 KeyF36 = uv.KeyF36108 KeyF37 = uv.KeyF37109 KeyF38 = uv.KeyF38110 KeyF39 = uv.KeyF39111 KeyF40 = uv.KeyF40112 KeyF41 = uv.KeyF41113 KeyF42 = uv.KeyF42114 KeyF43 = uv.KeyF43115 KeyF44 = uv.KeyF44116 KeyF45 = uv.KeyF45117 KeyF46 = uv.KeyF46118 KeyF47 = uv.KeyF47119 KeyF48 = uv.KeyF48120 KeyF49 = uv.KeyF49121 KeyF50 = uv.KeyF50122 KeyF51 = uv.KeyF51123 KeyF52 = uv.KeyF52124 KeyF53 = uv.KeyF53125 KeyF54 = uv.KeyF54126 KeyF55 = uv.KeyF55127 KeyF56 = uv.KeyF56128 KeyF57 = uv.KeyF57129 KeyF58 = uv.KeyF58130 KeyF59 = uv.KeyF59131 KeyF60 = uv.KeyF60132 KeyF61 = uv.KeyF61133 KeyF62 = uv.KeyF62134 KeyF63 = uv.KeyF63

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 135why, one step back
135

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 136–137why, one step back
136 // The following are keys defined in the Kitty keyboard protocol.
137 // XXX: Investigate the names of these keys.

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 138why, one step back
138

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 139–144why, one step back
139 KeyCapsLock = uv.KeyCapsLock
140 KeyScrollLock = uv.KeyScrollLock141 KeyNumLock = uv.KeyNumLock142 KeyPrintScreen = uv.KeyPrintScreen143 KeyPause = uv.KeyPause144 KeyMenu = uv.KeyMenu

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 145why, one step back
145

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 146–154why, one step back
146 KeyMediaPlay = uv.KeyMediaPlay
147 KeyMediaPause = uv.KeyMediaPause148 KeyMediaPlayPause = uv.KeyMediaPlayPause149 KeyMediaReverse = uv.KeyMediaReverse150 KeyMediaStop = uv.KeyMediaStop151 KeyMediaFastForward = uv.KeyMediaFastForward152 KeyMediaRewind = uv.KeyMediaRewind153 KeyMediaNext = uv.KeyMediaNext154 KeyMediaPrev = uv.KeyMediaPrev

fix(key): map media record to ultraviolet code (#1757)Ricardo-M-Lbefore adoptiondc4b017

line 155why, one step back
155 KeyMediaRecord = uv.KeyMediaRecord

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 156why, one step back
156

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 157–159why, one step back
157 KeyLowerVol = uv.KeyLowerVol
158 KeyRaiseVol = uv.KeyRaiseVol159 KeyMute = uv.KeyMute

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 160why, one step back
160

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 161–174why, one step back
161 KeyLeftShift = uv.KeyLeftShift
162 KeyLeftAlt = uv.KeyLeftAlt163 KeyLeftCtrl = uv.KeyLeftCtrl164 KeyLeftSuper = uv.KeyLeftSuper165 KeyLeftHyper = uv.KeyLeftHyper166 KeyLeftMeta = uv.KeyLeftMeta167 KeyRightShift = uv.KeyRightShift168 KeyRightAlt = uv.KeyRightAlt169 KeyRightCtrl = uv.KeyRightCtrl170 KeyRightSuper = uv.KeyRightSuper171 KeyRightHyper = uv.KeyRightHyper172 KeyRightMeta = uv.KeyRightMeta173 KeyIsoLevel3Shift = uv.KeyIsoLevel3Shift174 KeyIsoLevel5Shift = uv.KeyIsoLevel5Shift

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 175why, one step back
175

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 176why, one step back
176 // Special names in C0.

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 177why, one step back
177

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 178–183why, one step back
178 KeyBackspace = uv.KeyBackspace
179 KeyTab = uv.KeyTab180 KeyEnter = uv.KeyEnter181 KeyReturn = uv.KeyReturn182 KeyEscape = uv.KeyEscape183 KeyEsc = uv.KeyEsc

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 184why, one step back
184

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 185why, one step back
185 // Special names in G0.

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 186why, one step back
186

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 187–188why, one step back
187 KeySpace = uv.KeySpace
188)

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 189why, one step back
189

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 190–191why, one step back
190// KeyPressMsg represents a key press message.
191type KeyPressMsg Key

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 192why, one step back
192

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 193–197why, one step back
193// String implements [fmt.Stringer] and is quite useful for matching key
194// events. For details, on what this returns see [Key.String].195func (k KeyPressMsg) String() string {196 return Key(k).String()197}

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 198why, one step back
198

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 199–215why, one step back
199// Keystroke returns the keystroke representation of the [Key]. While less type
200// safe than looking at the individual fields, it will usually be more201// convenient and readable to use this method when matching against keys.202//203// Note that modifier keys are always printed in the following order:204// - ctrl205// - alt206// - shift207// - meta208// - hyper209// - super210//211// For example, you'll always see "ctrl+shift+alt+a" and never212// "shift+ctrl+alt+a".213func (k KeyPressMsg) Keystroke() string {214 return uv.Key(k).Keystroke()215}

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 216why, one step back
216

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 217–221why, one step back
217// Key returns the underlying key event. This is a syntactic sugar for casting
218// the key event to a [Key].219func (k KeyPressMsg) Key() Key {220 return Key(k)221}

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 222why, one step back
222

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 223–224why, one step back
223// KeyReleaseMsg represents a key release message.
224type KeyReleaseMsg Key

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 225why, one step back
225

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 226–230why, one step back
226// String implements [fmt.Stringer] and is quite useful for matching key
227// events. For details, on what this returns see [Key.String].228func (k KeyReleaseMsg) String() string {229 return Key(k).String()230}

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 231why, one step back
231

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 232–247why, one step back
232// Keystroke returns the keystroke representation of the [Key]. While less type
233// safe than looking at the individual fields, it will usually be more234// convenient and readable to use this method when matching against keys.235//236// Note that modifier keys are always printed in the following order:237// - ctrl238// - alt239// - shift240// - meta241// - hyper242// - super243//244// For example, you'll always see "ctrl+shift+alt+a" and never245// "shift+ctrl+alt+a".246func (k KeyReleaseMsg) Keystroke() string {247 return uv.Key(k).Keystroke()

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 248–249why, one step back
248}
249

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 250–254why, one step back
250// Key returns the underlying key event. This is a convenience method and
251// syntactic sugar to satisfy the [KeyMsg] interface, and cast the key event to252// [Key].253func (k KeyReleaseMsg) Key() Key {254 return Key(k)

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 255–256why, one step back
255}
256

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 257–260why, one step back
257// KeyMsg represents a key event. This can be either a key press or a key
258// release event.259type KeyMsg interface {260 fmt.Stringer

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 261why, one step back
261

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 262–263why, one step back
262 // Key returns the underlying key event.
263 Key() Key

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 264–265why, one step back
264}
265

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 266–306why, one step back
266// Key represents a Key press or release event. It contains information about
267// the Key pressed, like the runes, the type of Key, and the modifiers pressed.268// There are a couple general patterns you could use to check for key presses269// or releases:270//271// // Switch on the string representation of the key (shorter)272// switch msg := msg.(type) {273// case KeyPressMsg:274// switch msg.String() {275// case "enter":276// fmt.Println("you pressed enter!")277// case "a":278// fmt.Println("you pressed a!")279// }280// }281//282// // Switch on the key type (more foolproof)283// switch msg := msg.(type) {284// case KeyMsg:285// // catch both KeyPressMsg and KeyReleaseMsg286// switch key := msg.Key(); key.Code {287// case KeyEnter:288// fmt.Println("you pressed enter!")289// default:290// switch key.Text {291// case "a":292// fmt.Println("you pressed a!")293// }294// }295// }296//297// Note that [Key.Text] will be empty for special keys like [KeyEnter],298// [KeyTab], and for keys that don't represent printable characters like key299// combos with modifier keys. In other words, [Key.Text] is populated only for300// keys that represent printable characters shifted or unshifted (like 'a',301// 'A', '1', '!', etc.).302type Key struct {303 // Text contains the actual characters received. This usually the same as304 // [Key.Code]. When [Key.Text] is non-empty, it indicates that the key305 // pressed represents printable character(s).306 Text string

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 307why, one step back
307

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 308–309why, one step back
308 // Mod represents modifier keys, like [ModCtrl], [ModAlt], and so on.
309 Mod KeyMod

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 310why, one step back
310

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 311–313why, one step back
311 // Code represents the key pressed. This is usually a special key like
312 // [KeyTab], [KeyEnter], [KeyF1], or a printable character like 'a'.313 Code rune

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 314why, one step back
314

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 315–324why, one step back
315 // ShiftedCode is the actual, shifted key pressed by the user. For example,
316 // if the user presses shift+a, or caps lock is on, [Key.ShiftedCode] will317 // be 'A' and [Key.Code] will be 'a'.318 //319 // In the case of non-latin keyboards, like Arabic, [Key.ShiftedCode] is the320 // unshifted key on the keyboard.321 //322 // This is only available with the Kitty Keyboard Protocol or the Windows323 // Console API.324 ShiftedCode rune

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 325why, one step back
325

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 326–335why, one step back
326 // BaseCode is the key pressed according to the standard PC-101 key layout.
327 // On international keyboards, this is the key that would be pressed if the328 // keyboard was set to US PC-101 layout.329 //330 // For example, if the user presses 'q' on a French AZERTY keyboard,331 // [Key.BaseCode] will be 'q'.332 //333 // This is only available with the Kitty Keyboard Protocol or the Windows334 // Console API.335 BaseCode rune

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 336why, one step back
336

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 337–342why, one step back
337 // IsRepeat indicates whether the key is being held down and sending events
338 // repeatedly.339 //340 // This is only available with the Kitty Keyboard Protocol or the Windows341 // Console API.342 IsRepeat bool

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 343–344why, one step back
343}
344

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 345–353why, one step back
345// String implements [fmt.Stringer] and is quite useful for matching key
346// events. It will return the textual representation of the [Key] if there is347// one, otherwise, it will fallback to [Key.Keystroke].348//349// For example, you'll always get "?" and instead of "shift+/" on a US ANSI350// keyboard.351func (k Key) String() string {352 return uv.Key(k).String()353}

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 354why, one step back
354

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 355–370why, one step back
355// Keystroke returns the keystroke representation of the [Key]. While less type
356// safe than looking at the individual fields, it will usually be more357// convenient and readable to use this method when matching against keys.358//359// Note that modifier keys are always printed in the following order:360// - ctrl361// - alt362// - shift363// - meta364// - hyper365// - super366//367// For example, you'll always see "ctrl+shift+alt+a" and never368// "shift+ctrl+alt+a".369func (k Key) Keystroke() string {370 return uv.Key(k).Keystroke()

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 371why, one step back
371}