@pdc-test/chat-io 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.
- package/bin/cli.js +24 -16
- package/package.json +2 -2
- package/src/server/index.js +1 -2
package/bin/cli.js
CHANGED
|
@@ -28,6 +28,7 @@ let typingUsers = new Set();
|
|
|
28
28
|
let userTypingTimers = {};
|
|
29
29
|
let typingFrames = ['.', '..', '...'];
|
|
30
30
|
let tIdx = 0;
|
|
31
|
+
let isMultilinePrompt = false;
|
|
31
32
|
|
|
32
33
|
// Escuchador de teclado constante (Raw Mode Mágico)
|
|
33
34
|
process.stdin.on('keypress', (str, key) => {
|
|
@@ -54,15 +55,20 @@ setInterval(() => {
|
|
|
54
55
|
const users = Array.from(typingUsers).join(", ");
|
|
55
56
|
const suffix = users.includes(",") ? "están escribiendo" : "está escribiendo";
|
|
56
57
|
|
|
57
|
-
// Cambiar el diseño del prompt para mostrar texto gris ANTES del "> "
|
|
58
58
|
rl.setPrompt(`\x1b[90m[${users} ${suffix} ${typingFrames[tIdx]}]\x1b[0m\n> `);
|
|
59
59
|
tIdx = (tIdx + 1) % typingFrames.length;
|
|
60
60
|
rl.prompt(true);
|
|
61
|
+
isMultilinePrompt = true;
|
|
61
62
|
} else {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
if (isMultilinePrompt) {
|
|
64
|
+
rl.setPrompt('> ');
|
|
65
|
+
// Borrar el fantasma superior que dejó el prompt multilinea
|
|
66
|
+
readline.moveCursor(process.stdout, 0, -1);
|
|
67
|
+
readline.clearLine(process.stdout, 0);
|
|
68
|
+
readline.moveCursor(process.stdout, 0, 1);
|
|
69
|
+
rl.prompt(true);
|
|
70
|
+
isMultilinePrompt = false;
|
|
71
|
+
}
|
|
66
72
|
}
|
|
67
73
|
}, 400);
|
|
68
74
|
|
|
@@ -85,27 +91,29 @@ ws.on('message', (data) => {
|
|
|
85
91
|
return;
|
|
86
92
|
}
|
|
87
93
|
|
|
88
|
-
if (msg.startsWith("/
|
|
89
|
-
const u = msg.replace("/
|
|
94
|
+
if (msg.startsWith("/typ_stop_event ")) {
|
|
95
|
+
const u = msg.replace("/typ_stop_event ", "").trim();
|
|
90
96
|
typingUsers.delete(u);
|
|
91
97
|
clearTimeout(userTypingTimers[u]);
|
|
92
|
-
|
|
93
|
-
if (typingUsers.size === 0) {
|
|
94
|
-
rl.setPrompt('> ');
|
|
95
|
-
}
|
|
96
98
|
return;
|
|
97
99
|
}
|
|
98
100
|
|
|
99
|
-
// Si recibimos texto normal, limpiamos
|
|
101
|
+
// Si recibimos texto normal, limpiamos todas las señales tácticas
|
|
100
102
|
typingUsers.clear();
|
|
101
|
-
rl.setPrompt('> ');
|
|
102
103
|
|
|
103
|
-
// Purgamos
|
|
104
|
+
// Purgamos toda visualización flotante o entrada corrupta antes de dibujar texto nuevo
|
|
105
|
+
if (isMultilinePrompt) {
|
|
106
|
+
readline.moveCursor(process.stdout, 0, -1);
|
|
107
|
+
readline.clearLine(process.stdout, 0);
|
|
108
|
+
readline.moveCursor(process.stdout, 0, 1);
|
|
109
|
+
isMultilinePrompt = false;
|
|
110
|
+
}
|
|
104
111
|
readline.clearLine(process.stdout, 0);
|
|
105
112
|
readline.cursorTo(process.stdout, 0);
|
|
106
113
|
|
|
107
|
-
console.log(msg);
|
|
108
|
-
rl.
|
|
114
|
+
console.log(msg);
|
|
115
|
+
rl.setPrompt('> ');
|
|
116
|
+
rl.prompt(true);
|
|
109
117
|
});
|
|
110
118
|
|
|
111
119
|
// Cuando le damos ENTER
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdc-test/chat-io",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "./src/index.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"chat-io": "bin/cli.js"
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"start": "node src/server/index.js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@pdc-test/chat-io": "^1.0.
|
|
12
|
+
"@pdc-test/chat-io": "^1.0.2",
|
|
13
13
|
"crypto-js": "^4.2.0",
|
|
14
14
|
"ws": "^8.0.0"
|
|
15
15
|
}
|
package/src/server/index.js
CHANGED
|
@@ -183,8 +183,7 @@ wss.on("connection", (server) => {
|
|
|
183
183
|
server.send(introMsg);
|
|
184
184
|
broadcast(introMsg, server);
|
|
185
185
|
|
|
186
|
-
const asciiArt = `
|
|
187
|
-
_____ _ _ _ _ _ _ _
|
|
186
|
+
const asciiArt = `_____ _ _ _ _ _ _ _
|
|
188
187
|
|_ _(_) ___ _ __ __| (_) |_ __ _| | | |
|
|
189
188
|
| | | |/ _ \ '_ \ / _ | | __/ _ | | | |
|
|
190
189
|
| | | | __/ | | | (_ | | || (_ |_|_|_|
|