Skip to content

fix(ui_terminal): truncate by display width, not byte index - #170

Merged
stippi merged 1 commit into
mainfrom
fix/tui-multibyte-truncation
Jul 26, 2026
Merged

fix(ui_terminal): truncate by display width, not byte index#170
stippi merged 1 commit into
mainfrom
fix/tui-multibyte-truncation

Conversation

@stippi

@stippi stippi commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Rendering a tool output line whose byte-index cut landed inside a multi-byte character panicked the render task:

end byte index 104 is not a char boundary; it is inside 'ü'

Every truncation site sliced with &s[..n] where n was a column count, which is both panic-prone and wrong (bytes are not terminal columns).

Add text_util with width-aware truncate_to_width / truncate_with_ellipsis and route all truncation through it: the generic tool fallback, the error lines, the compact/command renderers, parameter display values, and the sub-agent instructions summary. The compact renderer's key column offset used key.len() too — also a width now, so umlauts in a key no longer shift the value.

Found via pal, whose pal_tui carries the same code.

Rendering a tool output line whose byte-index cut landed inside a
multi-byte character panicked the render task:

  end byte index 104 is not a char boundary; it is inside 'ü'

Every truncation site sliced with `&s[..n]` where n was a column count,
which is both panic-prone and wrong (bytes are not terminal columns).

Add `text_util` with width-aware `truncate_to_width` /
`truncate_with_ellipsis` and route all truncation through it: the
generic tool fallback, the error lines, the compact/command renderers,
parameter display values, and the sub-agent instructions summary. The
compact renderer's key column offset used `key.len()` too — also a
width now, so umlauts in a key no longer shift the value.

Found via pal, whose pal_tui carries the same code.
@stippi
stippi merged commit 99e924d into main Jul 26, 2026
3 of 4 checks passed
@stippi
stippi deleted the fix/tui-multibyte-truncation branch July 26, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant