# TuiSerial - Terminal Serial Port Debugger
A modern TUI serial port debugging tool built with Rust + Ratatui, featuring complete keyboard and mouse interaction.

## π¦ Installation
### Install from crates.io
```bash
cargo install tuiserial
```
Run:
```bash
tuiserial
```
### Build from Source
1. Clone the repository: `git clone https://github.com/yourusername/tuiserial.git`
2. Enter directory: `cd tuiserial`
3. Build: `cargo build --release`
4. Run: `cargo run --release`
### Use Pre-compiled Binaries
1. Download binary: [Download Link](https://github.com/yourusername/tuiserial/releases)
2. Extract the archive
3. Run: `./tuiserial`
## β¨ Features
### Core Features
- **Complete Serial Configuration**: Port selection, baud rate, data bits, parity, stop bits, flow control
- **Configuration Persistence**: Auto save/load config to `~/.config/tuiserial/config.json` πΎ
- **Config Lock Mechanism**: Auto-lock config after connection to prevent misoperations, unlock after disconnect π
- **Smart Status Display**: Real-time connection status and complete config info (8-N-1 format)
- **Internationalization Support**: English and Chinese, default English π
- **Menu Bar Navigation**: Standard menu bar (File/Settings/Help), supports keyboard and mouse
- **Dual Display Modes**: HEX and TEXT modes, real-time switching
- **Clean Message Format**: `[Time] β RX (Bytes) Data` - clear and intuitive
- **Bidirectional Data Transfer**: Support HEX/ASCII send modes
- **Flexible Append Options**: Choose to append `\n`, `\r`, `\r\n`, `\n\r` or none
- **Real-time Data Reception**: Efficient circular buffer, supports up to 10000 log lines
- **Auto/Manual Scroll**: Smart auto-tracking or manual browsing of historical data
- **Quick Operations**: Fast toggle between configs and display modes
### Interaction Features
- **Full Keyboard Control**: Vim-style shortcuts + standard navigation + F10 menu
- **Comprehensive Mouse Support**: Click, right-click, middle-click, scroll wheel, menu bar clicks
- **Real-time Statistics**: Tx/Rx byte count and connection status
- **Notification System**: Operation feedback and error alerts, multilingual support
### UI Optimizations
- **Status Panel Redesign**:
- Connection status: `β Connected` / `β Disconnected`
- Config status: `π Modifiable` / `π Locked`
- Complete config info: Port, Baud rate, Config format (8-N-1)
- **Message Log Optimization**:
- Clean title: `Message - HEX | 123 items [x toggle | c clear]`
- Unified format: `[Time] β RX (Bytes) Data`
- Smart hints: Show connection status and shortcuts when log is empty
- **Config Lock Indicator**: Display `[Locked]` marker when connected, border turns gray
- **Append Option Selector**: Independent right panel for quick line ending selection
- **Highlight Hints**: Focused field in yellow, selected items bold, locked fields in gray
## π¦ Project Structure
Modular architecture managed with Cargo Workspace:
```
tuiserial/
βββ Cargo.toml # Workspace configuration
βββ crates/
β βββ tuiserial-core/ # Core data models and state management
β βββ tuiserial-serial/ # Serial communication library (wraps serialport)
β βββ tuiserial-ui/ # UI rendering components (based on ratatui)
β βββ tuiserial-cli/ # Main binary package (published as "tuiserial")
βββ ARCHITECTURE.md # Detailed architecture documentation
βββ LOGIC_VALIDATION.md # Logic validation and test checklist
βββ QUICK_REFERENCE.md # Quick reference guide
βββ README.md # This document (English)
βββ README-CN.md # Chinese documentation
```
**Note**: The directory is named `tuiserial-cli` but the package is published as `tuiserial` on crates.io. Users should install with `cargo install tuiserial`.
## π Quick Start
### Compile
```bash
cd tuiserial
cargo build --release
```
### Run
```bash
./target/release/tuiserial
```
Or run directly:
```bash
cargo run --release --bin tuiserial
```
## β¨οΈ Keyboard Shortcuts
### Global Controls
| `F10` | Open/Close menu bar |
| `q` / `Esc` | Quit program (or close menu) |
| `Tab` | Switch focus to next field |
| `Shift+Tab` | Switch focus to previous field |
| `o` | Open/Close serial connection (locks config when connected) |
| `r` | Refresh serial port list |
### Menu Bar Navigation (F10 to activate)
| `β` / `β` | Switch menu items |
| `β` / `β` | Select in dropdown menu |
| `Enter` | Execute selected menu item |
| `Esc` | Close menu/return to parent |
### Config Panel Navigation (β οΈ Auto-locks after connection)
| `β` / `k` | List up/decrease value |
| `β` / `j` | List down/increase value |
| `β` / `h` | Decrease baud rate |
| `β` / `l` | Increase baud rate |
| `p` | Toggle parity (None β Even β Odd) |
| `f` | Toggle flow control (None β Hardware β Software) |
**Note**: After connecting to serial port, all config parameters are automatically locked and cannot be modified. You must disconnect first to adjust config.
### Log Area
| `x` | Toggle HEX/TEXT display mode |
| `c` | Clear log |
| `a` | Toggle auto-scroll |
| `PgUp` | Scroll up (10 lines) |
| `PgDn` | Scroll down (10 lines) |
| `Home` | Jump to log beginning |
| `End` | Jump to log end (and enable auto-scroll) |
### Send Area (when focused on input box)
| `Character keys` | Input characters |
| `Backspace` | Delete previous character |
| `Delete` | Delete next character |
| `β` / `β` | Move cursor |
| `Home` / `End` | Move cursor to start/end |
| `β` / `β` | Toggle HEX/ASCII mode |
| `n` | Cycle through append options |
| `Enter` | Send data |
| `Esc` | Clear input |
## π±οΈ Mouse Interaction
### Left Click
- **Menu Bar** β Open menu dropdown
- **Menu Item** β Execute corresponding function
- **Config Panel** β Switch focus and directly select list item
- **Log Area** β Switch focus to log area
- **Input Box** β Switch focus and position cursor
- **Append Options** β Directly select append mode
### Right Click
- **Log Area** β Quick toggle HEX/TEXT display mode
- **Input Box** β Quick toggle HEX/ASCII send mode
- **Append Options** β Cycle through append modes
- **Statistics Area** β Toggle auto-scroll
### Middle Click
- **Log Area** β Quick clear log
- **Input Box** β Quick clear input
### Scroll Wheel
- **Log Area** β Scroll log up/down (3 lines)
- **Config List** β Select up/down in list
- **Append Options** β Cycle through append modes
## π Data Format
### Receive Display Format
```
[14:32:45.123] β RX ( 5 B) 48 65 6C 6C 6F
[14:32:45.456] β RX ( 5 B) Hello
```
**Format Description**:
- Timestamp accurate to milliseconds
- `β RX` Receive direction (cyan bold)
- `βΊ TX` Transmit direction (green bold)
- Byte count right-aligned for easy viewing
### Send Modes
1. **ASCII Mode**: Enter text directly, e.g., `Hello`
2. **HEX Mode**: Enter hexadecimal, space-separated, e.g., `48 65 6C 6C 6F`
### Append Options
- **None**: Don't add any characters
- **\n**: Add line feed (LF, 0x0A)
- **\r**: Add carriage return (CR, 0x0D)
- **\r\n**: Add carriage return line feed (CRLF, 0x0D 0x0A)
- **\n\r**: Add line feed carriage return (LFCR, 0x0A 0x0D)
## π οΈ Tech Stack
- **Ratatui 0.29**: Modern Rust TUI framework
- **Crossterm 0.28**: Cross-platform terminal control
- **Serialport 4.3+**: Cross-platform serial port access
- **Tokio 1.40**: Async runtime
- **Chrono 0.4**: Timestamp handling
- **Color-eyre 0.6**: Error handling
## π Development Status
### β
Implemented
- β
Serial port config management (all common parameters)
- β
**Configuration persistence** (auto save/load config file)
- β
**Menu bar system** (File/Settings/Help, keyboard and mouse support)
- β
**Internationalization support** (English/Chinese toggle, zero runtime cost)
- β
**Config lock mechanism** (auto-lock after connection, prevent misoperations)
- β
**Smart status display** (connection status, config status, complete config info)
- β
Data reception display (HEX/TEXT modes)
- β
Data transmission (HEX/ASCII modes)
- β
Append options (\n, \r, \r\n, \n\r, none)
- β
Full keyboard control (including F10 menu shortcuts)
- β
Full mouse interaction (click, right-click, middle-click, scroll, menu bar)
- β
**Optimized message format** (clean and intuitive log display)
- β
Auto/manual scroll
- β
Real-time statistics and notification system
- β
Complete logic validation (see LOGIC_VALIDATION.md)
- β
Modular architecture (Workspace)
### π Planned
- π Command presets and quick send
- π Log export (TXT/CSV/JSON)
- π Search and filter functionality
- π Data analysis and charts
- π Protocol parser plugins
- π More language support (Japanese, Korean, etc.)
- π Multiple serial port monitoring
- π Macro recording and playback
## π Documentation
- [ARCHITECTURE.md](ARCHITECTURE.md) - Detailed architecture design document
- [LOGIC_VALIDATION.md](LOGIC_VALIDATION.md) - Logic validation and test checklist
- [QUICK_REFERENCE.md](QUICK_REFERENCE.md) - Quick reference guide
- [Cargo Workspace](https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html) - Cargo Workspace official documentation
## π Core Feature: Config Lock Mechanism
**Why do we need config locking?**
After establishing a serial connection, modifying parameters may cause:
- Communication interruption or data corruption
- Device abnormal response
- Debug information confusion
**Our Solution:**
1. β
**Auto-lock on connection** - After pressing `o` to connect, all config parameters are immediately locked
2. β
**Visual feedback** - Config panel shows `[Locked]` marker, border turns gray
3. β
**Operation interception** - Any modification attempt shows warning: "Config locked, please disconnect first"
4. β
**Unlock on disconnect** - Press `o` again to disconnect, config returns to modifiable state
5. β
**Status sync** - Status panel displays current config and lock status in real-time
**Actual Effect:**
```
When disconnected:
Status: β Disconnected
Config: π Modifiable
β Can freely adjust all parameters
When connected:
Status: β Connected
Config: π Locked
Port: /dev/ttyUSB0
Baud: 115200
Config: 8-N-1
β Parameters locked, cannot modify
After disconnect:
Status: β Disconnected
Config: π Modifiable
β Returns to modifiable state
```
## π€ Contributing
Issues and Pull Requests are welcome!
1. Fork this project
2. Create feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to branch (`git push origin feature/AmazingFeature`)
5. Open Pull Request
## π License
MIT License
## π¨βπ» Author
pengheng <m18511047688@163.com>
## π Internationalization
Currently supported:
- **English** (default)
- **δΈζ** (Chinese)
Switch language:
- Press `F10` to open menu
- Select `Settings` β `Toggle Language`
- Or click directly on menu bar
Technical implementation:
- Uses `phf` for compile-time static HashMap
- Zero runtime overhead, all translations embedded at compile time
- Fallback mechanism: returns key itself if translation not found
- Simple and direct, no complex framework dependencies
## πΎ Configuration File
Config auto-saves to:
- **Linux/macOS**: `~/.config/tuiserial/config.json`
- **Windows**: `%APPDATA%\tuiserial\config.json`
Config content:
```json
{
"port": "/dev/ttyUSB0",
"baud_rate": 115200,
"data_bits": 8,
"parity": "None",
"stop_bits": 1,
"flow_control": "None"
}
```
Operations:
- **Save Config**: Menu β File β Save Config
- **Load Config**: Menu β File β Load Config (auto-loads on startup)
- Uses default config if config file is corrupted, no crashes
---
**β If this project helps you, please give it a Star!**