-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest-keys.js
31 lines (27 loc) · 896 Bytes
/
test-keys.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"use strict";
const readline = require("readline");
process.stdin.setRawMode(true);
process.stdin.setEncoding("utf8");
readline.emitKeypressEvents(process.stdin);
process.stdin.on("data", (data) => {
console.log("data: ", JSON.stringify(data));
});
// `keypress.sequence` is mostly identical to `data` above.
// However, Vim begins by writing:
// "\u001b]11;rgb:28/2c/34\u0007", which
// `readline` splits that into:
// "\u001b]", "1", "1", ";", "r", "g", "b", ":", "2", "8", "/", "2", "c", "/", "3", "4" "\u0007"
// That breaks Vim, so we can’t use "keypress".
process.stdin.on(
"keypress",
/**
* @param {unknown} unknown
* @param {{ ctrl: boolean, name: string }} keypress
*/
(unknown, keypress) => {
console.log("keypress:", JSON.stringify(unknown), JSON.stringify(keypress));
if (keypress.ctrl && keypress.name === "c") {
process.exit();
}
},
);