42 lines
936 B
JavaScript
42 lines
936 B
JavaScript
import { importForRuntime } from './runtime.ts';
|
|
import { Editor } from './editor.ts';
|
|
import { getTermios } from './termios.ts';
|
|
|
|
export * from './runtime.ts';
|
|
export * from './strings.ts';
|
|
export type * from './types.ts';
|
|
|
|
const decoder = new TextDecoder();
|
|
|
|
export async function main() {
|
|
const { inputLoop, onExit } = await importForRuntime('mod.ts');
|
|
|
|
// Setup raw mode, and tear down on error or normal exit
|
|
const t = await getTermios();
|
|
t.enableRawMode();
|
|
onExit(() => {
|
|
console.info('Exit handler called, disabling raw mode');
|
|
t.disableRawMode();
|
|
});
|
|
|
|
// Create the editor itself
|
|
const editor = new Editor();
|
|
|
|
// The main event loop
|
|
for await (const chunk of inputLoop()) {
|
|
const char = String(decoder.decode(chunk));
|
|
|
|
// Clear the screen for output
|
|
await editor.refreshScreen();
|
|
|
|
// Process input
|
|
const shouldLoop = editor.processKeyPress(char);
|
|
|
|
if (!shouldLoop) {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|