Skip to content
Myr

Add ability to type AltGr characters in FullscreenRenderer on Windows.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Vlastimil Ovčáčík · committed by Junegunn Choi · parent 00fb486 · Browse files · 2 files+32 added−17 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+32 added−17 removed

  • other:+32 added−17 removed

2 files+32 added−17 removed

modified:src/tui/tcell_test.go+19 added-14 removed
86 unmodified lines
87 // Ctrl+Alt keys88 {giveKey{tcell.KeyCtrlA, rune(tcell.KeyCtrlA), tcell.ModCtrl | tcell.ModAlt}, wantKey{CtrlAlt, 'a', nil}}, // fabricated89 {giveKey{tcell.KeyCtrlA, rune(tcell.KeyCtrlA), tcell.ModCtrl | tcell.ModAlt | tcell.ModShift}, wantKey{CtrlAlt, 'a', nil}}, // fabricated9091 /*92 "Input method" in Windows Language options:93 US: "US Keyboard" does not generate any characters (and thus any events) in Ctrl+Alt+[a-z] range94 CS: "Czech keyboard"95 DE: "German keyboard"9697 Note that right Alt is not just `tcell.ModAlt` on foreign language keyboards, but it is the AltGr `tcell.ModCtrl|tcell.ModAlt`.98 */99 {giveKey{tcell.KeyRune, '{', tcell.ModCtrl | tcell.ModAlt}, wantKey{Alt, '{', nil}}, // CS: Ctrl+Alt+b = "{"100 {giveKey{tcell.KeyRune, '{', tcell.ModCtrl | tcell.ModAlt}, wantKey{Alt, '{', nil}}, // DE: Ctrl+Alt+7 = "{"101 {giveKey{tcell.KeyRune, '@', tcell.ModCtrl | tcell.ModAlt}, wantKey{Alt, '@', nil}}, // DE: Ctrl+Alt+q = "@"102 {giveKey{tcell.KeyRune, 'µ', tcell.ModCtrl | tcell.ModAlt}, wantKey{Alt, 'µ', nil}}, // DE: Ctrl+Alt+m = "µ"10391 // section 2: Ctrl+[ \]_]92 {giveKey{tcell.KeyCtrlSpace, rune(tcell.KeyCtrlSpace), tcell.ModCtrl}, wantKey{CtrlSpace, 0, nil}}, // fabricated93 {giveKey{tcell.KeyNUL, rune(tcell.KeyNUL), tcell.ModNone}, wantKey{CtrlSpace, 0, nil}}, // fabricated, unhandled94 {giveKey{tcell.KeyRune, ' ', tcell.ModCtrl}, wantKey{Rune, ' ', nil}}, // actual Ctrl+' '
37 unmodified lines
132 {giveKey{tcell.KeyCenter, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // fabricated, unhandled133 // section 5: (Insert|Home|Delete|End|PgUp|PgDn|BackTab|F1-F12)134 {giveKey{tcell.KeyInsert, 0, tcell.ModNone}, wantKey{Insert, 0, nil}},135 {giveKey{tcell.KeyF1, 0, tcell.ModNone}, wantKey{F1, 0, nil}},149 // section 6: (Alt)+'rune'136 // section 6: (Ctrl+Alt)+'rune'137 {giveKey{tcell.KeyRune, 'a', tcell.ModNone}, wantKey{Rune, 'a', nil}},138 {giveKey{tcell.KeyRune, 'a', tcell.ModCtrl}, wantKey{Rune, 'a', nil}}, // fabricated139 {giveKey{tcell.KeyRune, 'a', tcell.ModAlt}, wantKey{Alt, 'a', nil}},140 {giveKey{tcell.KeyRune, 'A', tcell.ModAlt}, wantKey{Alt, 'A', nil}},141 {giveKey{tcell.KeyRune, '`', tcell.ModAlt}, wantKey{Alt, '`', nil}},142 /*143 "Input method" in Windows Language options:144 US: "US Keyboard" does not generate any characters (and thus any events) in Ctrl+Alt+[a-z] range145 CS: "Czech keyboard"146 DE: "German keyboard"147148 Note that right Alt is not just `tcell.ModAlt` on foreign language keyboards, but it is the AltGr `tcell.ModCtrl|tcell.ModAlt`.149 */150 {giveKey{tcell.KeyRune, '{', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '{', nil}}, // CS: Ctrl+Alt+b = "{" // Note that this does not interfere with CtrlB, since the "b" is replaced with "{" on OS level151 {giveKey{tcell.KeyRune, '$', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '$', nil}}, // CS: Ctrl+Alt+ů = "$"152 {giveKey{tcell.KeyRune, '~', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '~', nil}}, // CS: Ctrl+Alt++ = "~"153 {giveKey{tcell.KeyRune, '`', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '`', nil}}, // CS: Ctrl+Alt+ý,Space = "`" // this is dead key, space is required to emit the char154155 {giveKey{tcell.KeyRune, '{', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '{', nil}}, // DE: Ctrl+Alt+7 = "{"156 {giveKey{tcell.KeyRune, '@', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '@', nil}}, // DE: Ctrl+Alt+q = "@"157 {giveKey{tcell.KeyRune, 'µ', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, 'µ', nil}}, // DE: Ctrl+Alt+m = "µ"158159 // section 7: Esc160 // KeyEsc and KeyEscape are aliases for KeyESC161 {giveKey{tcell.KeyEsc, rune(tcell.KeyEsc), tcell.ModNone}, wantKey{ESC, 0, nil}}, // fabricated162 {giveKey{tcell.KeyESC, rune(tcell.KeyESC), tcell.ModNone}, wantKey{ESC, 0, nil}}, // unhandled
229 unmodified lines
modified:src/tui/tcell.go+13 added-3 removed
222 unmodified lines
223 // process keyboard:224 case *tcell.EventKey:225 mods := ev.Modifiers()226 alt := (mods & tcell.ModAlt) > 0227 ctrl := (mods & tcell.ModCtrl) > 0228 shift := (mods & tcell.ModShift) > 0229 ctrlAlt := ctrl && alt230 altShift := alt && shift231232 keyfn := func(r rune) Event {233 if alt {234 return CtrlAltKey(r)235 }
154 unmodified lines
390 return Event{F11, 0, nil}391 case tcell.KeyF12:392 return Event{F12, 0, nil}393391 // section 6: (Alt)+'rune'394 // section 6: (Ctrl+Alt)+'rune'395 case tcell.KeyRune:396 r := ev.Rune()394 if alt {397398 switch {399 // handle AltGr characters400 case ctrlAlt:401 return Event{Rune, r, nil} // dropping modifiers402 // simple characters (possibly with modifier)403 case alt:404 return AltKey(r)405 default:406 return Event{Rune, r, nil}407 }397 return Event{Rune, r, nil}408409 // section 7: Esc410 case tcell.KeyEsc:411 return Event{ESC, 0, nil}
253 unmodified lines