2023-10-27 16:02:54 -04:00
|
|
|
/**
|
|
|
|
* The main entrypoint when using Deno as the runtime
|
|
|
|
*/
|
2023-11-01 15:27:31 -04:00
|
|
|
import { getTermios } from '../common/termios.ts';
|
2023-11-02 13:06:48 -04:00
|
|
|
import { ctrl_key, is_control } from '../common/strings.ts';
|
2023-11-01 15:05:31 -04:00
|
|
|
|
2023-10-27 16:02:54 -04:00
|
|
|
export async function main(): Promise<number> {
|
2023-11-01 15:27:31 -04:00
|
|
|
const t = await getTermios();
|
2023-11-01 15:05:31 -04:00
|
|
|
t.enableRawMode();
|
|
|
|
|
2023-10-27 16:02:54 -04:00
|
|
|
const decoder = new TextDecoder();
|
|
|
|
for await (const chunk of Deno.stdin.readable) {
|
2023-11-02 13:06:48 -04:00
|
|
|
const char = String(decoder.decode(chunk));
|
2023-10-27 16:02:54 -04:00
|
|
|
|
2023-11-02 13:06:48 -04:00
|
|
|
if (char === ctrl_key('q')) {
|
2023-11-01 15:05:31 -04:00
|
|
|
t.disableRawMode();
|
2023-10-27 16:02:54 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2023-11-02 13:06:48 -04:00
|
|
|
|
|
|
|
if (is_control(char)) {
|
|
|
|
console.log(char.codePointAt(0) + '\r');
|
|
|
|
} else {
|
|
|
|
console.log(`${char} ('${char.codePointAt(0)}')\r`);
|
|
|
|
}
|
2023-10-27 16:02:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2023-11-01 15:27:31 -04:00
|
|
|
}
|