Skip to content

Commit d7449c1

Browse files
committed
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.
1 parent 3339d67 commit d7449c1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/textual/_xterm_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# to be unsuccessful?
1919
_MAX_SEQUENCE_SEARCH_THRESHOLD = 32
2020

21-
_re_mouse_event = re.compile("^" + re.escape("\x1b[") + r"(<?[-?\d;]+[mM]|M...)\Z")
21+
_re_mouse_event = re.compile("^" + re.escape("\x1b[") + r"(<?[-\d;]+[mM]|M...)\Z")
2222
_re_terminal_mode_response = re.compile(
2323
"^" + re.escape("\x1b[") + r"\?(?P<mode_id>\d+);(?P<setting_parameter>\d)\$y"
2424
)
@@ -50,7 +50,7 @@
5050

5151

5252
class XTermParser(Parser[Message]):
53-
_re_sgr_mouse = re.compile(r"\x1b\[<(-?\d+);(-?\d+);(-?\d+)([Mm])")
53+
_re_sgr_mouse = re.compile(r"\x1b\[<(\d+);(-?\d+);(-?\d+)([Mm])")
5454

5555
def __init__(self, debug: bool = False) -> None:
5656
self.last_x = 0.0

0 commit comments

Comments
 (0)