@cs7player/chat 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 ADDED
@@ -0,0 +1,14 @@
1
+ # LAN Chat CLI
2
+
3
+ A simple terminal-based LAN chat application built with Node.js using WebSockets.
4
+
5
+ ## 📦 Installation
6
+
7
+ ```bash
8
+ npm install -g @cs7player/chat
9
+
10
+ 🚀 Usage
11
+
12
+ Start the chat server:
13
+
14
+ lan-chat
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cs7player/chat",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "to communicate in terminal",
5
5
  "keywords": [
6
6
  "chat"
@@ -1,9 +1,9 @@
1
+ import { startUI } from "../tui/welcome.js";
1
2
  import WebSocket, { WebSocketServer } from "ws";
2
- import { addMessage, chatState, removeUser, addUser } from "../state/chatState.js";
3
- import { addPeer, removePeer, hasPeer, getPeers } from "./peers.js";
4
3
  import { createAlertBox } from "../tui/alert.js";
5
4
  import { clearFocus, screenExit } from "../utils/screen.js";
6
- import { startUI } from "../tui/welcome.js";
5
+ import { addPeer, removePeer, hasPeer, getPeers } from "./peers.js";
6
+ import { addMessage, chatState, removeUser, addUser } from "../state/chatState.js";
7
7
 
8
8
  export const startWSServer = (username) => {
9
9
  try {
@@ -1,4 +1,4 @@
1
- import * as os from "node:os";
1
+ import * as os from "os";
2
2
  import { loadUsers } from "../tui/side-bar.js";
3
3
  import { renderMessage, renderContent } from "../tui/content.js";
4
4
  import { sendPrivateMessage } from "../network/websocket.js";
@@ -34,7 +34,10 @@ export function addMessage(user, msg) {
34
34
  chatState.messages[key] = [];
35
35
  }
36
36
  chatState.messages[key].push(msg);
37
- if (chatState.selectedUser.username == msg.from) {
37
+ if (chatState.selectedUser && chatState.selectedUser.username == msg.from) {
38
+ renderMessage(msg);
39
+ }
40
+ if (msg.from == "You") {
38
41
  renderMessage(msg);
39
42
  }
40
43
  }
@@ -69,11 +69,10 @@ const sendButton = blessed.button({
69
69
  /* -SEND MESSAGE HANDLER-*/
70
70
  const handleSend = () => {
71
71
  try {
72
- // inputBox.cancel();
73
72
  const text = inputBox.getValue().trim();
73
+ inputBox.clearValue();
74
74
  if (!text) {
75
75
  clearFocus();
76
- createAlertBox("NO Text is Entered!");
77
76
  return;
78
77
  }
79
78
  const user = chatState.selectedUser;
@@ -82,8 +81,8 @@ const handleSend = () => {
82
81
  createAlertBox("NO User is Selected!");
83
82
  return;
84
83
  }
85
- sendMessage(user, text);
86
84
  inputBox.clearValue();
85
+ sendMessage(user, text);
87
86
  } catch (err) {
88
87
  console.log(err)
89
88
  }
@@ -1,6 +1,6 @@
1
1
  import blessed from 'blessed';
2
2
  import { screen, screenRefresh, addFocusBtn, removeFocusBtn, screenExit } from './screen.js';
3
- import { color } from './contants.js';
3
+ import { color, tabsfocus } from './contants.js';
4
4
 
5
5
  const dialogBox = blessed.box({
6
6
  top: 'center',
@@ -73,6 +73,7 @@ noBtn.on('press', () => {
73
73
  dialogBox.hide();
74
74
  removeFocusBtn(5);
75
75
  removeFocusBtn(6);
76
+ tabsfocus.btnIndex = 0;
76
77
  screen.remove(dialogBox);
77
78
  disableModalMode();
78
79
  screenRefresh();
@@ -83,6 +84,7 @@ export function showDialogBox() {
83
84
  addFocusBtn({ id: 5, btn: okBtn })
84
85
  addFocusBtn({ id: 6, btn: noBtn })
85
86
  okBtn.focus();
87
+ tabsfocus.btnIndex = tabsfocus.btns.findIndex(b => b.id === 5);
86
88
  dialogBox.show();
87
89
  enableModalMode();
88
90
  dialogBox.focus();
@@ -56,6 +56,9 @@ screen.key(['tab'], () => {
56
56
  if (!tabsfocus.istoggle) return;
57
57
  if (!tabsfocus.btns.length) return;
58
58
  tabsfocus.btnIndex = (tabsfocus.btnIndex + 1) % tabsfocus.btns.length;
59
+ if (tabsfocus.btnIndex == 0 && tabsfocus.btns.length > 5) {
60
+ tabsfocus.btnIndex = tabsfocus.btns.findIndex(b => b.id === 5);
61
+ }
59
62
  focusButton(tabsfocus.btnIndex);
60
63
  });
61
64
 
package/Read.md DELETED
@@ -1 +0,0 @@
1
- if u find any issue send mail to s.chandrasekhar.h@gmail.com