(input string, offset int, wrapAt int, padding string)
| 560 | } |
| 561 | |
| 562 | func wrapLine(input string, offset int, wrapAt int, padding string) string { |
| 563 | if wrapAt <= offset || len(input) <= wrapAt-offset { |
| 564 | return input |
| 565 | } |
| 566 | |
| 567 | lineWidth := wrapAt - offset |
| 568 | words := strings.Fields(input) |
| 569 | if len(words) == 0 { |
| 570 | return input |
| 571 | } |
| 572 | |
| 573 | wrapped := words[0] |
| 574 | spaceLeft := lineWidth - len(wrapped) |
| 575 | for _, word := range words[1:] { |
| 576 | if len(word)+1 > spaceLeft { |
| 577 | wrapped += "\n" + padding + word |
| 578 | spaceLeft = lineWidth - len(word) |
| 579 | } else { |
| 580 | wrapped += " " + word |
| 581 | spaceLeft -= 1 + len(word) |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | return wrapped |
| 586 | } |
| 587 | |
| 588 | func offset(input string, fixed int) int { |
| 589 | return len(input) + fixed |
no outgoing calls