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 fileTake 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 back1package tea23import (4 "fmt"5Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
line 6why, one step back6 uv "github.com/charmbracelet/ultraviolet"feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 7–9why, one step back7)89const (Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 10–12why, one step back10 // KeyExtended is a special key code used to signify that a key event11 // contains multiple runes.12 KeyExtended = uv.KeyExtendedfeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 13–14why, one step back13)14Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
line 15why, one step back15// Special key symbols.feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 16–17why, one step back16const (17Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
line 18why, one step back18 // Special keys.feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 19why, one step back19Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 20–32why, one step back20 KeyUp = uv.KeyUp21 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.KeyEndfeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 33why, one step back33Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
line 34why, one step back34 // Keypad keys.feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 35why, one step back35Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 36–53why, one step back36 KeyKpEnter = uv.KeyKpEnter37 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.KeyKp9feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 54why, one step back54Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 55–68why, one step back55 // 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.KeyKpBeginfeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 69why, one step back69Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
line 70why, one step back70 // Function keys.feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 71why, one step back71Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 72–134why, one step back72 KeyF1 = uv.KeyF173 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.KeyF63feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 135why, one step back135Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 136–137why, one step back136 // 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 back138Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 139–144why, one step back139 KeyCapsLock = uv.KeyCapsLock140 KeyScrollLock = uv.KeyScrollLock141 KeyNumLock = uv.KeyNumLock142 KeyPrintScreen = uv.KeyPrintScreen143 KeyPause = uv.KeyPause144 KeyMenu = uv.KeyMenufeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 145why, one step back145Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 146–154why, one step back146 KeyMediaPlay = uv.KeyMediaPlay147 KeyMediaPause = uv.KeyMediaPause148 KeyMediaPlayPause = uv.KeyMediaPlayPause149 KeyMediaReverse = uv.KeyMediaReverse150 KeyMediaStop = uv.KeyMediaStop151 KeyMediaFastForward = uv.KeyMediaFastForward152 KeyMediaRewind = uv.KeyMediaRewind153 KeyMediaNext = uv.KeyMediaNext154 KeyMediaPrev = uv.KeyMediaPrevfix(key): map media record to ultraviolet code (#1757)Ricardo-M-Lbefore adoptiondc4b017
line 155why, one step back155 KeyMediaRecord = uv.KeyMediaRecordfeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 156why, one step back156Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 157–159why, one step back157 KeyLowerVol = uv.KeyLowerVol158 KeyRaiseVol = uv.KeyRaiseVol159 KeyMute = uv.KeyMutefeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 160why, one step back160Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 161–174why, one step back161 KeyLeftShift = uv.KeyLeftShift162 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.KeyIsoLevel5Shiftfeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 175why, one step back175Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
line 176why, one step back176 // Special names in C0.feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 177why, one step back177Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 178–183why, one step back178 KeyBackspace = uv.KeyBackspace179 KeyTab = uv.KeyTab180 KeyEnter = uv.KeyEnter181 KeyReturn = uv.KeyReturn182 KeyEscape = uv.KeyEscape183 KeyEsc = uv.KeyEscfeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 184why, one step back184Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
line 185why, one step back185 // Special names in G0.feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 186why, one step back186Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 187–188why, one step back187 KeySpace = uv.KeySpace188)feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 189why, one step back189Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 190–191why, one step back190// KeyPressMsg represents a key press message.191type KeyPressMsg Keyfeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 192why, one step back192Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 193–197why, one step back193// String implements [fmt.Stringer] and is quite useful for matching key194// 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 back198Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 199–215why, one step back199// Keystroke returns the keystroke representation of the [Key]. While less type200// 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 back216Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 217–221why, one step back217// Key returns the underlying key event. This is a syntactic sugar for casting218// 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 back222Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 223–224why, one step back223// KeyReleaseMsg represents a key release message.224type KeyReleaseMsg Keyfeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 225why, one step back225Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 226–230why, one step back226// String implements [fmt.Stringer] and is quite useful for matching key227// 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 back231Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 232–247why, one step back232// Keystroke returns the keystroke representation of the [Key]. While less type233// 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 back248}249Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 250–254why, one step back250// Key returns the underlying key event. This is a convenience method and251// 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 back255}256Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 257–260why, one step back257// KeyMsg represents a key event. This can be either a key press or a key258// release event.259type KeyMsg interface {260 fmt.Stringerfeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 261why, one step back261Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 262–263why, one step back262 // Key returns the underlying key event.263 Key() Keyfeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 264–265why, one step back264}265Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 266–306why, one step back266// Key represents a Key press or release event. It contains information about267// 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 stringfeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 307why, one step back307Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 308–309why, one step back308 // Mod represents modifier keys, like [ModCtrl], [ModAlt], and so on.309 Mod KeyModfeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 310why, one step back310Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 311–313why, one step back311 // Code represents the key pressed. This is usually a special key like312 // [KeyTab], [KeyEnter], [KeyF1], or a printable character like 'a'.313 Code runefeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 314why, one step back314Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 315–324why, one step back315 // 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 runefeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 325why, one step back325Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 326–335why, one step back326 // 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 runefeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 336why, one step back336Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 337–342why, one step back337 // IsRepeat indicates whether the key is being held down and sending events338 // repeatedly.339 //340 // This is only available with the Kitty Keyboard Protocol or the Windows341 // Console API.342 IsRepeat boolfeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 343–344why, one step back343}344Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 345–353why, one step back345// String implements [fmt.Stringer] and is quite useful for matching key346// 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 back354Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 355–370why, one step back355// Keystroke returns the keystroke representation of the [Key]. While less type356// 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 back371}