mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 09:01:20 +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
|
|
@ -1,4 +1,5 @@
|
|||
import { marked, type Token } from "marked";
|
||||
import { isImageLine } from "../terminal-image.js";
|
||||
import type { Component } from "../tui.js";
|
||||
import { applyBackgroundToLine, visibleWidth, wrapTextWithAnsi } from "../utils.js";
|
||||
|
||||
|
|
@ -121,7 +122,11 @@ export class Markdown implements Component {
|
|||
// Wrap lines (NO padding, NO background yet)
|
||||
const wrappedLines: string[] = [];
|
||||
for (const line of renderedLines) {
|
||||
wrappedLines.push(...wrapTextWithAnsi(line, contentWidth));
|
||||
if (isImageLine(line)) {
|
||||
wrappedLines.push(line);
|
||||
} else {
|
||||
wrappedLines.push(...wrapTextWithAnsi(line, contentWidth));
|
||||
}
|
||||
}
|
||||
|
||||
// Add margins and background to each wrapped line
|
||||
|
|
@ -131,6 +136,11 @@ export class Markdown implements Component {
|
|||
const contentLines: string[] = [];
|
||||
|
||||
for (const line of wrappedLines) {
|
||||
if (isImageLine(line)) {
|
||||
contentLines.push(line);
|
||||
continue;
|
||||
}
|
||||
|
||||
const lineWithMargins = leftMargin + line + rightMargin;
|
||||
|
||||
if (bgFn) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue