asciitorium
Version:
an ASCII CLUI framework
125 lines (124 loc) • 4.26 kB
TypeScript
import { Component, ComponentProps } from './Component.js';
import { FocusManager } from './FocusManager.js';
/**
* Configuration options for the App component.
*
* Extends ComponentProps with app-specific properties.
*/
export interface AppProps extends ComponentProps {
/** Font name for ASCII art text rendering (e.g., 'Standard', 'Doom') */
font?: string;
}
/**
* Root application component for asciitorium.
*
* The App class is the entry point for all asciitorium applications. It handles:
* - **Renderer Selection**: Automatically detects environment (web/CLI) and initializes appropriate renderer
* - **Focus Management**: Manages keyboard navigation between focusable components
* - **Performance Monitoring**: Tracks FPS, CPU, and memory usage
* - **Keyboard Handling**: Sets up global keyboard event handling
* - **Resize Handling**: Responds to terminal/window resize events
* - **Keybind Registry**: Manages global keyboard shortcuts
*
* The App automatically sizes itself to the screen if no dimensions are provided,
* and uses a column layout by default.
*
* @example
* Basic web application:
* ```tsx
* import { App, Button } from 'asciitorium';
*
* const app = (
* <App>
* <Button onClick={() => console.log('Clicked!')}>
* Click Me
* </Button>
* </App>
* );
* ```
*
* @example
* CLI application with custom size:
* ```tsx
* const app = (
* <App width={80} height={24} layout="column">
* <Text>Content</Text>
* </App>
* );
* ```
*/
export declare class App extends Component {
/** Reliable identifier for App class */
readonly isApp = true;
/** Focus manager for keyboard navigation */
readonly focus: FocusManager;
/** Renderer instance (DOMRenderer for web, TTYRenderer for CLI) */
private readonly renderer;
/** FPS counter for current second */
private fpsCounter;
/** Total render time for current second (ms) */
private totalRenderTime;
/** Current frames per second */
private currentFPS;
/** Current CPU usage percentage */
private currentCPU;
/** Current memory usage in MB */
private currentMemory;
/** Last CPU usage measurement for delta calculation */
private lastCPUUsage?;
/** Registry for global keyboard shortcuts */
private keybindRegistry;
/** Registry for mobile controller components */
private mobileControllerRegistry;
/** Whether width was explicitly fixed by user */
private readonly fixedWidth;
/** Whether height was explicitly fixed by user */
private readonly fixedHeight;
/**
* Creates a new App instance.
*
* Automatically detects the environment (web vs CLI) and initializes the
* appropriate renderer. Sets up keyboard handling, focus management, and
* performance monitoring.
*
* @param props - App configuration options
*/
constructor(props: AppProps);
/**
* Renders the application to the screen.
*
* Traverses the component tree, renders each component to buffers, and
* composites them based on z-index. Updates performance metrics and
* increments the FPS counter.
*
* This method is called automatically on initialization and whenever
* components request a re-render via the RenderScheduler.
*/
render(): void;
addChild(component: Component): void;
removeChild(component: Component): void;
getFPS(): number;
getRenderTime(): number;
getCPUUsage(): number;
getMemoryUsage(): number;
private updatePerformanceMetrics;
registerKeybind(keybind: any): void;
unregisterKeybind(keybind: any): void;
registerMobileController(controller: any): void;
unregisterMobileController(controller: any): void;
handleMobileButton(buttonId: string): void;
handleKey(key: string, event?: KeyboardEvent): void;
private getFocusedComponent;
private isKeybindActive;
private isComponentInTree;
private hasComponentWithFocus;
private setupResizeHandling;
getScreenSize(): {
width: number;
height: number;
};
start(): Promise<void>;
private resolveSizesRecursively;
private validateSizesResolved;
private resolveSizesForComponent;
}