2023-03-24 19:36:11 +00:00
|
|
|
import { readLines } from './deps.ts';
|
|
|
|
|
2023-03-24 21:08:36 +00:00
|
|
|
import type { InputMessage, OutputMessage } from './types.ts';
|
2023-03-24 19:36:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the first line from stdin.
|
|
|
|
* Can only be read ONCE, or else it returns undefined.
|
|
|
|
*/
|
|
|
|
async function readStdin(): Promise<InputMessage> {
|
|
|
|
const { value } = await readLines(Deno.stdin).next();
|
|
|
|
return JSON.parse(value);
|
|
|
|
}
|
|
|
|
|
2023-03-24 21:08:36 +00:00
|
|
|
/** Writes the output message to stdout. */
|
|
|
|
function writeStdout(msg: OutputMessage): void {
|
|
|
|
console.log(JSON.stringify(msg));
|
|
|
|
}
|
|
|
|
|
|
|
|
export { readStdin, writeStdout };
|