scroll/src/scroll.ts

35 lines
698 B
JavaScript

/**
* The starting point for running scroll
*/
import { ctrl_key, importForRuntime, is_control } from './common/mod.ts';
async function main() {
const { inputLoop, init } = await importForRuntime('mod.ts');
// Set up handlers to enable/disable raw mode for each runtime
await init();
// The main event loop
for await (const chunk of inputLoop()) {
const decoder = new TextDecoder();
const char = String(decoder.decode(chunk));
if (char === ctrl_key('q')) {
return 0;
}
if (is_control(char)) {
console.log(char.codePointAt(0) + '\r');
} else {
console.log(`${char} ('${char.codePointAt(0)}')\r`);
}
}
return -1;
}
/**
* Start the event loop
*/
await main();