MCPcopy Create free account
hub / github.com/arctic-cli/interface / wrapPlainText

Function wrapPlainText

packages/arctic/src/cli/cmd/tui/component/logo.tsx:277–307  ·  view source on GitHub ↗
(value: string, width: number)

Source from the content-addressed store, hash-verified

275}
276
277function wrapPlainText(value: string, width: number) {
278 if (!value) return [""]
279 const words = value.split(" ")
280 const lines: string[] = []
281 let current = ""
282 for (const word of words) {
283 if (!word) continue
284 if (word.length > width) {
285 if (current) {
286 lines.push(current)
287 current = ""
288 }
289 let start = 0
290 while (start < word.length) {
291 lines.push(word.slice(start, start + width))
292 start += width
293 }
294 continue
295 }
296 const attempt = current ? `${current} ${word}` : word
297 if (attempt.length <= width) {
298 current = attempt
299 } else {
300 if (current) lines.push(current)
301 current = word
302 }
303 }
304 if (current) lines.push(current)
305 if (!lines.length) lines.push("")
306 return lines
307}

Callers 2

buildLeftColumnFunction · 0.85
bulletLinesFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected