2023-11-29 16:09:58 -05:00
|
|
|
import { RunTimeType } from './runtime.ts';
|
|
|
|
|
2024-06-21 14:14:10 -04:00
|
|
|
export { Position } from './position.ts';
|
|
|
|
|
2023-11-29 16:09:58 -05:00
|
|
|
/**
|
|
|
|
* The size of terminal in rows and columns
|
|
|
|
*/
|
|
|
|
export interface ITerminalSize {
|
|
|
|
rows: number;
|
|
|
|
cols: number;
|
|
|
|
}
|
|
|
|
|
2024-07-09 16:12:28 -04:00
|
|
|
/**
|
|
|
|
* Which direction to search in the current document
|
|
|
|
*/
|
|
|
|
export enum SearchDirection {
|
|
|
|
Forward = 1,
|
|
|
|
Backward = -1,
|
|
|
|
}
|
|
|
|
|
2024-01-10 15:44:19 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Runtime adapter interfaces
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2023-11-29 16:09:58 -05:00
|
|
|
/**
|
2024-07-09 16:12:28 -04:00
|
|
|
* Runtime-specific terminal functionality
|
2023-11-29 16:09:58 -05:00
|
|
|
*/
|
2024-07-09 16:12:28 -04:00
|
|
|
export interface ITerminal {
|
2023-11-29 16:09:58 -05:00
|
|
|
/**
|
2024-07-09 16:12:28 -04:00
|
|
|
* The arguments passed to the program on launch
|
2023-11-29 16:09:58 -05:00
|
|
|
*/
|
2024-07-09 16:12:28 -04:00
|
|
|
argv: string[];
|
2023-11-29 16:09:58 -05:00
|
|
|
|
|
|
|
/**
|
2024-07-09 16:12:28 -04:00
|
|
|
* The generator function returning chunks of input from the stdin stream
|
2023-11-29 16:09:58 -05:00
|
|
|
*/
|
2024-07-09 16:12:28 -04:00
|
|
|
inputLoop(): AsyncGenerator<Uint8Array, null>;
|
2023-11-29 16:09:58 -05:00
|
|
|
|
2024-07-09 16:12:28 -04:00
|
|
|
/**
|
|
|
|
* Get the size of the terminal
|
|
|
|
*/
|
|
|
|
getTerminalSize(): Promise<ITerminalSize>;
|
2023-11-29 16:09:58 -05:00
|
|
|
|
2024-07-09 16:12:28 -04:00
|
|
|
/**
|
|
|
|
* Get the current chunk of input, if it exists
|
|
|
|
*/
|
|
|
|
readStdin(): Promise<string | null>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the raw chunk of input
|
|
|
|
*/
|
|
|
|
readStdinRaw(): Promise<Uint8Array | null>;
|
2023-11-29 16:09:58 -05:00
|
|
|
|
2024-07-09 16:12:28 -04:00
|
|
|
/**
|
|
|
|
* Pipe a string to stdout
|
|
|
|
*/
|
|
|
|
writeStdout(s: string): Promise<void>;
|
|
|
|
}
|
2023-11-29 16:09:58 -05:00
|
|
|
|
2024-07-09 16:12:28 -04:00
|
|
|
/**
|
|
|
|
* Runtime-specific file system io
|
|
|
|
*/
|
|
|
|
export interface IFileIO {
|
|
|
|
/**
|
|
|
|
* Open an entire file
|
|
|
|
*
|
|
|
|
* @param path
|
|
|
|
*/
|
|
|
|
openFile(path: string): Promise<string>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Append to a file, or create it if it doesn't exist
|
|
|
|
*
|
|
|
|
* @param path
|
|
|
|
* @param contents
|
|
|
|
*/
|
|
|
|
appendFile(path: string, contents: string): Promise<void>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save a string into a file
|
|
|
|
*
|
|
|
|
* @param path
|
|
|
|
* @param contents
|
|
|
|
*/
|
|
|
|
saveFile(path: string, contents: string): Promise<void>;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The common interface for runtime adapters
|
|
|
|
*/
|
|
|
|
export interface IRuntime {
|
|
|
|
/**
|
|
|
|
* The name of the runtime
|
|
|
|
*/
|
|
|
|
name: RunTimeType;
|
2023-11-29 16:09:58 -05:00
|
|
|
|
2024-07-09 16:12:28 -04:00
|
|
|
/**
|
|
|
|
* Runtime-specific terminal functionality
|
|
|
|
*/
|
|
|
|
term: ITerminal;
|
2023-11-29 16:09:58 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Runtime-specific file system io
|
|
|
|
*/
|
2024-07-09 16:12:28 -04:00
|
|
|
file: IFileIO;
|
2023-11-29 16:09:58 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2023-11-10 08:36:18 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Testing
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The shared test interface, so tests can be run by both runtimes
|
|
|
|
*/
|
|
|
|
export interface ITestBase {
|
2024-07-09 16:12:28 -04:00
|
|
|
/**
|
|
|
|
* The values (often objects) have all the same property values
|
|
|
|
*
|
|
|
|
* @param actual
|
|
|
|
* @param expected
|
|
|
|
*/
|
|
|
|
assertEquivalent(actual: unknown, expected: unknown): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The value is not null or undefined
|
|
|
|
*
|
|
|
|
* @param actual
|
|
|
|
*/
|
2023-11-10 08:36:18 -05:00
|
|
|
assertExists(actual: unknown): void;
|
2024-07-09 16:12:28 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The value is false
|
|
|
|
*
|
|
|
|
* @param actual
|
|
|
|
*/
|
2023-11-16 20:57:21 -05:00
|
|
|
assertFalse(actual: boolean): void;
|
2024-07-09 16:12:28 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* `actual` is an object implementing `expectedType`
|
|
|
|
*
|
|
|
|
* @param actual
|
|
|
|
* @param expectedType
|
|
|
|
*/
|
2023-11-10 08:36:18 -05:00
|
|
|
assertInstanceOf(actual: unknown, expectedType: any): void;
|
2024-07-09 16:12:28 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The values are not exactly equal (Different instance, type, value, etc)
|
|
|
|
*
|
|
|
|
* @param actual
|
|
|
|
* @param expected
|
|
|
|
*/
|
2023-11-16 20:57:21 -05:00
|
|
|
assertNotEquals(actual: unknown, expected: unknown): void;
|
2024-07-09 16:12:28 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The values are exactly the same
|
|
|
|
*
|
|
|
|
* @param actual
|
|
|
|
* @param expected
|
|
|
|
*/
|
|
|
|
assertEquals(actual: unknown, expected: unknown): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The value is true
|
|
|
|
*
|
|
|
|
* @param actual
|
|
|
|
*/
|
2023-11-10 08:36:18 -05:00
|
|
|
assertTrue(actual: boolean): void;
|
2023-11-16 20:57:21 -05:00
|
|
|
testSuite(testObj: any): void;
|
2023-11-10 08:36:18 -05:00
|
|
|
}
|