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