fix: keep wrapping usage text after a word wider than the column

wrapN returned the whole remaining string whenever the first word did not
fit the description column, which ended the wrapping loop in wrap and left
every later word on that one line.

Break after the over-wide word instead, so only that word overflows and
wrapping resumes on the next one. Searching for the break point from i
covers both cases the old guard caught: no whitespace before i at all, and
whitespace only at index 0 where splitting would emit an empty line.

Fixes #501
This commit is contained in:
dualfroz committed 2026-09-03 14:10:59 +02:00
1 parent 38ddaa30dd
commit a84e5d973b
2 files changed
+65

No files matched your search

+7
View File
@@ -704,6 +704,13 @@ func wrapN(i, slop int, s string) (string, string) {
w := strings.LastIndexAny(s[:i], " \t\n")
if w <= 0 {
// There is nowhere to break within the first `i` runes, so the
// leading word is wider than the line. Let that one word overflow
// and break after it, rather than returning all of `s` and leaving
// everything that follows unwrapped.
if x := strings.IndexAny(s[i:], " \t\n"); x >= 0 {
return s[:i+x], s[i+x+1:]
}
return s, ""
}
nlPos := strings.LastIndex(s[:i], "\n")