28 lines
609 B
TypeScript
28 lines
609 B
TypeScript
// ── Keyboard input via blessed ────────────────────────
|
|
import type blessed from "blessed";
|
|
|
|
export type Key =
|
|
| "h"
|
|
| "s"
|
|
| "n"
|
|
| "up"
|
|
| "down"
|
|
| "q";
|
|
|
|
/** Wire blessed screen key events to a callback. */
|
|
export function startInput(
|
|
screen: blessed.Widgets.Screen,
|
|
onKey: (key: Key) => void,
|
|
): void {
|
|
screen.key(
|
|
["h", "s", "n", "up", "down", "q", "C-c"],
|
|
(_ch, key) => {
|
|
if (key.name === "q" || key.name === "C-c") {
|
|
screen.destroy();
|
|
process.exit(0);
|
|
}
|
|
onKey(key.name as Key);
|
|
},
|
|
);
|
|
}
|