A terminal user interface (TUI) for macOS Surge proxy management.
- ✅ Terminal-Friendly - Pure text interface with SSH remote support
- ✅ Multi-Language Support - Compile-time language selection (Chinese/English), zero runtime overhead
- ✅ Clean Architecture - Clear layered architecture
- ✅ Fallback Strategy - HTTP API → CLI → System three-layer fallback
- ✅ Alert Mechanism - User-controlled error handling (no automatic config modification)
- ✅ Real-Time Monitoring - Policy, requests, connections, and DNS status
- ✅ Search Functionality - Independent search for policy groups/requests/connections
- ✅ Grouping Mode - Group requests/connections by application name
- ✅ Connection Management - Terminate individual connections with confirmation dialogs
- ✅ DNS Management - DNS cache view and one-click flush
- ✅ Help System - Built-in help popup with keyboard shortcuts
surge-tui/
├── src/
│ ├── domain/ # Core business logic (zero dependencies)
│ │ ├── models.rs # Data models
│ │ ├── entities.rs # Business entities
│ │ └── errors.rs # Error definitions
│ ├── infrastructure/ # Infrastructure implementations
│ │ ├── http_client.rs # HTTP API client
│ │ ├── cli_client.rs # surge-cli client
│ │ └── system_client.rs # System command client
│ ├── application/ # Business coordination layer
│ │ └── surge_client.rs # Unified interface
│ ├── ui/ # User interface
│ │ ├── app.rs # Main application state
│ │ └── components/ # UI components
│ └── config/ # Configuration management
└── docs/ # Design documents
# English version (default)
brew tap keyp-dev/tap
brew install surge-tui
# Chinese version
brew install surge-tui-zh# English version
nix profile install github:keyp-dev/surge-cli
# Chinese version
nix profile install github:keyp-dev/surge-cli#surge-tui-zh# English version (default)
cargo build --release
cargo install --path .
# Chinese version
cargo build --release --no-default-features --features lang-zh-cn
cargo install --path . --no-default-features --features lang-zh-cnSupported languages:
- 🇺🇸 American English (
lang-en-us) - Default - 🇨🇳 Simplified Chinese (
lang-zh-cn)
Ensure Surge is installed and running on macOS, and enable HTTP API in the configuration file:
[General]
http-api = your-secret-key@127.0.0.1:6171
http-api-tls = falseCreate a configuration file surge-tui.toml:
[surge]
http_api_host = "127.0.0.1"
http_api_port = 6171
http_api_key = "your-secret-key" # Match the API Key in Surge config
[ui]
refresh_interval = 1
max_requests = 100Or configure via environment variables:
export SURGE_HTTP_API_KEY="your-secret-key"# Run locally
surge-tui
# Run remotely via SSH
ssh user@mac-host surge-tui- ✅ Non-Blocking Latency Testing - Press
Tto test all policies while keeping UI responsive - ✅ Nested Policy Group Support - Recursively display final policy latency in policy group chains
- ✅ Smart Notification System - Real-time status bar notifications + history view (
Nkey) - ✅ Search Functionality - Press
/to search policy groups/requests/connections with real-time filtering - ✅ Grouping Mode - Press
Gto toggle request/connection grouping by application name - ✅ Help System - Press
Hto open help popup showing all keyboard shortcuts - ✅ Connection Management - Press
Kto terminate selected connection with confirmation dialog - ✅ DNS Management - View DNS cache in 5th view, press
Fto flush all cache - ✅ Feature Toggles - Keyboard shortcuts to toggle outbound mode(
M), MITM(I), traffic capture(C) - ✅ Enhanced Request Details - Notes syntax highlighting, HTTP Body markers
- ✅ Developer Tools - Press
`to open DevTools for debug logs - ✅ Latency Color Coding - Cyan(<100ms) / Yellow(100-300ms) / Red(>300ms)
- ✅ Test Result Caching - Preserve latency data after refresh or view switching
| Key | Function | Description |
|---|---|---|
q |
Quit | Exit program |
r |
Refresh | Manually refresh snapshot / reload config (when Alert prompts) |
1-5 |
Switch View | Overview/Policies/Requests/Connections/DNS |
↑/↓ |
Navigate | Move up/down in lists |
Enter |
Enter/Confirm | Enter policy group or switch policy |
Esc |
Back/Close | Exit policy group or close popup |
h / H |
Help | Open help popup showing all keyboard shortcuts |
/ |
Search | Search policy groups/requests/connections |
g / G |
Group Mode | Group requests/connections by application name |
t / T |
Test Latency | Non-blocking test all policy latencies |
m / M |
Toggle Mode | Cycle through Direct/Proxy/Rule |
i / I |
Toggle MITM | Toggle MITM status in Overview view |
c / C |
Toggle Capture | Toggle traffic capture in Overview view |
k / K |
Kill Connection | Terminate selected connection in Connections view (with confirmation) |
f / F |
Flush Cache | Flush DNS cache in DNS view |
n / N |
Notification History | View complete notification history (50 items) |
` |
DevTools | Open developer debug tools |
s / S |
Start Surge | Only available when Alert prompts |
Keyboard shortcuts are displayed directly in the bottom status bar (similar to btop).
- Surge running status, HTTP API availability
- Current outbound mode (
Mkey for quick toggle) - MITM status (
Ikey for quick toggle) - Traffic capture status (
Ckey for quick toggle) - System statistics
- Left: Policy group list with currently selected policy
- Right: Policy details and latency (supports nested policy groups)
- Search:
/key to search policy groups - Test:
Tkey to test all policy latencies
- Recent request records (URL, policy, traffic stats)
- Search:
/key to search requests - Group:
Gkey to group by application name - Details: Notes highlighting, HTTP Body markers
- Current active network connections
- Search:
/key to search connections - Group:
Gkey to group by application name - Manage:
Kkey to terminate selected connection (with confirmation)
- DNS cache records (domain, IP, TTL)
- Search:
/key to search domains - Flush:
Fkey to flush all DNS cache
surge-tui implements a three-layer fallback mechanism to ensure it works in various situations:
- HTTP API (Priority) - Most complete features, best performance
- surge-cli (Fallback) - Automatically switches when HTTP API is unavailable
- System Commands (Last Resort) - Check process status, start Surge
Does not automatically modify configuration, but prompts users through Alerts:
- Surge Not Running → Shows "Press S to start Surge"
- HTTP API Unavailable → Shows "Press R to reload config" (user must manually add http-api config first)
cargo check # Check code
cargo build # Debug build
cargo build --release # Release build- Single Responsibility - Each module responsible for one thing
- Dependency Inversion - Dependency flow: UI → Application → Infrastructure → Domain
- Open/Closed - Easy to extend without modifying existing code
- Zero Domain Dependencies - Domain layer has zero external dependencies
# Check Surge process
pgrep -x Surge
# Start Surge
open -a SurgeCheck Surge configuration file (usually in ~/.config/surge/ or Surge.app config directory):
[General]
http-api = your-secret-key@127.0.0.1:6171After adding, press R in surge-tui to reload configuration.
surge-cli is located inside Surge.app:
/Applications/Surge.app/Contents/Applications/surge-cliYou can manually specify the path in the configuration file.
- Rust - Systems programming language
- tokio - Async runtime
- ratatui - Terminal UI framework
- reqwest - HTTP client
- serde - Serialization/deserialization
MIT
Detailed documentation in the docs/ directory:
- FEATURES.md - Detailed description of implemented features (recommended reading)
- requirements.md - Detailed requirements documentation
- research.md - Surge CLI/HTTP API technical research
Generated with Claude Code via Happy
Co-Authored-By: Claude noreply@anthropic.com