( text: string, maxWidth: number, )
| 106 | * Width-aware and grapheme-safe. |
| 107 | */ |
| 108 | export function truncateToWidthNoEllipsis( |
| 109 | text: string, |
| 110 | maxWidth: number, |
| 111 | ): string { |
| 112 | if (stringWidth(text) <= maxWidth) return text |
| 113 | if (maxWidth <= 0) return '' |
| 114 | let width = 0 |
| 115 | let result = '' |
| 116 | for (const { segment } of getGraphemeSegmenter().segment(text)) { |
| 117 | const segWidth = stringWidth(segment) |
| 118 | if (width + segWidth > maxWidth) break |
| 119 | result += segment |
| 120 | width += segWidth |
| 121 | } |
| 122 | return result |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Truncates a string to fit within a maximum display width (terminal columns), |
no test coverage detected