Files
oh-my-pi/packages/coding-agent/src/modes/components/dynamic-border.ts
T
can1357 61a57c1d21 fix(coding-agent): stabilized streaming TUI rendering with readonly rows and memoized reuse
- Changed render methods to return component-owned `readonly string[]` rows.
- Added `RenderStablePrefix` row reuse to avoid repainting unchanged streaming content.
- Stabilized streaming gutters and spinner placement to reduce preview jitter and flicker.
- Finalized commit-safe transcript behavior for tool-call previews and added streaming edge-case tests.
2026-06-10 07:26:02 +02:00

35 lines
1.0 KiB
TypeScript

import type { Component } from "@oh-my-pi/pi-tui";
import { theme } from "../../modes/theme/theme";
/**
* Dynamic border component that adjusts to viewport width.
*
* Note: When used from hooks loaded via jiti, the global `theme` may be undefined
* because jiti creates a separate module cache. Always pass an explicit color
* function when using DynamicBorder in components exported for hook use.
*/
export class DynamicBorder implements Component {
#color: (str: string) => string;
#cachedWidth = -1;
#cachedLines: string[] | undefined;
constructor(color: (str: string) => string = str => theme.fg("border", str)) {
this.#color = color;
}
invalidate(): void {
this.#cachedWidth = -1;
this.#cachedLines = undefined;
}
render(width: number): readonly string[] {
if (this.#cachedLines && this.#cachedWidth === width) {
return this.#cachedLines;
}
const lines = [this.#color(theme.boxSharp.horizontal.repeat(Math.max(1, width)))];
this.#cachedWidth = width;
this.#cachedLines = lines;
return lines;
}
}