MCPcopy
hub / github.com/docker/docker-agent / wrapDisplayText

Function wrapDisplayText

pkg/tui/dialog/max_iterations.go:113–139  ·  view source on GitHub ↗

wrapDisplayText wraps text based on display cell width.

(text string, maxWidth int)

Source from the content-addressed store, hash-verified

111
112// wrapDisplayText wraps text based on display cell width.
113func wrapDisplayText(text string, maxWidth int) string {
114 if maxWidth <= 0 {
115 return text
116 }
117 words := strings.Fields(text)
118 if len(words) == 0 {
119 return text
120 }
121 var lines []string
122 var current string
123 for _, w := range words {
124 if lipgloss.Width(current) == 0 {
125 current = w
126 continue
127 }
128 if lipgloss.Width(current+" "+w) <= maxWidth {
129 current += " " + w
130 } else {
131 lines = append(lines, current)
132 current = w
133 }
134 }
135 if current != "" {
136 lines = append(lines, current)
137 }
138 return strings.Join(lines, "\n")
139}

Callers 1

ViewMethod · 0.85

Calls 1

WidthMethod · 0.45

Tested by

no test coverage detected