- Remove old TUI implementation and components (LoadingAnimation, MarkdownComponent, TextComponent, TextEditor, WhitespaceComponent) - Rename components-new to components with new API (Loader, Markdown, Text, Editor, Spacer) - Move Text and Input components to separate files in src/components/ - Add render caching to Text component (similar to Markdown) - Add proper ANSI code handling in Text component using stripVTControlCharacters - Update coding-agent to use new TUI API (requires ProcessTerminal, uses custom Editor subclass for key handling) - Remove old test files, keep only chat-simple.ts and virtual-terminal.ts - Update README.md with new minimal API documentation - Switch from tsc to tsgo for type checking - Update package dependencies across monorepo
51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
import chalk from "chalk";
|
|
import type { TUI } from "../tui.js";
|
|
import { Text } from "./text.js";
|
|
|
|
/**
|
|
* Loader component that updates every 80ms with spinning animation
|
|
*/
|
|
export class Loader extends Text {
|
|
private frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
private currentFrame = 0;
|
|
private intervalId: NodeJS.Timeout | null = null;
|
|
private ui: TUI | null = null;
|
|
|
|
constructor(
|
|
ui: TUI,
|
|
private message: string = "Loading...",
|
|
) {
|
|
super("");
|
|
this.ui = ui;
|
|
this.start();
|
|
}
|
|
|
|
start() {
|
|
this.updateDisplay();
|
|
this.intervalId = setInterval(() => {
|
|
this.currentFrame = (this.currentFrame + 1) % this.frames.length;
|
|
this.updateDisplay();
|
|
}, 80);
|
|
}
|
|
|
|
stop() {
|
|
if (this.intervalId) {
|
|
clearInterval(this.intervalId);
|
|
this.intervalId = null;
|
|
}
|
|
}
|
|
|
|
setMessage(message: string) {
|
|
this.message = message;
|
|
this.updateDisplay();
|
|
}
|
|
|
|
private updateDisplay() {
|
|
const frame = this.frames[this.currentFrame];
|
|
this.setText(`${chalk.cyan(frame)} ${chalk.dim(this.message)}`);
|
|
if (this.ui) {
|
|
this.ui.requestRender();
|
|
}
|
|
}
|
|
}
|