Skip to content

Commit be8581e

Browse files
authored
Merge pull request #3769 from davep/simplify-some-rxvt-sequences
Simplify some sequences that seem unique to rxvt
2 parents a3e91d4 + 0c19777 commit be8581e

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313
- `link-hover-background` renamed to `link-background-hover`
1414
- `link-hover-color` renamed to `link-color-hover`
1515
- `link-hover-style` renamed to `link-style-hover`
16+
- Brought rxvt's use of shift-numpad keys in line with most other terminals https://github.com/Textualize/textual/pull/3769
1617

1718
### Added
1819

src/textual/_ansi_sequences.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
from __future__ import annotations
2+
13
from typing import Mapping, Tuple
24

35
from .keys import Keys
46

57
# Mapping of vt100 escape codes to Keys.
6-
ANSI_SEQUENCES_KEYS: Mapping[str, Tuple[Keys, ...]] = {
8+
ANSI_SEQUENCES_KEYS: Mapping[str, Tuple[Keys, ...] | str] = {
79
# Control keys.
810
" ": (Keys.Space,),
911
"\r": (Keys.Enter,),
@@ -350,6 +352,24 @@
350352
"\x1b[1;8w": (Keys.Escape, Keys.ControlShift7),
351353
"\x1b[1;8x": (Keys.Escape, Keys.ControlShift8),
352354
"\x1b[1;8y": (Keys.Escape, Keys.ControlShift9),
355+
# Simplify some sequences that appear to be unique to rxvt; see
356+
# https://github.com/Textualize/textual/issues/3741 for context.
357+
"\x1bOj": "*",
358+
"\x1bOk": "+",
359+
"\x1bOm": "-",
360+
"\x1bOn": ".",
361+
"\x1bOo": "/",
362+
"\x1bOp": "0",
363+
"\x1bOq": "1",
364+
"\x1bOr": "2",
365+
"\x1bOs": "3",
366+
"\x1bOt": "4",
367+
"\x1bOu": "5",
368+
"\x1bOv": "6",
369+
"\x1bOw": "7",
370+
"\x1bOx": "8",
371+
"\x1bOy": "9",
372+
"\x1bOM": (Keys.Enter,),
353373
}
354374

355375
# https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036

src/textual/_xterm_parser.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,20 @@ def _sequence_to_key_events(
243243
Keys
244244
"""
245245
keys = ANSI_SEQUENCES_KEYS.get(sequence)
246-
if keys is not None:
246+
if isinstance(keys, tuple):
247+
# If the sequence mapped to a tuple, then it's values from the
248+
# `Keys` enum. Raise key events from what we find in the tuple.
247249
for key in keys:
248250
yield events.Key(key.value, sequence if len(sequence) == 1 else None)
249-
elif len(sequence) == 1:
251+
return
252+
# If keys is a string, the intention is that it's a mapping to a
253+
# character, which should really be treated as the sequence for the
254+
# purposes of the next step...
255+
if isinstance(keys, str):
256+
sequence = keys
257+
# If the sequence is a single character, attempt to process it as a
258+
# key.
259+
if len(sequence) == 1:
250260
try:
251261
if not sequence.isalnum():
252262
name = _character_to_key(sequence)

0 commit comments

Comments
 (0)