2023-10-27 12:11:48 -04:00
|
|
|
/**
|
|
|
|
* The starting point for running scroll
|
|
|
|
*/
|
2023-11-08 18:07:34 -05:00
|
|
|
import {
|
|
|
|
Editor,
|
|
|
|
getTermios,
|
|
|
|
importDefaultForRuntime,
|
|
|
|
importForRuntime,
|
|
|
|
} from './common/mod.ts';
|
2023-11-08 17:02:59 -05:00
|
|
|
|
|
|
|
const decoder = new TextDecoder();
|
|
|
|
|
|
|
|
export async function main() {
|
2023-11-09 10:46:12 -05:00
|
|
|
const { inputLoop, getSize } = await importDefaultForRuntime(
|
|
|
|
'terminal_io.ts',
|
|
|
|
);
|
2023-11-08 18:07:34 -05:00
|
|
|
const { onExit } = await importForRuntime('mod.ts');
|
2023-11-08 17:02:59 -05:00
|
|
|
|
|
|
|
// Setup raw mode, and tear down on error or normal exit
|
|
|
|
const t = await getTermios();
|
|
|
|
t.enableRawMode();
|
|
|
|
onExit(() => {
|
2023-11-09 12:05:30 -05:00
|
|
|
console.log('Exit handler called, disabling raw mode\r\n');
|
2023-11-08 17:02:59 -05:00
|
|
|
t.disableRawMode();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Create the editor itself
|
2023-11-09 10:46:12 -05:00
|
|
|
const editor = new Editor(getSize());
|
2023-11-09 12:05:30 -05:00
|
|
|
await editor.refreshScreen();
|
2023-11-08 17:02:59 -05:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
2023-11-01 15:05:31 -04:00
|
|
|
|
2023-10-27 16:02:54 -04:00
|
|
|
/**
|
2023-11-03 12:26:09 -04:00
|
|
|
* Start the event loop
|
2023-10-27 16:02:54 -04:00
|
|
|
*/
|
2023-11-03 12:26:09 -04:00
|
|
|
await main();
|