scroll/src/common/mod.ts

39 lines
857 B
JavaScript
Raw Normal View History

2023-11-08 08:02:03 -05:00
import { importForRuntime } from "./runtime";
import { ctrl_key, is_control } from "./strings";
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-08 08:02:03 -05:00
const decoder = new TextDecoder();
export function readKey(chunk): string {
const char = String(decoder.decode(chunk))
return char;
}
export 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 char = readKey(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;
}