2023-11-03 12:26:09 -04:00
|
|
|
import { importForRuntime } from './runtime.ts';
|
2023-11-06 15:36:41 -05:00
|
|
|
import { getTermios } from './termios.ts';
|
|
|
|
import { ctrl_key, is_control } from './strings.ts';
|
2023-11-03 12:26:09 -04:00
|
|
|
|
2023-11-03 11:59:58 -04:00
|
|
|
export * from './runtime.ts';
|
|
|
|
export * from './strings.ts';
|
|
|
|
export type { ITestBase } from './test_base.ts';
|
2023-11-03 12:26:09 -04:00
|
|
|
|
|
|
|
export async function main() {
|
2023-11-06 15:36:41 -05:00
|
|
|
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;
|
|
|
|
}
|