scroll/src/scroll.ts

45 lines
901 B
JavaScript

/**
* The starting point for running scroll
*/
import { Editor, getRuntime, getTermios } from './common/mod.ts';
const decoder = new TextDecoder();
export async function main() {
const runTime = await getRuntime();
const { io, onExit } = runTime;
// Setup raw mode, and tear down on error or normal exit
const t = await getTermios();
t.enableRawMode();
onExit(() => {
t.disableRawMode();
});
const terminalSize = await io.getTerminalSize();
// Create the editor itself
const editor = new Editor(terminalSize);
await editor.refreshScreen();
// The main event loop
for await (const chunk of io.inputLoop()) {
// Process input
const char = String(decoder.decode(chunk));
const shouldLoop = editor.processKeyPress(char);
if (!shouldLoop) {
return 0;
}
// Render output
await editor.refreshScreen();
}
return -1;
}
/**
* Start the event loop
*/
await main();