xshell 1.1.10 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/stdin.d.ts +4 -0
- package/stdin.js +23 -0
package/package.json
CHANGED
package/stdin.d.ts
ADDED
package/stdin.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import process from 'process';
|
|
2
|
+
/** 监听终端按键 (输入),并调用 key_processor 处理
|
|
3
|
+
- on_key: 按键处理函数
|
|
4
|
+
- on_exit?: ctrl + c 会退出进程,可加入退出前自定义处理逻辑 */
|
|
5
|
+
export function process_stdin(on_key, on_exit) {
|
|
6
|
+
// https://stackoverflow.com/a/12506613/7609214
|
|
7
|
+
let { stdin } = process;
|
|
8
|
+
stdin.setRawMode(true);
|
|
9
|
+
stdin.resume();
|
|
10
|
+
stdin.setEncoding('utf-8');
|
|
11
|
+
// on any data into stdin
|
|
12
|
+
stdin.on('data', async (key) => {
|
|
13
|
+
// ctrl-c ( end of text )
|
|
14
|
+
if (key === '\u0003') {
|
|
15
|
+
await on_exit?.();
|
|
16
|
+
process.exit();
|
|
17
|
+
}
|
|
18
|
+
// write the key to stdout all normal like
|
|
19
|
+
console.log(key);
|
|
20
|
+
await on_key(key);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=stdin.js.map
|