MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / asciiVisibleWidth

Function asciiVisibleWidth

packages/pi-tui/src/utils.ts:280–297  ·  view source on GitHub ↗
(line: string, limit: number)

Source from the content-addressed store, hash-verified

278 * as the width exceeds `limit`, returning the partial count (> limit).
279 */
280export 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.

Callers 2

doRenderMethod · 0.90

Calls 1

extractAnsiCodeFunction · 0.85

Tested by

no test coverage detected