2023-11-08 11:11:19 -05:00
|
|
|
import { importForRuntime } from './runtime.ts';
|
|
|
|
import { Editor } from './editor.ts';
|
2023-11-08 08:02:03 -05:00
|
|
|
|
2023-11-03 11:59:58 -04:00
|
|
|
export * from './runtime.ts';
|
|
|
|
export * from './strings.ts';
|
2023-11-06 18:49:29 -05:00
|
|
|
export * from './termios.ts';
|
2023-11-03 11:59:58 -04:00
|
|
|
export type { ITestBase } from './test_base.ts';
|
2023-11-03 12:26:09 -04:00
|
|
|
|
2023-11-08 08:02:03 -05:00
|
|
|
const decoder = new TextDecoder();
|
|
|
|
|
|
|
|
export async function main() {
|
|
|
|
const { inputLoop, init } = await importForRuntime('mod.ts');
|
|
|
|
|
|
|
|
// Set up handlers to enable/disable raw mode for each runtime
|
|
|
|
await init();
|
|
|
|
|
2023-11-08 11:11:19 -05:00
|
|
|
// Create the editor itself
|
|
|
|
const editor = new Editor();
|
|
|
|
|
2023-11-08 08:02:03 -05:00
|
|
|
// The main event loop
|
|
|
|
for await (const chunk of inputLoop()) {
|
2023-11-08 11:11:19 -05:00
|
|
|
const char = String(decoder.decode(chunk));
|
2023-11-08 08:02:03 -05:00
|
|
|
|
2023-11-08 11:11:19 -05:00
|
|
|
// Clear the screen for output
|
|
|
|
await editor.refreshScreen();
|
|
|
|
|
|
|
|
// Process input
|
|
|
|
const shouldLoop = editor.processKeyPress(char);
|
2023-11-08 08:02:03 -05:00
|
|
|
|
2023-11-08 11:11:19 -05:00
|
|
|
if (!shouldLoop) {
|
|
|
|
return 0;
|
2023-11-08 08:02:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2023-11-08 11:11:19 -05:00
|
|
|
}
|