| 536 | } |
| 537 | |
| 538 | func wrap(input string, offset int, wrapAt int) string { |
| 539 | var ss []string |
| 540 | |
| 541 | lines := strings.Split(input, "\n") |
| 542 | |
| 543 | padding := strings.Repeat(" ", offset) |
| 544 | |
| 545 | for i, line := range lines { |
| 546 | if line == "" { |
| 547 | ss = append(ss, line) |
| 548 | } else { |
| 549 | wrapped := wrapLine(line, offset, wrapAt, padding) |
| 550 | if i == 0 { |
| 551 | ss = append(ss, wrapped) |
| 552 | } else { |
| 553 | ss = append(ss, padding+wrapped) |
| 554 | } |
| 555 | |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | return strings.Join(ss, "\n") |
| 560 | } |
| 561 | |
| 562 | func wrapLine(input string, offset int, wrapAt int, padding string) string { |
| 563 | if wrapAt <= offset || len(input) <= wrapAt-offset { |