Fix: prevent crash on legacy X10 mouse reports after terminal rebuild - #6696
Open
Jyotish08 wants to merge 1 commit into
Open
Fix: prevent crash on legacy X10 mouse reports after terminal rebuild#6696Jyotish08 wants to merge 1 commit into
Jyotish08 wants to merge 1 commit into
Conversation
1. Decode stdin with errors='replace' in input loops to prevent UnicodeDecodeError on raw non-ASCII X10 mouse coordinate bytes (> 0x7F). 2. Emit LegacyMouseReport from XTermParser on ESC [ M sequence and re-assert SGR mouse mode in driver to restore SGR mouse encoding after terminal teardown/rebuild.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens Textual’s input pipeline against legacy X10 mouse reporting that can appear after a terminal teardown/rebuild (e.g., VS Code terminal reload), preventing UTF-8 decode crashes and restoring full mouse tracking by re-enabling SGR mouse mode when X10 sequences are detected.
Changes:
- Switch stdin byte-stream decoding in terminal/web drivers to a fault-tolerant UTF-8 incremental decoder (
errors="replace") to avoidUnicodeDecodeErroron non-UTF-8 X10 coordinate bytes. - Introduce a
LegacyMouseReportmessage and teachXTermParserto emit it whenESC [ M ...(X10) is seen, prompting the driver to re-assert mouse mode via_enable_mouse_support(). - Add targeted tests covering parser emission and driver behavior on legacy X10 reports.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_xterm_parser.py | Adds regression test ensuring X10 sequences emit LegacyMouseReport. |
| tests/test_driver.py | Adds regression test ensuring the driver re-enables mouse support on LegacyMouseReport. |
| src/textual/messages.py | Introduces the LegacyMouseReport message type. |
| src/textual/drivers/web_driver.py | Makes UTF-8 decoding tolerant (errors="replace") in the web input loop. |
| src/textual/drivers/linux_inline_driver.py | Makes UTF-8 decoding tolerant (errors="replace") in the inline terminal input loop. |
| src/textual/drivers/linux_driver.py | Makes UTF-8 decoding tolerant (errors="replace") in the terminal input loop. |
| src/textual/driver.py | Handles LegacyMouseReport by re-enabling mouse support from the input thread. |
| src/textual/_xterm_parser.py | Detects X10 mouse sequences and emits LegacyMouseReport prior to mouse parsing. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #6668 ### Problem
When a terminal emulator is torn down and rebuilt underneath a running Textual application (e.g. VS Code terminal reload, tmux detach/reattach, SSH reconnect):
ESC [ M Cb Cx Cy).Cx > 127), the raw coordinate bytes exceed0x7F(non-ASCII).UnicodeDecodeError, causing the input loop and application to crash.?1006).Solution
linux_driver.py,linux_inline_driver.py, andweb_driver.pyto useerrors="replace". This preventsUnicodeDecodeErrorwhen raw non-ASCII X10 mouse bytes (> 0x7F) are read from stdin.LegacyMouseReportmessage class inmessages.py.XTermParserin_xterm_parser.pyto emitLegacyMouseReportupon encountering an X10 mouse sequence (ESC [ M ...).Driver.process_messageto handleLegacyMouseReportby invokingself._enable_mouse_support(), re-asserting SGR mouse mode (\x1b[?1006h) to restore full mouse tracking.test_legacy_x10_mouse_report_emits_legacy_mouse_reportintests/test_xterm_parser.py.test_driver_reasserts_mouse_on_legacy_reportintests/test_driver.py.