mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 21:03:19 +00:00
- Add setEditorText() and getEditorText() to HookUIContext for prompt generator pattern - custom() now accepts async factories for fire-and-forget work - Add CancellableLoader component to tui package - Add BorderedLoader component for hooks with cancel UI - Export HookAPI, HookContext, HookFactory from main package - Update all examples to import from packages instead of relative paths - Update hooks.md and custom-tools.md documentation fixes #350
41 lines
1 KiB
TypeScript
41 lines
1 KiB
TypeScript
import { CancellableLoader, Container, Spacer, Text, type TUI } from "@mariozechner/pi-tui";
|
|
import type { Theme } from "../theme/theme.js";
|
|
import { DynamicBorder } from "./dynamic-border.js";
|
|
|
|
/** Loader wrapped with borders for hook UI */
|
|
export class BorderedLoader extends Container {
|
|
private loader: CancellableLoader;
|
|
|
|
constructor(tui: TUI, theme: Theme, message: string) {
|
|
super();
|
|
this.addChild(new DynamicBorder());
|
|
this.addChild(new Spacer(1));
|
|
this.loader = new CancellableLoader(
|
|
tui,
|
|
(s) => theme.fg("accent", s),
|
|
(s) => theme.fg("muted", s),
|
|
message,
|
|
);
|
|
this.addChild(this.loader);
|
|
this.addChild(new Spacer(1));
|
|
this.addChild(new Text(theme.fg("muted", "esc cancel"), 1, 0));
|
|
this.addChild(new Spacer(1));
|
|
this.addChild(new DynamicBorder());
|
|
}
|
|
|
|
get signal(): AbortSignal {
|
|
return this.loader.signal;
|
|
}
|
|
|
|
set onAbort(fn: (() => void) | undefined) {
|
|
this.loader.onAbort = fn;
|
|
}
|
|
|
|
handleInput(data: string): void {
|
|
this.loader.handleInput(data);
|
|
}
|
|
|
|
dispose(): void {
|
|
this.loader.dispose();
|
|
}
|
|
}
|