From d7449c12aa207f6591736c4e674a1a40f27253cc Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Wed, 9 Jul 2025 15:12:02 +0100 Subject: [PATCH] fix: fix regexes for mouse escape sequences Fix potential issues with the regexes for mouse escape sequences, which were recently updated to allow negative coordinates. - Fix the updated character class `[-?\d;]`. This will match the literal character `?` which I assume was not the intention. - Fix the regex for SGR mouse sequences, where the first parameter is the button value and should not be negative. --- src/textual/_xterm_parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/textual/_xterm_parser.py b/src/textual/_xterm_parser.py index 431a4866e7..fc9f4baa61 100644 --- a/src/textual/_xterm_parser.py +++ b/src/textual/_xterm_parser.py @@ -18,7 +18,7 @@ # to be unsuccessful? _MAX_SEQUENCE_SEARCH_THRESHOLD = 32 -_re_mouse_event = re.compile("^" + re.escape("\x1b[") + r"(\d+);(?P\d)\$y" ) @@ -50,7 +50,7 @@ class XTermParser(Parser[Message]): - _re_sgr_mouse = re.compile(r"\x1b\[<(-?\d+);(-?\d+);(-?\d+)([Mm])") + _re_sgr_mouse = re.compile(r"\x1b\[<(\d+);(-?\d+);(-?\d+)([Mm])") def __init__(self, debug: bool = False) -> None: self.last_x = 0.0