refactor(ui): simplify truncPad via runewidth Truncate/FillRight#94
Merged
Conversation
Replace truncPad's hand-rolled width-aware truncate-and-pad loop with runewidth's built-in Truncate/FillRight helpers. go-runewidth is already a direct dependency, so this adds no modules while removing the manual width bookkeeping (ellipsis-cell reservation, wide-rune boundary handling, padding). Output is byte-for-byte identical: verified against the side-by-side golden fixture, the unicode/wide-rune tests, and a differential check over 21 inputs x 28 widths (incl. negatives, zero, CJK, tabs, emoji, accents, and the wide-rune-straddling case). This is also the resolution of the side-by-side library investigation: the lightest alternative to lipgloss/x-cellbuf/reflow is no new library at all, since color is applied after truncPad and ANSI-aware truncation buys us nothing. Closes #93 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replace
truncPad's hand-rolled width-aware truncate-and-pad loop withrunewidth's built-inTruncate/FillRighthelpers:go-runewidthis already a direct dependency, so this adds no modules while removing the manual width bookkeeping (ellipsis-cell reservation, wide-rune boundary handling, padding).Why
This is the resolution of the side-by-side rendering library investigation: the lightest alternative to
lipgloss/charmbracelet/x/cellbuf/muesli/reflowis no new library at all. Those only buy ANSI-aware truncation, which we don't need — color is applied aftertruncPad, so cells are always plain text when truncated.Verification — output is byte-for-byte identical
TestTruncPadUnicode/TestTruncPadWideRunes(incl.世界世→世界…)task cigreen (202 tests, lint 0 issues)Closes #93
🤖 Generated with Claude Code