#5509: Fix TUI crash when terminal window is too narrow
docs
Fixes #5490. Uses visibleWidth from @mariozechner/pi-tui to correctly calculate string width.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates the `SearchableSelectList` TUI component to compute prompt/input/layout widths using `visibleWidth` from `@mariozechner/pi-tui` instead of a local ANSI-stripping width function, addressing crashes and rendering issues when the terminal is very narrow and when strings include wide characters. It also adds focused tests asserting that rendered lines don’t exceed a specified terminal width, including a wide-character case.
<h3>Confidence Score: 3/5</h3>
- Reasonably safe to merge, but edge cases with extremely small widths could still crash due to negative widths passed into truncation.
- Change is localized and conceptually correct (use a more accurate width calculator), and tests were added. However, there are still paths where calculated widths can go negative when the terminal width is extremely small, which is directly related to the original crash class. Also, some width calculations still rely on `.length` rather than `visibleWidth`, which could reintroduce mis-measurements with styled prefixes.
- src/tui/components/searchable-select-list.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#6260: fix(tui): prevent width overflow crashes from nested ANSI escape codes
by 0xktn · 2026-02-01
86.2%
#12913: TUI: truncate lines to fit terminal width on narrow terminals
by kutayilmaaz · 2026-02-09
85.5%
#4479: fix(tui): prevent crash when search matches ANSI escape sequences
by bee4come · 2026-01-30
82.1%
#4035: fix(tui): ensure UI updates when status changes
by willerxar-cmyk · 2026-01-29
80.3%
#17677: fix(tui): prevent crash when rendered line exceeds terminal width
by Phineas1500 · 2026-02-16
80.1%
#6819: fix(tui): handle unstructured tool results and errors in tool execu...
by TreyDong · 2026-02-02
77.4%
#9220: Fix: TUI drops API responses silently when runID already finalized
by vishaltandale00 · 2026-02-05
75.4%
#8342: Fix debug interface CSS layout issues
by Klopib · 2026-02-03
74.8%
#12175: ui: fix sessions table collapse on narrow widths
by benjipeng · 2026-02-08
74.4%
#12079: TUI: improve thinking UX, tool readability, and live running status...
by rubenfb23 · 2026-02-08
74.1%