MCPcopy Create free account
hub / github.com/diillson/chatcli / wrapStringWithColor

Function wrapStringWithColor

cli/welcome.go:91–124  ·  view source on GitHub ↗

--- quebra preservando códigos ANSI ---

(text string, maxWidth int)

Source from the content-addressed store, hash-verified

89
90// --- quebra preservando códigos ANSI ---
91func 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

Callers 1

printTipBoxFunction · 0.85

Calls 4

visibleLenFunction · 0.85
StringMethod · 0.45
ResetMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected