--- quebra preservando códigos ANSI ---
(text string, maxWidth int)
| 89 | |
| 90 | // --- quebra preservando códigos ANSI --- |
| 91 | func wrapStringWithColor(text string, maxWidth int) []string { |
| 92 | if maxWidth <= 0 { |
| 93 | return []string{text} |
| 94 | } |
| 95 | words := strings.Fields(text) |
| 96 | if len(words) == 0 { |
| 97 | return nil |
| 98 | } |
| 99 | |
| 100 | var lines []string |
| 101 | var b strings.Builder |
| 102 | curr := 0 |
| 103 | |
| 104 | for _, w := range words { |
| 105 | wlen := visibleLen(w) |
| 106 | |
| 107 | // se não cabe na linha atual, pula pra próxima |
| 108 | if curr > 0 && curr+1+wlen > maxWidth { |
| 109 | lines = append(lines, b.String()) |
| 110 | b.Reset() |
| 111 | curr = 0 |
| 112 | } |
| 113 | if curr > 0 { |
| 114 | b.WriteByte(' ') |
| 115 | curr++ |
| 116 | } |
| 117 | b.WriteString(w) |
| 118 | curr += wlen |
| 119 | } |
| 120 | if b.Len() > 0 { |
| 121 | lines = append(lines, b.String()) |
| 122 | } |
| 123 | return lines |
| 124 | } |
| 125 | |
| 126 | // tipBoxBorderStyle is the rounded gray border used for the welcome |
| 127 | // tip box and the active-model card. Defined once so future palette |
no test coverage detected