Word-wrap to `width`, capped at `maxLines` (last line gets an ellipsis when clipped).
(text: string, width: number, maxLines: number)
| 211 | |
| 212 | /** Word-wrap to `width`, capped at `maxLines` (last line gets an ellipsis when clipped). */ |
| 213 | function 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 | } |
no test coverage detected