Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/cliffy/examples/keycode/read_key.ts

Command line framework for deno πŸ¦• Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...
Extremely Popular
Go to Latest
File
#!/usr/bin/env -S deno run --unstable
import { KeyCode } from "../../keycode/key_code.ts";
async function read(): Promise<void> { const buffer = new Uint8Array(8);
Deno.setRaw(Deno.stdin.rid, true); const nread = await Deno.stdin.read(buffer); Deno.setRaw(Deno.stdin.rid, false);
if (nread === null) { return; }
const data = buffer.subarray(0, nread);
const [event] = KeyCode.parse(data);
if (event?.name === "c" && event.ctrl) { console.log("exit"); return; }
console.log(event);
await read();}
console.log("Hit ctrl + c to exit.");
await read();