Visitar URL original
fix: count runes, not bytes, when wrapping help text by Rohilalala · Pull Request #2511 · urfave/cli · GitHub
Skip to content

fix: count runes, not bytes, when wrapping help text - #2511

Open
Rohilalala wants to merge 1 commit into
urfave:mainfrom
Rohilalala:fix/wrap-runes
Open

Rohilalala wants to merge 1 commit into
urfave:mainfrom
Rohilalala:fix/wrap-runes

Conversation

@Rohilalala

Copy link
Copy Markdown

What type of PR is this?

  • bug

What this PR does / why we need it:

With wrapAt set, wrapLine measured lines and words in bytes, so help text with multi-byte characters wrapped before the configured column. At wrapAt 30, app - ändert die Größe für Überprüfung broke after "Größe"; it now breaks after "für". offset and 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

TestWrapLineCountsRunes in help_test.go.

Release Notes

Help text wrapping counts characters instead of bytes, so non-ASCII usage text no longer wraps early.

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.
@Rohilalala
Rohilalala requested a review from a team as a code owner October 28, 2026 11:11
Comment thread help.go
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

@abitrolly abitrolly Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lineWidth := wrapAt - offset
// Like offset, count runes rather than bytes.
if lineWidth <= 0 || utf8.RuneCountInString(input) <= lineWidth {
return input
}

@abitrolly

Copy link
Copy Markdown
Contributor

LGTM.

This branch has not been deployed

No deployments
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.

2 participants