perf(tui): optimize image line detection and box cache (#1084)

- Add isImageLine() to terminal-image.ts with single startsWith check based on detected terminal protocol
- Replace dual includes() checks in tui.ts with imported isImageLine()
- Add image line handling to markdown.ts to skip wrapping and margins for image escapes
- Consolidate Box cache into RenderCache type with childLines/width/bgSample/lines fields
- Use in-place mutation in applyLineResets() to avoid array allocation
This commit is contained in:
Can Bölük 2026-01-30 02:25:19 +01:00 committed by GitHub
parent e045a9f142
commit 4058346a64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 73 additions and 30 deletions

View file

@ -79,6 +79,24 @@ export function getCapabilities(): TerminalCapabilities {
export function resetCapabilitiesCache(): void {
cachedCapabilities = null;
imageEscapePrefix = undefined;
}
let imageEscapePrefix: string | null | undefined;
function getImageEscapePrefix(): string | null {
if (imageEscapePrefix === undefined) {
const protocol = getCapabilities().images;
if (protocol === "kitty") imageEscapePrefix = "\x1b_G";
else if (protocol === "iterm2") imageEscapePrefix = "\x1b]1337;File=";
else imageEscapePrefix = null;
}
return imageEscapePrefix;
}
export function isImageLine(line: string): boolean {
const prefix = getImageEscapePrefix();
return prefix !== null && line.startsWith(prefix);
}
/**