Files
oh-my-pi/packages/coding-agent/src/modes/components/dynamic-border.ts
T
can1357 b877464575 refactor(coding-agent): migrated UI chrome to rounded box corners
- Switch all UI components and tests from sharp box corners (`boxSharp`) to rounded ones (`boxRound`).
- Update `Theme` to re-export sharp junction symbols (tees and cross) under `boxRound` to ensure consistent divider rendering in rounded boxes.
- Remove outdated architectural notes regarding forced tool-choice queues in documentation.
2026-06-19 07:57:15 +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.boxRound.horizontal.repeat(Math.max(1, width)))];
this.#cachedWidth = width;
this.#cachedLines = lines;
return lines;
}
}