File tree Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
13from typing import Mapping , Tuple
24
35from .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 ,),
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+ "\x1b Oj" : "*" ,
358+ "\x1b Ok" : "+" ,
359+ "\x1b Om" : "-" ,
360+ "\x1b On" : "." ,
361+ "\x1b Oo" : "/" ,
362+ "\x1b Op" : "0" ,
363+ "\x1b Oq" : "1" ,
364+ "\x1b Or" : "2" ,
365+ "\x1b Os" : "3" ,
366+ "\x1b Ot" : "4" ,
367+ "\x1b Ou" : "5" ,
368+ "\x1b Ov" : "6" ,
369+ "\x1b Ow" : "7" ,
370+ "\x1b Ox" : "8" ,
371+ "\x1b Oy" : "9" ,
372+ "\x1b OM" : (Keys .Enter ,),
353373}
354374
355375# https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments