fix(cli): recover from leaked mouse tracking escapes

Detect leaked SGR mouse-report fragments in CLI input, strip them, and reset terminal modes in-place so scroll and typing recover without reopening the tab. Add regression tests for escaped, visible, and bare leak forms.
This commit is contained in:
Brooklyn Nicholson 2026-04-29 21:35:47 -05:00
parent 8cce85b819
commit 98a428fd61
2 changed files with 101 additions and 6 deletions

View file

@ -55,3 +55,23 @@ class TestStripLeakedTerminalResponses:
def test_preserves_multiline_content(self):
text = "line 1\n\x1b[53;1Rline 2"
assert _strip_leaked_terminal_responses(text) == "line 1\nline 2"
def test_strips_sgr_mouse_report_esc_form(self):
text = "abc\x1b[<65;1;49Mdef"
assert _strip_leaked_terminal_responses(text) == "abcdef"
def test_strips_sgr_mouse_report_visible_form(self):
text = "abc^[[<65;1;49Mdef"
assert _strip_leaked_terminal_responses(text) == "abcdef"
def test_strips_sgr_mouse_report_bare_form(self):
text = "abc<65;1;49Mdef"
assert _strip_leaked_terminal_responses(text) == "abcdef"
def test_strips_multiple_concatenated_sgr_mouse_reports(self):
text = "<65;1;49M<35;1;42Mhello<64;1;40m"
assert _strip_leaked_terminal_responses(text) == "hello"
def test_does_not_strip_regular_angle_bracket_text(self):
text = "render <div class='hero'> literal"
assert _strip_leaked_terminal_responses(text) == text