Skip to content

AprilYoLies/termchat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Termchat

A lightweight terminal-based chat application with two modes: P2P (peer-to-peer) and Server/Client (multi-user).


Features

  • Terminal UI with blessed library — clean split-screen layout
  • Auto-wrap for long messages in both chat and input areas
  • Chinese support with optional pinyin conversion (--pinyin)
  • 3-line input area — no more truncated typing
  • Cross-platform — Linux, macOS, Windows

Installation

Online

pip install blessed
# For pinyin conversion (optional)
pip install pypinyin

Offline

Download wheels on a machine with internet:

pip download blessed pypinyin -d ./packages

Copy ./packages to the offline machine:

pip install --no-index --find-links=./packages blessed pypinyin

Mode 1: P2P (termchat.py)

Direct peer-to-peer connection. No server needed.

Usage

Host A (IP: 192.168.1.10):

python termchat.py -p 5000 --connect 192.168.1.20:5000

Host B (IP: 192.168.1.20):

python termchat.py -p 5000 --connect 192.168.1.10:5000

Options

Option Description
-p, --port Local listen port (default: 5000)
--connect Peer address in host:port format
--pinyin Convert Chinese input to pinyin before sending

Shortcuts

Key Action
Ctrl+L Clear screen
Enter Send message
Backspace Delete character
Ctrl+C / Ctrl+D / Esc Exit
/quit Graceful quit

Mode 2: Server/Client (termchat_server.py + termchat_client.py)

Multi-user chat room. One server, multiple clients.

Start Server

python termchat_server.py -p 5000

Server shows online user count and supports direct broadcast messages.

Connect Clients

# Basic connection
python termchat_client.py -s 192.168.1.5 -p 5000

# With custom username
python termchat_client.py -s 192.168.1.5 -p 5000 -n alice

# With pinyin conversion
python termchat_client.py -s 192.168.1.5 -p 5000 -n bob --pinyin

Client Options

Option Description
-s, --server Server host (default: 127.0.0.1)
-p, --port Server port (default: 5000)
-n, --name Your username (default: auto-generated)
--pinyin Convert Chinese input to pinyin

In-Chat Commands (Client)

Command Description
/name <newname> Change your username
/quit Disconnect and exit

Pinyin Conversion

When --pinyin is enabled:

  • Input: 你好
  • Sent: ni hao
  • Local display: ni hao (in green as me)
  • Peer display: ni hao (in magenta)

Pure English text is sent as-is without conversion.


UI Layout

┌────────────────────────────────────────┐
│ Termchat | Port: 5000 | Connected to...│  ← Header
├────────────────────────────────────────┤
│ [14:05:01] Chat started                │
│ [14:05:10] alice: hello everyone       │  ← Message area
│ [14:05:15] me: ni hao                  │
│                                        │
├────────────────────────────────────────┤
│ Ctrl+L:Clear | /quit:Exit | Enter:Send │  ← Hint bar
│> type your message here                │  ← Input area (3 lines)
│  and it wraps automatically            │
│  when exceeding terminal width         │
└────────────────────────────────────────┘
  • Green = your own messages (me / send)
  • Magenta = peer messages (receive / other users)
  • Cyan = system notifications
  • Yellow = warnings
  • Red = errors

Files

File Mode Description
termchat.py P2P Direct peer-to-peer chat
termchat_server.py Server Multi-user chat server
termchat_client.py Client Connect to server

License

MIT

About

A lightweight terminal-based chat application with two modes: P2P (peer-to-peer) and Server/Client (multi-user).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages