Repository navigation
fix: count runes, not bytes, when wrapping help text - #2511
Open
Rohilalala wants to merge 1 commit into
Open
Rohilalala wants to merge 1 commit into
Rohilalala wants to merge 1 commit into
Conversation
wrapLine measured lines and words with len, so text with multi-byte characters wrapped well before the wrapAt column. Count runes, as offset and the tabwriter that aligns the help output already do.
abitrolly
reviewed
Oct 28, 2026
Comment on lines
+506
to
511
| // Like offset, count runes rather than bytes. | ||
| if wrapAt <= offset || utf8.RuneCountInString(input) <= wrapAt-offset { | ||
| return input | ||
| } | ||
|
|
||
| lineWidth := wrapAt - offset |
Contributor
There was a problem hiding this comment.
Suggested change
| lineWidth := wrapAt - offset | |
| // Like offset, count runes rather than bytes. | |
| if lineWidth <= 0 || utf8.RuneCountInString(input) <= lineWidth { | |
| return input | |
| } |
Contributor
|
LGTM. |
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.
What type of PR is this?
What this PR does / why we need it:
With
wrapAtset,wrapLinemeasured lines and words in bytes, so help text with multi-byte characters wrapped before the configured column. AtwrapAt30,app - ändert die Größe für Überprüfungbroke after "Größe"; it now breaks after "für".offsetand the tabwriter that aligns help output already count runes (#2493), and this makes wrapping agree with them. Wide East Asian characters still count as one column each, as they do in the tabwriter.Which issue(s) this PR fixes:
None.
Testing
TestWrapLineCountsRunesinhelp_test.go.Release Notes