Skip to content

Commit 28f0aa6

Browse files
authored
Merge pull request #5926 from Textualize/fix-ghostty-mouse
allow negative mouse coordinates
2 parents c2b964f + 5d4d0f0 commit 28f0aa6

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- Fixed issue with the "transparent" CSS value not being transparent when set using python https://github.com/Textualize/textual/pull/5890
1313
- Fixed issue with pushing screens when Input has mouse captured https://github.com/Textualize/textual/pull/5900
14+
- Implemented workaround for Ghostty bug which produces negative mouse coordinates https://github.com/Textualize/textual/pull/5926
1415

1516
## Changed
1617

src/textual/_xterm_parser.py

Lines changed: 5 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
@@ -78,6 +78,9 @@ def parse_mouse_code(self, code: str) -> Message | None:
7878
buttons = int(_buttons)
7979
x = float(int(_x) - 1)
8080
y = float(int(_y) - 1)
81+
if x < 0 or y < 0:
82+
# TODO: Workaround for Ghostty erroneous negative coordinate bug
83+
return None
8184
if (
8285
self.mouse_pixels
8386
and self.terminal_pixel_size is not None

0 commit comments

Comments
 (0)