@bruggmann._/ccli 1.0.1 → 1.0.2
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.
|
@@ -13,10 +13,41 @@ const colors_1 = require("./colors");
|
|
|
13
13
|
function isMenuMessage(msg) {
|
|
14
14
|
return msg.type === 'menu';
|
|
15
15
|
}
|
|
16
|
+
let shuttingDown = false;
|
|
17
|
+
function isPromptAbortError(err) {
|
|
18
|
+
if (!err || typeof err !== 'object')
|
|
19
|
+
return false;
|
|
20
|
+
const maybeError = err;
|
|
21
|
+
return (maybeError.name === 'ExitPromptError' ||
|
|
22
|
+
maybeError.message?.includes('User force closed the prompt') === true);
|
|
23
|
+
}
|
|
24
|
+
function gracefulShutdown(code = 0) {
|
|
25
|
+
if (shuttingDown)
|
|
26
|
+
return;
|
|
27
|
+
shuttingDown = true;
|
|
28
|
+
(0, ui_1.endInteractivePrompt)();
|
|
29
|
+
if (socket_1.socket.readyState === socket_1.socket.OPEN ||
|
|
30
|
+
socket_1.socket.readyState === socket_1.socket.CONNECTING) {
|
|
31
|
+
socket_1.socket.once('close', () => process.exit(code));
|
|
32
|
+
socket_1.socket.close();
|
|
33
|
+
setTimeout(() => {
|
|
34
|
+
process.exit(code);
|
|
35
|
+
}, 250);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
process.exit(code);
|
|
39
|
+
}
|
|
40
|
+
process.on('SIGINT', () => {
|
|
41
|
+
gracefulShutdown(0);
|
|
42
|
+
});
|
|
16
43
|
socket_1.socket.on('open', () => {
|
|
17
44
|
main().catch(err => {
|
|
45
|
+
if (isPromptAbortError(err)) {
|
|
46
|
+
gracefulShutdown(0);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
18
49
|
console.error(err);
|
|
19
|
-
|
|
50
|
+
gracefulShutdown(1);
|
|
20
51
|
});
|
|
21
52
|
});
|
|
22
53
|
async function main() {
|
|
@@ -27,13 +58,13 @@ async function main() {
|
|
|
27
58
|
while (true) {
|
|
28
59
|
const action = await (0, menu_1.showMenu)(menu.payload.users, menu.payload.channels);
|
|
29
60
|
if (action.type === 'exit')
|
|
30
|
-
exitApp();
|
|
61
|
+
return exitApp();
|
|
31
62
|
(0, socket_1.sendJson)(socket_1.socket, { type: 'join', payload: { channel: action.channel } });
|
|
32
63
|
(0, render_1.clearScreen)();
|
|
33
64
|
(0, ui_1.endInteractivePrompt)();
|
|
34
65
|
const reason = await chatLoop(nickname);
|
|
35
66
|
if (reason === 'exit')
|
|
36
|
-
exitApp();
|
|
67
|
+
return exitApp();
|
|
37
68
|
(0, socket_1.sendJson)(socket_1.socket, { type: 'menu_request' });
|
|
38
69
|
menu = await (0, socket_1.waitForServerMessage)(socket_1.socket, isMenuMessage);
|
|
39
70
|
}
|
|
@@ -65,8 +96,7 @@ function setupMessageHandler() {
|
|
|
65
96
|
});
|
|
66
97
|
}
|
|
67
98
|
function exitApp() {
|
|
68
|
-
|
|
69
|
-
process.exit(0);
|
|
99
|
+
gracefulShutdown(0);
|
|
70
100
|
}
|
|
71
101
|
async function getNickname() {
|
|
72
102
|
return (0, input_1.prompt)('Enter your nickname:', {
|