for _, line := range lines {
if len(line) <= maxWidth {
result = append(result, line)
continue
}
// Wrap at word boundaries
words := strings.Fields(line)
var currentLine string
for _, word := range words {
if len(currentLine)+len(word)+1 <= maxWidth {
if currentLine == "" {
currentLine = word
} else {
currentLine += " " + word
}
} else {
if currentLine != "" {
result = append(result, currentLine)
}
// If single word is longer than maxWidth, force break it
if len(word) > maxWidth {
result = append(result, word[:maxWidth])
word = word[maxWidth:]
}
currentLine = word
}
}
if currentLine != "" {
result = append(result, currentLine)
}
}
return strings.Join(result, "\n")
}