MCPcopy
hub / github.com/pterm/pterm / splitText

Function splitText

header_printer.go:125–155  ·  view source on GitHub ↗
(text string, width int)

Source from the content-addressed store, hash-verified

123}
124
125func splitText(text string, width int) string {
126 var lines []string
127 linesTmp := strings.Split(text, "\n")
128 for _, line := range linesTmp {
129 if runewidth.StringWidth(RemoveColorFromString(line)) > width {
130 extraLines := []string{""}
131 extraLinesCounter := 0
132 for i, letter := range line {
133 if i%width == 0 && i != 0 {
134 extraLinesCounter++
135 extraLines = append(extraLines, "")
136 }
137 extraLines[extraLinesCounter] += string(letter)
138 }
139 for _, extraLine := range extraLines {
140 extraLine += "\n"
141 lines = append(lines, extraLine)
142 }
143 } else {
144 line += "\n"
145 lines = append(lines, line)
146 }
147 }
148
149 var line string
150 for _, s := range lines {
151 line += s
152 }
153
154 return strings.TrimSuffix(line, "\n")
155}
156
157// Sprintln formats using the default formats for its operands and returns the resulting string.
158// Spaces are always added between operands and a newline is appended.

Callers 1

SprintMethod · 0.85

Calls 1

RemoveColorFromStringFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…