← Back to PRs

#4479: fix(tui): prevent crash when search matches ANSI escape sequences

by bee4come open 2026-01-30 08:10 View on GitHub →
## Summary Fixes #4519 Prevents TUI crash when search input partially matches ANSI escape sequences in styled text. ## Changes - Split text into ANSI and visible parts before highlighting - Only apply search highlight to visible text portions - Preserve ANSI escape sequences intact ## Testing - Tested with colored model names in selector - Verified search highlighting works without corrupting styles <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR hardens `SearchableSelectList` rendering and highlighting so search highlighting doesn’t corrupt ANSI escape sequences (avoiding TUI crashes when a query partially matches escape codes). It does this by splitting text into ANSI vs visible segments before applying highlights, and by truncating rendered lines using `pi-tui`’s `visibleWidth`/`truncateToWidth` so ANSI styling is preserved. The changes are localized to `src/tui/components/searchable-select-list.ts` and affect how list item labels/descriptions are highlighted and width-constrained, plus some minor input-handling guards. <h3>Confidence Score: 4/5</h3> - This PR is likely safe to merge and addresses a real crash class, with a couple of edge cases worth checking. - The change is self-contained and improves ANSI-safety in highlighting and truncation, but the ANSI regex is narrow (SGR-only) and may miss other escape sequences, and there’s a small type/logic inconsistency (`items ?? []`) that should be clarified. - src/tui/components/searchable-select-list.ts <!-- greptile_other_comments_section --> <sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub> <!-- /greptile_comment -->

Most Similar PRs