diff options
| author | Jacob Richman <[email protected]> | 2025-06-19 20:17:23 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-19 13:17:23 -0700 |
| commit | b0bc7c3d996d25c9fefdfbcba3ca19fa46ad199f (patch) | |
| tree | c2d89d14b8dade1daf51f835969d9b0e79d4df30 /packages/cli/src/ui/utils/textUtils.ts | |
| parent | 10a83a6395b70f21b01da99d0992c78d0354a8dd (diff) | |
Fix flicker issues by ensuring all actively changing content fits in the viewport (#1217)
Diffstat (limited to 'packages/cli/src/ui/utils/textUtils.ts')
| -rw-r--r-- | packages/cli/src/ui/utils/textUtils.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/packages/cli/src/ui/utils/textUtils.ts b/packages/cli/src/ui/utils/textUtils.ts index 35e4c4a2..f7006047 100644 --- a/packages/cli/src/ui/utils/textUtils.ts +++ b/packages/cli/src/ui/utils/textUtils.ts @@ -45,3 +45,25 @@ export function isBinary( // If no NULL bytes were found in the sample, we assume it's text. return false; } + +/* + * ------------------------------------------------------------------------- + * Unicode‑aware helpers (work at the code‑point level rather than UTF‑16 + * code units so that surrogate‑pair emoji count as one "column".) + * ---------------------------------------------------------------------- */ + +export function toCodePoints(str: string): string[] { + // [...str] or Array.from both iterate by UTF‑32 code point, handling + // surrogate pairs correctly. + return Array.from(str); +} + +export function cpLen(str: string): number { + return toCodePoints(str).length; +} + +export function cpSlice(str: string, start: number, end?: number): string { + // Slice by code‑point indices and re‑join. + const arr = toCodePoints(str).slice(start, end); + return arr.join(''); +} |
