From 46ddf9ac0ebb3bc1935275a3ab3f87381bc6a4fa Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 9 Oct 2023 11:23:31 +0100 Subject: [PATCH] Add a debug hook for getting sent unknown sequences from the XTerm parser This is here only for serving the keyboard checker/recorder tool. --- src/textual/_xterm_parser.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/textual/_xterm_parser.py b/src/textual/_xterm_parser.py index edf587a3f9..d3653dc3d5 100644 --- a/src/textual/_xterm_parser.py +++ b/src/textual/_xterm_parser.py @@ -84,6 +84,13 @@ def parse_mouse_code(self, code: str) -> events.Event | None: return event return None + _reissued_sequence_debug_book: Callable[[str], None] | None = None + """INTERNAL USE ONLY! + + If this property is set to a callable, it will be called *instead* of + the reissued sequence being emitted as key events. + """ + def parse(self, on_token: TokenCallback) -> Generator[Awaitable, str, None]: ESC = "\x1b" read1 = self.read1 @@ -94,6 +101,9 @@ def parse(self, on_token: TokenCallback) -> Generator[Awaitable, str, None]: use_prior_escape = False def reissue_sequence_as_keys(reissue_sequence: str) -> None: + if self._reissued_sequence_debug_book is not None: + self._reissued_sequence_debug_book(reissue_sequence) + return for character in reissue_sequence: key_events = sequence_to_key_events(character) for event in key_events: