MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / wrap

Function wrap

apps/kimi-code/src/tui/components/messages/goal-panel.ts:213–222  ·  view source on GitHub ↗

Word-wrap to `width`, capped at `maxLines` (last line gets an ellipsis when clipped).

(text: string, width: number, maxLines: number)

Source from the content-addressed store, hash-verified

211
212/** Word-wrap to `width`, capped at `maxLines` (last line gets an ellipsis when clipped). */
213function wrap(text: string, width: number, maxLines: number): string[] {
214 const safeWidth = Math.max(1, width);
215 const lines = wrapTextWithAnsi(text.replaceAll(/\s+/g, ' ').trim(), safeWidth);
216 if (lines.length === 0) return [''];
217 if (lines.length <= maxLines) return lines;
218 const clipped = lines.slice(0, maxLines);
219 const lastLine = clipped[maxLines - 1] ?? '';
220 clipped[maxLines - 1] = truncateToWidth(`${lastLine}…`, safeWidth, '…');
221 return clipped;
222}

Callers 1

buildGoalReportLinesFunction · 0.70

Calls 2

wrapTextWithAnsiFunction · 0.90
truncateToWidthFunction · 0.90

Tested by

no test coverage detected