mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-19 15:04:45 +00:00
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:
parent
e045a9f142
commit
4058346a64
5 changed files with 73 additions and 30 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue