scroll/src/common/mod.ts

35 lines
853 B
JavaScript
Raw Normal View History

import { importForRuntime } from './runtime.ts';
import { getTermios } from './termios.ts';
import { ctrl_key, is_control } from './strings.ts';
2023-11-03 11:59:58 -04:00
export * from './runtime.ts';
export * from './strings.ts';
export type { ITestBase } from './test_base.ts';
export async function main() {
const t = await getTermios();
t.enableRawMode();
const { inputLoop, init } = await importForRuntime('mod.ts');
// Set up handlers to disable raw mode for each runtime
await init();
for await (const chunk of inputLoop()) {
const decoder = new TextDecoder();
const char = String(decoder.decode(chunk));
if (char === ctrl_key('q')) {
t.disableRawMode();
return 0;
}
if (is_control(char)) {
console.log(char.codePointAt(0) + '\r');
} else {
console.log(`${char} ('${char.codePointAt(0)}')\r`);
}
}
t.disableRawMode();
return -1;
}