hacker-lobby 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.
Files changed (3) hide show
  1. package/index.js +14 -2
  2. package/package.json +2 -2
  3. package/src/ui.js +6 -0
package/index.js CHANGED
@@ -89,6 +89,9 @@ function initChat() {
89
89
  addSystemMessage(`Stream disconnected: ${err.message}`);
90
90
  });
91
91
 
92
+ // Post join message to the server
93
+ sendMessage(getAlias(), 'joined the chat').catch(() => {});
94
+
92
95
  rl.on('line', (line) => {
93
96
  // Disable newline muting once readline has finished processing the line
94
97
  muteNewline = false;
@@ -119,6 +122,11 @@ function initChat() {
119
122
  }
120
123
  });
121
124
 
125
+ // Handle Ctrl+C gracefully
126
+ rl.on('SIGINT', () => {
127
+ cleanupAndExit();
128
+ });
129
+
122
130
  // Initial prompt display
123
131
  rl.prompt(true);
124
132
  }
@@ -143,7 +151,7 @@ function drawLayout() {
143
151
 
144
152
  // 2. Draw static divider line just above the input prompt
145
153
  moveCursor(rows - 1, 1);
146
- process.stdout.write(COLORS.GRAY + '─'.repeat(cols) + COLORS.RESET);
154
+ process.stdout.write(COLORS.GRAY + '-'.repeat(cols) + COLORS.RESET);
147
155
 
148
156
  // 3. Set the scrolling region for messages
149
157
  setScrollRegion(topMargin, bottomMargin);
@@ -207,10 +215,14 @@ function addSystemMessage(text) {
207
215
  moveCursor(rows, col);
208
216
  }
209
217
 
210
- function cleanupAndExit() {
218
+ async function cleanupAndExit() {
211
219
  if (abortController) {
212
220
  abortController.abort();
213
221
  }
222
+ try {
223
+ // Send leave notification to server before exiting
224
+ await sendMessage(getAlias(), 'left the chat');
225
+ } catch (_) {}
214
226
  resetScrollRegion();
215
227
  clearScreen();
216
228
  console.log(formatSystem('Goodbye!'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hacker-lobby",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Multiplayer terminal chat application",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -17,4 +17,4 @@
17
17
  "engines": {
18
18
  "node": ">=16.0.0"
19
19
  }
20
- }
20
+ }
package/src/ui.js CHANGED
@@ -54,6 +54,12 @@ ${COLORS.CYAN} ██╗ ██╗ █████╗ ██████╗█
54
54
  * @returns {string}
55
55
  */
56
56
  export function formatMessage(sender, text) {
57
+ if (text === 'joined the chat') {
58
+ return `${COLORS.GREEN}${COLORS.BOLD}[+]${COLORS.RESET} ${COLORS.CYAN}${COLORS.BOLD}${sender}${COLORS.RESET} ${COLORS.NEON_GREEN}joined the chat${COLORS.RESET}`;
59
+ }
60
+ if (text === 'left the chat') {
61
+ return `${COLORS.RED}${COLORS.BOLD}[-]${COLORS.RESET} ${COLORS.CYAN}${COLORS.BOLD}${sender}${COLORS.RESET} ${COLORS.RED}left the chat${COLORS.RESET}`;
62
+ }
57
63
  return `${COLORS.CYAN}${COLORS.BOLD}${sender}${COLORS.RESET}: ${text}`;
58
64
  }
59
65