A lightweight terminal-based chat application with two modes: P2P (peer-to-peer) and Server/Client (multi-user).
- 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
pip install blessed
# For pinyin conversion (optional)
pip install pypinyinDownload wheels on a machine with internet:
pip download blessed pypinyin -d ./packagesCopy ./packages to the offline machine:
pip install --no-index --find-links=./packages blessed pypinyinDirect peer-to-peer connection. No server needed.
Host A (IP: 192.168.1.10):
python termchat.py -p 5000 --connect 192.168.1.20:5000Host B (IP: 192.168.1.20):
python termchat.py -p 5000 --connect 192.168.1.10:5000| Option | Description |
|---|---|
-p, --port |
Local listen port (default: 5000) |
--connect |
Peer address in host:port format |
--pinyin |
Convert Chinese input to pinyin before sending |
| Key | Action |
|---|---|
Ctrl+L |
Clear screen |
Enter |
Send message |
Backspace |
Delete character |
Ctrl+C / Ctrl+D / Esc |
Exit |
/quit |
Graceful quit |
Multi-user chat room. One server, multiple clients.
python termchat_server.py -p 5000Server shows online user count and supports direct broadcast messages.
# 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| 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 |
| Command | Description |
|---|---|
/name <newname> |
Change your username |
/quit |
Disconnect and exit |
When --pinyin is enabled:
- Input:
你好 - Sent:
ni hao - Local display:
ni hao(in green asme) - Peer display:
ni hao(in magenta)
Pure English text is sent as-is without conversion.
┌────────────────────────────────────────┐
│ 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
| 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 |
MIT