MCPcopy Create free account
hub / github.com/Noumena-Network/code / wrapWithSoftWrap

Function wrapWithSoftWrap

src/ink/render-node-to-output.ts:338–360  ·  view source on GitHub ↗

* Wrap text and record which output lines are soft-wrap continuations * (i.e. the `\n` before them was inserted by word-wrap, not in the * source). wrapAnsi already processes each input line independently, so * wrapping per-input-line here gives identical output to a single * whole-string wrap w

(
  plainText: string,
  maxWidth: number,
  textWrap: Parameters<typeof wrapText>[2],
)

Source from the content-addressed store, hash-verified

336 * change from the pre-softWrap path.
337 */
338function wrapWithSoftWrap(
339 plainText: string,
340 maxWidth: number,
341 textWrap: Parameters<typeof wrapText>[2],
342): { wrapped: string; softWrap: boolean[] | undefined } {
343 if (textWrap !== 'wrap' && textWrap !== 'wrap-trim') {
344 return {
345 wrapped: wrapText(plainText, maxWidth, textWrap),
346 softWrap: undefined,
347 }
348 }
349 const origLines = plainText.split('\n')
350 const outLines: string[] = []
351 const softWrap: boolean[] = []
352 for (const orig of origLines) {
353 const pieces = wrapText(orig, maxWidth, textWrap).split('\n')
354 for (let i = 0; i < pieces.length; i++) {
355 outLines.push(pieces[i]!)
356 softWrap.push(i > 0)
357 }
358 }
359 return { wrapped: outLines.join('\n'), softWrap }
360}
361
362// If parent container is `<Box>`, text nodes will be treated as separate nodes in
363// the tree and will have their own coordinates in the layout.

Callers 1

renderNodeToOutputFunction · 0.85

Calls 1

wrapTextFunction · 0.70

Tested by

no test coverage detected