第一版

This commit is contained in:
yinsx
2025-12-16 16:21:26 +08:00
parent 0c73ef2547
commit 8ba7e635f5
15 changed files with 1006 additions and 30 deletions

18
lib/keyboard.js Normal file
View File

@ -0,0 +1,18 @@
import readline from "readline";
let initialized = false;
export function initKeypress() {
if (!initialized) {
readline.emitKeypressEvents(process.stdin);
initialized = true;
}
process.stdin.removeAllListeners("keypress");
if (process.stdin.isTTY) {
process.stdin.setRawMode(true);
}
}
export function onKey(handler) {
process.stdin.on("keypress", handler);
}