(line: string, limit: number)
| 278 | * as the width exceeds `limit`, returning the partial count (> limit). |
| 279 | */ |
| 280 | export function asciiVisibleWidth(line: string, limit: number): number | undefined { |
| 281 | let width = 0; |
| 282 | let i = 0; |
| 283 | while (i < line.length) { |
| 284 | const code = line.charCodeAt(i); |
| 285 | if (code === 0x1b) { |
| 286 | const ansi = extractAnsiCode(line, i); |
| 287 | if (!ansi) return undefined; |
| 288 | i += ansi.length; |
| 289 | continue; |
| 290 | } |
| 291 | if (code < 0x20 || code > 0x7e) return undefined; |
| 292 | width++; |
| 293 | if (width > limit) return width; |
| 294 | i++; |
| 295 | } |
| 296 | return width; |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Normalize text for terminal output without changing logical editor content. |
no test coverage detected