|
61 | 61 | _IGNORED_MODS = _CAPSLOCK | _NUMLOCK |
62 | 62 |
|
63 | 63 |
|
64 | | -# Functional-key codes from the Kitty spec, mapped to the nearest |
65 | | -# existing prompt_toolkit `Keys` value. Only keys likely to appear under |
66 | | -# `disambiguate` (flag 1) are included. |
| 64 | +# Functional-key codes from the Kitty spec that can reach this decoder |
| 65 | +# under flag 1 ("disambiguate escape codes"), mapped to the nearest |
| 66 | +# existing prompt_toolkit `Keys` value. Everything else listed in the |
| 67 | +# spec's functional-key table keeps its legacy encoding under flag 1 |
| 68 | +# and travels through `ANSI_SEQUENCES` instead: |
| 69 | +# |
| 70 | +# - Arrow keys and the navigation block (Home / End / PageUp / |
| 71 | +# PageDown / Insert / Delete): legacy `CSI <letter>` / `CSI <n>~`. |
| 72 | +# - F1-F12: legacy `SS3 <letter>` (F1-F4) / `CSI <n>~` (F5-F12). |
| 73 | +# - CapsLock / ScrollLock / NumLock / PrintScreen / Pause / Menu: no |
| 74 | +# legacy encoding and no matching `Keys` enum, so out of scope here. |
| 75 | +# |
| 76 | +# What remains are the four keys whose single-byte legacy encoding |
| 77 | +# collides with a Ctrl+letter (Enter=\r=C-m, Tab=\t=C-i, Esc=\x1b=C-[, |
| 78 | +# Backspace=\x7f/C-h) — those are the only gestures flag 1 actually |
| 79 | +# re-encodes as `CSI u`. |
67 | 80 | _FUNCTIONAL: dict[int, Keys] = { |
68 | 81 | 13: Keys.ControlM, # Enter |
69 | 82 | 9: Keys.ControlI, # Tab |
70 | 83 | 27: Keys.Escape, |
71 | 84 | 127: Keys.ControlH, # Backspace |
72 | | - # 57358 = CapsLock, |
73 | | - # 57359 = ScrollLock, |
74 | | - # 57360 = NumLock, |
75 | | - # 57361 = PrintScreen, |
76 | | - # 57362 = Pause, |
77 | | - # 57363 = Menu — no corresponding `Keys` enum, so left out of the table. |
78 | | - 57364: Keys.F1, |
79 | | - 57365: Keys.F2, |
80 | | - 57366: Keys.F3, |
81 | | - 57367: Keys.F4, |
82 | | - 57368: Keys.F5, |
83 | | - 57369: Keys.F6, |
84 | | - 57370: Keys.F7, |
85 | | - 57371: Keys.F8, |
86 | | - 57372: Keys.F9, |
87 | | - 57373: Keys.F10, |
88 | | - 57374: Keys.F11, |
89 | | - 57375: Keys.F12, |
90 | 85 | } |
91 | 86 |
|
92 | 87 |
|
@@ -214,16 +209,11 @@ def _apply_modifiers(base: Keys, ctrl: bool, shift: bool) -> Keys: |
214 | 209 | Promote a plain functional `Keys` value to its richer Ctrl / Shift / |
215 | 210 | Ctrl-Shift variant when prompt_toolkit has an enum for it. |
216 | 211 |
|
217 | | - `base` is one of the unmodified functional keys from `_FUNCTIONAL` |
218 | | - (Enter, Tab, Escape, arrows, navigation block, F1–F12). `ctrl` and |
219 | | - `shift` are booleans decoded from the modifier mask; the Alt bit is |
220 | | - handled one level up in `decode_csi_u`, so it is intentionally not a |
| 212 | + `base` is one of the four unmodified functional keys from |
| 213 | + `_FUNCTIONAL` — Enter, Tab, Escape, Backspace. `ctrl` and `shift` |
| 214 | + are booleans decoded from the modifier mask; the Alt bit is handled |
| 215 | + one level up in `decode_csi_u`, so it is intentionally not a |
221 | 216 | parameter here. |
222 | | -
|
223 | | - When no matching richer enum exists (e.g. plain Shift-Enter, |
224 | | - Shift-Fn, Shift-Backspace), the base key is returned unchanged. The |
225 | | - caller should treat those as "modifier silently folded away" rather |
226 | | - than "decode failure". |
227 | 217 | """ |
228 | 218 | if base is Keys.ControlM: # Enter |
229 | 219 | if ctrl and shift: |
@@ -261,14 +251,4 @@ def _apply_modifiers(base: Keys, ctrl: bool, shift: bool) -> Keys: |
261 | 251 | return Keys.ShiftBackspace |
262 | 252 | return Keys.ControlH |
263 | 253 |
|
264 | | - # F1..F24 — Ctrl+ is a distinct enum; Shift+ is mapped to FN+12 in |
265 | | - # prompt_toolkit's existing convention (F1 → F13 etc.), but we don't |
266 | | - # emulate that here; Shift+Fn just returns Fn for now. |
267 | | - if base.value.startswith("f") and base.value[1:].isdigit(): |
268 | | - if ctrl: |
269 | | - ctrl_key: Keys | None = getattr(Keys, "Control" + base.name, None) |
270 | | - if ctrl_key is not None: |
271 | | - return ctrl_key |
272 | | - return base |
273 | | - |
274 | 254 | return base |
0 commit comments