MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / wrapCell

Function wrapCell

ui-tui/src/components/markdown.tsx:333–385  ·  view source on GitHub ↗
(raw: string, width: number, hard: boolean)

Source from the content-addressed store, hash-verified

331 // Word-wrap plain text to fit within `width` display columns.
332 // Operates on stripped text for correct width measurement.
333 const wrapCell = (raw: string, width: number, hard: boolean): string[] => {
334 const text = stripInlineMarkup(raw)
335
336 if (width <= 0) {
337 return [text]
338 }
339
340 if (stringWidth(text) <= width) {
341 return [text]
342 }
343
344 const words = text.split(/\s+/).filter(w => w.length > 0)
345 const lines: string[] = []
346 let current = ''
347 let currentWidth = 0
348
349 for (const word of words) {
350 const w = stringWidth(word)
351
352 if (currentWidth === 0) {
353 if (hard && w > width) {
354 for (const ch of graphemes(word)) {
355 const cw = stringWidth(ch)
356
357 if (currentWidth + cw > width && current) {
358 lines.push(current)
359 current = ''
360 currentWidth = 0
361 }
362
363 current += ch
364 currentWidth += cw
365 }
366 } else {
367 current = word
368 currentWidth = w
369 }
370 } else if (currentWidth + 1 + w <= width) {
371 current += ' ' + word
372 currentWidth += 1 + w
373 } else {
374 lines.push(current)
375 current = word
376 currentWidth = w
377 }
378 }
379
380 if (current) {
381 lines.push(current)
382 }
383
384 return lines.length > 0 ? lines : ['']
385 }
386
387 const isHard = totalMin > availableWidth // tier 3 needs hard word breaks
388 const sep = columnWidths.map(w => '─'.repeat(Math.max(1, w))).join(' ')

Callers 1

buildRowLinesFunction · 0.85

Calls 4

stringWidthFunction · 0.90
stripInlineMarkupFunction · 0.85
pushMethod · 0.80
graphemesFunction · 0.70

Tested by

no test coverage detected