Something went wrong. Try again.
fork of prime agent with changes i want but are not upstreamable probqbly (and some fixes)
Something went wrong. Try again.
783 B · 34 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435import type { TUI } from "@earendil-works/pi-tui";
export class CountdownTimer { private intervalId: ReturnType<typeof setInterval> | undefined; private remainingSeconds: number;
constructor( timeoutMs: number, private tui: TUI | undefined, private onTick: (seconds: number) => void, private onExpire: () => void, ) { this.remainingSeconds = Math.ceil(timeoutMs / 1000); this.onTick(this.remainingSeconds);
this.intervalId = setInterval(() => { this.remainingSeconds--; this.onTick(this.remainingSeconds); this.tui?.requestRender();
if (this.remainingSeconds <= 0) { this.dispose(); this.onExpire(); } }, 1000); }
dispose(): void { if (this.intervalId) { clearInterval(this.intervalId); this.intervalId = undefined; } }}