Truncate each line of multi-line text separately - #1006
Conversation
`cli-truncate` treats its input as a single line: newlines are zero-width, so the widths of every line added up and the text was cut as one run. As soon as any line overflowed, lines were merged or dropped and lines that fit were truncated (`'foo\nhello world'` at width 6 rendered `fo…`). Because the Yoga measure function uses the same code, the layout height collapsed too, so the lost lines never showed up as overlap. Truncate each line on its own, the same way `wrap` and `hard` wrap each line via `wrap-ansi`.
8707583 to
fa6af9e
Compare
|
Truncating each explicit line independently makes sense, but splitting the raw string before truncating each line seperately loses ANSI state that spans a newline. For example, Could we tokenize the full string first, build self-contained styled lines, and then pass each serialized line to |
|
Two things before this is ready:
|
…rms across newlines Only split on styled characters when the text contains a newline; single-line text goes straight to `cliTruncate` as before, so cache misses on long strings stay cheap. Add integrated tests for a C1 SGR color, a C1 OSC 8 hyperlink, a colon 256-color and a colon truecolor parameter spanning a truncated newline. These forms are normalized by `squashTextNodes` before reaching `wrapText`.
One gap: colon parameters on non-color SGR ( |
wrapTextpasses the whole text tocli-truncate, which treats its input as a single line: newlines are zero-width, so the widths of every line add up and the text is cut as one run. As soon as any line is wider than the box, lines are merged or dropped, and lines that fit are truncated. Because the Yoga measure function uses the samewrapText, the layout height collapses too, so the lost lines never show up as overlap.wrapandhardalready wrap each line on its own viawrap-ansi. This does the same fortruncate,truncate-startandtruncate-middle: split on\n, truncate each line, join.Tests: unit cases for all three positions and a bordered
renderToStringcase; they fail on master.Fixes #1008