UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

32 lines • 1.21 kB
import { Text } from "@earendil-works/pi-tui"; /** * Text whose content applies theme colors. Plain `Text` keeps the colors its string was built with, so * a theme change, or the system theme receiving the terminal's colors, would leave it stale. This * rebuilds the string from `build` after every invalidation, which the UI performs on theme changes. * * `build` must return the same content each time, apart from colors. Snapshot changing data before * creating the component, or call `invalidate()` after changing state that `build` reads. */ export class ThemedText extends Text { constructor(build, paddingX = 1, paddingY = 1) { super("", paddingX, paddingY); this.stale = true; this.build = build; } invalidate() { super.invalidate(); this.stale = true; } /** Output is the built text; `invalidate()` bumps the revision before the rebuild in `render`. */ getRenderRevision() { return this.textRenderRevision(); } render(width) { if (this.stale) { this.stale = false; this.setText(this.build()); } return super.render(width); } } //# sourceMappingURL=themed-text.js.map