Repository navigation
Measure terminal columns by glyph, not by char - #350
Open
yu2971512385-ui wants to merge 1 commit into
Open
yu2971512385-ui wants to merge 1 commit into
yu2971512385-ui wants to merge 1 commit into
Conversation
update_row.rs imports UnicodeWidthChar and UnicodeWidthStr on one line and uses them for the two halves of the same arithmetic. visible_width asks the string; middle_truncate, format_group_header and the two format_*_line budgets add up chars. The answers differ for anything a terminal draws as one glyph out of several chars: family emoji str 2, per char 8 skin tone str 2, per char 4 rainbow flag str 2, per char 3 keycap str 2, per char 1 So a dep name holding one is thought wider than it is and gets truncated when it fitted, and middle_truncate's char-by-char head and tail can stop inside a glyph, leaving a dangling joiner. Use the string measure everywhere, and step middle_truncate by grapheme cluster. unicode-segmentation is already in Cargo.lock. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This branch has not been deployed
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.
update_row.rsimportsUnicodeWidthCharandUnicodeWidthStron one line and uses them for the two halves of the same arithmetic.visible_widthasks the string.middle_truncate,format_group_headerand bothformat_*_linebudgets add up chars. The answers differ for anything a terminal draws as one glyph out of several chars:str.width()char.width()@scope/pkg-👨👩👧👦-uiis 16 columns and counts as 22, so atmax_width20 it gets truncated when it fitted — and the cut lands inside the glyph:Change
String measure everywhere.
middle_truncatesteps by grapheme cluster.unicode-segmentationis already inCargo.lock, so nothing new is fetched.Tests
Three added to
middle_truncate_helper, over four glyphs at every budget from 2 to 20:What I ran
just testwould not run in the sandbox I work in. I copied the rewrittenmiddle_truncateverbatim into a scratch crate beside the shipped one, pinned to theunicode-width0.2.2 andunicode-segmentation1.13.3 your lock file carries, and ran both against every assertion above plus the onesupdate_row_test.rsalready pins. Those figures are that program's output. CI is the real check.First draft of the tests passed against the shipped code: I had put the glyph in the middle of a long name, where no cut from either end reached it. The strings now are
ab{glyph}×6cd, where cuts land on a glyph.Disclosure: written with AI assistance (Claude). Figures are real output.
🤖 Generated with Claude Code