Cliffy ❯ KeyCode
ANSI key code parser for Deno
>_ Used by cliffy’s prompt module.
❯ Content
❯ Install
This module can be imported directly from the repo and from following registries.
Deno Registry
import { KeyCode } from "https://deno.land/x/cliffy@<version>/keycode/mod.ts";
Nest Registry
import { KeyCode } from "https://x.nest.land/cliffy@<version>/keycode/mod.ts";
Github
import { KeyCode } from "https://raw.githubusercontent.com/c4spar/deno-cliffy/<version>/keycode/mod.ts";
❯ Usage
import { KeyCode } from "https://deno.land/x/cliffy/keycode/mod.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();
$ deno run --unstable https://deno.land/x/cliffy/examples/keycode/read_key.ts
❯ API
KeyCode
- parse( data: Uint8Array | string ): KeyEvent | undefined
KeyEvent
- name?: string
- sequence?: string
- ctrl: boolean
- meta: boolean
- shift: boolean
❯ Contributing
Any kind of contribution is welcome! Please take a look at the contributing guidelines.