@bruggmann._/ccli 1.0.0 → 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.
package/README.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
A terminal-based real-time chat built with TypeScript and WebSockets.
|
|
4
4
|
|
|
5
|
+
## Quick Start (via npm)
|
|
6
|
+
|
|
7
|
+
Install and run the client directly from your terminal:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g "@bruggmann._/ccli"
|
|
11
|
+
ccli
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Or run without installing:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npx "@bruggmann._/ccli"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
> **Note:** On PowerShell, wrap the package name in quotes as shown above.
|
|
21
|
+
|
|
5
22
|
## Features
|
|
6
23
|
|
|
7
24
|
- Real-time messaging via WebSockets
|
|
@@ -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:', {
|
|
@@ -11,7 +11,7 @@ const schemas_1 = require("../../shared/src/schemas");
|
|
|
11
11
|
const ws_1 = require("ws");
|
|
12
12
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
13
13
|
dotenv_1.default.config();
|
|
14
|
-
exports.socket = new ws_1.WebSocket(process.env.SERVER_URL);
|
|
14
|
+
exports.socket = new ws_1.WebSocket(process.env.SERVER_URL ?? 'wss://ccli-tpio.onrender.com');
|
|
15
15
|
function sendJson(socket, msg) {
|
|
16
16
|
socket.send(JSON.stringify(msg));
|
|
17
17
|
}
|