refactor: unslop common utilities

This commit is contained in:
can1357
2026-02-22 10:41:39 +01:00
parent a95d432f7b
commit abf8c1efc9
215 changed files with 1978 additions and 4582 deletions
+2 -29
View File
@@ -31,15 +31,11 @@ export function getSegmenter(): Intl.Segmenter {
return segmenter;
}
// Cache for non-ASCII strings
//const WIDTH_CACHE_SIZE = 512;
//const widthCache = new Map<string, number>();
/**
* Calculate the visible width of a string in terminal columns.
*/
export function visibleWidthRaw(str: string): number {
if (str.length === 0) {
if (!str) {
return 0;
}
@@ -64,31 +60,8 @@ export function visibleWidthRaw(str: string): number {
* Calculate the visible width of a string in terminal columns.
*/
export function visibleWidth(str: string): number {
if (str.length === 0) {
return 0;
}
if (!str) return 0;
return visibleWidthRaw(str);
// === Disabled cache ===
/*
// Check cache
const cached = widthCache.get(str);
if (cached !== undefined) {
return cached;
}
const width = visibleWidthRaw(str);
if (widthCache.size >= WIDTH_CACHE_SIZE) {
const firstKey = widthCache.keys().next().value;
if (firstKey !== undefined) {
widthCache.delete(firstKey);
}
}
widthCache.set(str, width);
return width;
*/
}
const makeBoolArray = (chars: string): ReadonlyArray<boolean> => {