2023-11-08 15:53:14 -05:00
|
|
|
/**
|
|
|
|
* The shared test interface, so tests can be run by both runtimes
|
|
|
|
*/
|
|
|
|
export interface ITestBase {
|
|
|
|
test(name: string, fn: () => void): void;
|
|
|
|
assertEquals(actual: unknown, expected: unknown): void;
|
|
|
|
assertNotEquals(actual: unknown, expected: unknown): void;
|
|
|
|
assertStrictEquals(actual: unknown, expected: unknown): void;
|
|
|
|
assertExists(actual: unknown): void;
|
|
|
|
assertInstanceOf(actual: unknown, expectedType: any): void;
|
|
|
|
assertTrue(actual: boolean): void;
|
|
|
|
assertFalse(actual: boolean): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The native functions for terminal settings
|
|
|
|
*/
|
|
|
|
export interface IFFI {
|
|
|
|
/**
|
|
|
|
* Get the existing termios settings (for canonical mode)
|
|
|
|
*/
|
|
|
|
tcgetattr(fd: number, termiosPtr: unknown): number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the termios settings
|
|
|
|
*/
|
|
|
|
tcsetattr(fd: number, act: number, termiosPtr: unknown): number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the termios pointer with raw mode settings
|
|
|
|
*/
|
|
|
|
cfmakeraw(termiosPtr: unknown): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a TypedArray to an opaque pointer for ffi calls
|
|
|
|
*/
|
|
|
|
getPointer(ta: any): unknown;
|
|
|
|
}
|
|
|
|
|
2023-11-08 17:02:59 -05:00
|
|
|
export interface ITerminalSize {
|
|
|
|
rows: number;
|
|
|
|
cols: number;
|
|
|
|
}
|
|
|
|
|
2023-11-08 15:53:14 -05:00
|
|
|
/**
|
|
|
|
* Runtime-specific IO streams
|
|
|
|
*/
|
|
|
|
export interface ITerminalIO {
|
|
|
|
/**
|
|
|
|
* The generator function returning chunks of input from the stdin stream
|
|
|
|
*/
|
|
|
|
inputLoop(): AsyncGenerator<Uint8Array, void, unknown>;
|
|
|
|
|
2023-11-08 17:02:59 -05:00
|
|
|
/**
|
|
|
|
* Get the size of the terminal
|
|
|
|
*/
|
|
|
|
getSize(): ITerminalSize;
|
|
|
|
|
2023-11-08 15:53:14 -05:00
|
|
|
/**
|
|
|
|
* Pipe a string to stdout
|
|
|
|
*/
|
|
|
|
write(s: string): Promise<void>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IRuntime {
|
|
|
|
/**
|
|
|
|
* Set a beforeExit/beforeUnload event handler for the runtime
|
|
|
|
* @param cb - The event handler
|
|
|
|
*/
|
|
|
|
onExit(cb: () => void): void;
|
|
|
|
}
|