import { RunTimeType } from './runtime.ts'; export { Position } from './position.ts'; /** * The size of terminal in rows and columns */ export interface ITerminalSize { rows: number; cols: number; } // ---------------------------------------------------------------------------- // Runtime adapter interfaces // ---------------------------------------------------------------------------- /** * The common interface for runtime adapters */ export interface IRuntime { /** * The name of the runtime */ name: RunTimeType; /** * Runtime-specific terminal functionality */ term: { /** * The arguments passed to the program on launch */ argv: string[]; /** * The generator function returning chunks of input from the stdin stream */ inputLoop(): AsyncGenerator; /** * Get the size of the terminal */ getTerminalSize(): Promise; /** * Get the current chunk of input, if it exists */ readStdin(): Promise; /** * Get the raw chunk of input */ readStdinRaw(): Promise; /** * Pipe a string to stdout */ writeStdout(s: string): Promise; }; /** * Runtime-specific file system io */ file: { openFile(path: string): Promise; appendFile(path: string, contents: string): Promise; saveFile(path: string, contents: string): Promise; }; /** * Set up an event handler * * @param eventName - The event to listen for * @param handler - The event handler */ onEvent: ( eventName: string, handler: (e: Event | ErrorEvent) => void, ) => void; /** * Set a beforeExit/beforeUnload event handler for the runtime * @param cb - The event handler */ onExit(cb: () => void): void; /** * Stop execution * * @param code */ exit(code?: number): void; } /** * Runtime-specific terminal functionality */ export type ITerminal = IRuntime['term']; /** * Runtime-specific file handling */ export type IFileIO = IRuntime['file']; // ---------------------------------------------------------------------------- // Testing // ---------------------------------------------------------------------------- /** * The shared test interface, so tests can be run by both runtimes */ export interface ITestBase { assertEquals(actual: unknown, expected: unknown): void; assertExists(actual: unknown): void; assertFalse(actual: boolean): void; assertInstanceOf(actual: unknown, expectedType: any): void; assertNotEquals(actual: unknown, expected: unknown): void; assertNull(actual: unknown): void; assertStrictEquals(actual: unknown, expected: unknown): void; assertTrue(actual: boolean): void; testSuite(testObj: any): void; }