← Back to PRs

#6260: fix(tui): prevent width overflow crashes from nested ANSI escape codes

by 0xktn open 2026-02-01 13:25 View on GitHub →
docs channel: telegram app: web-ui docker
## Problem The TUI crashes with 'Rendered line X exceeds terminal width' on terminals where `process.stdout.columns` is undefined. This happens because: 1. `visibleWidth()` uses single-pass ANSI code removal, but nested sequences like `[1m[38;2;246;196;83m` survive one pass 2. Select list components don't truncate output to the declared width Result: visible width is calculated ~20 characters higher than actual content. ## Solution 1. **Multi-pass ANSI stripping** in `terminal/ansi.ts` - repeat regex passes until no more ANSI codes are found 2. **Defensive line truncation** in `tui/components/searchable-select-list.ts` - truncate any line exceeding the declared width ## Testing - Open model picker with `/models` - Type to filter the list - Verify no width overflow crashes occur --- **Related** - Supersedes the partial fix in #1686 by addressing the root cause (nested ANSI codes) <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR hardens TUI rendering against width overflows by (1) making ANSI stripping multi-pass to better handle adjacent/nested escape sequences (including OSC-8 hyperlinks) and (2) defensively truncating select list render lines to the declared width. It also includes some docs formatting changes. Main issues to address before merge: - The docs sentinel markers were changed to `{/_ ... _/}`, which is not valid MDX comment syntax and will likely render or break docs builds. - The new truncation pass in `SearchableSelectList.render()` is bypassed on the `noMatch` early return, so the crash can still occur in that path. - `docker-compose.yml` now has a trailing comma in a YAML flow sequence, which some parsers reject. <h3>Confidence Score: 3/5</h3> - Reasonably safe, but a few changes likely break docs and some environments’ compose parsing. - Core ANSI/TUI changes are small and test-backed, but the MDX sentinel syntax change is very likely incorrect and the truncation bypass on the no-match path undermines the stated crash fix. The docker-compose trailing comma may also break parsing depending on YAML implementation. - docs/concepts/model-providers.md, docs/providers/moonshot.md, src/tui/components/searchable-select-list.ts, docker-compose.yml <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs