#6260: fix(tui): prevent width overflow crashes from nested ANSI escape codes
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
#5509: Fix TUI crash when terminal window is too narrow
by omar-khaled-2 · 2026-01-31
86.2%
#17677: fix(tui): prevent crash when rendered line exceeds terminal width
by Phineas1500 · 2026-02-16
84.9%
#4479: fix(tui): prevent crash when search matches ANSI escape sequences
by bee4come · 2026-01-30
84.9%
#12913: TUI: truncate lines to fit terminal width on narrow terminals
by kutayilmaaz · 2026-02-09
83.8%
#9220: Fix: TUI drops API responses silently when runID already finalized
by vishaltandale00 · 2026-02-05
76.3%
#17814: fix(tui): add OSC 8 hyperlinks for wrapped URLs
by Phineas1500 · 2026-02-16
75.6%
#17777: fix(tui): prevent URL breaking during line wrap
by proto-genesys-x · 2026-02-16
74.9%
#17686: fix(memory): support non-ASCII characters in FTS query tokenization
by Phineas1500 · 2026-02-16
74.6%
#21932: fix(tui): eliminate stale model indicator lag in TUI
by graysurf · 2026-02-20
74.6%
#20516: fix(tui): preserve streamed text on finalize for pure text responses
by MisterGuy420 · 2026-02-19
74.5%