TUI Mode (Interactive)
The default mode provides a beautiful terminal user interface for managing downloads.Starting TUI Mode
The TUI uses Bubble Tea for the interactive interface and Lipgloss for styling.
Features
Real-Time Visualization:- Live progress bars with chunk visualization
- Speed graphs (current and average)
- ETA calculations
- Active worker count
a- Add new downloadp- Pause/Resume selected downloadd- Delete selected downloadq- Quit (downloads continue in background)↑/↓- Navigate downloadstab- Switch between views
- Active - Currently downloading
- Completed - Finished downloads
- Queued - Pending downloads
- Settings - Configuration panel
Architecture
- User presses key → Bubble Tea
Update(msg) - TUI calls
GlobalService.Add(url, path, mirrors) - Service queues to
GlobalPool - Worker emits progress →
GlobalProgressCh - Service broadcasts → TUI receives via
p.Send(msg) - TUI re-renders with new data
TUI mode also starts an HTTP server in the background on port 1700. This allows the browser extension to send downloads even when using the interactive interface.
When to Use TUI Mode
Development
Quickly test downloads and see detailed progress visualization
Manual Management
Interactively pause, resume, and monitor multiple downloads
Local Machine
You’re sitting at the computer and want visual feedback
Learning
Explore Surge’s features and settings interactively
Server Mode (Headless)
Runs Surge as a background daemon without a user interface. Perfect for servers, Raspberry Pis, or automation.Starting Server Mode
Server mode binds to
0.0.0.0 (all interfaces) by default. This makes it accessible via localhost and your local network IP.Features
HTTP API:- REST endpoints for all operations
- Token-based authentication
- CORS enabled for browser extensions
- Download events printed to stdout
- Structured logs with download IDs
- No interactive interface overhead
- Runs in background (use
nohupor systemd) - Survives SSH disconnections
- Auto-resumes paused downloads on restart
Authentication
Server mode requires a bearer token for API access:- Linux:
~/.local/state/surge/token - macOS:
~/Library/Application Support/surge/token - Windows:
%LOCALAPPDATA%\surge\token
If you lose the token, delete the token file and restart Surge. A new token will be auto-generated.
Headless Output
CLI Commands (While Server Running)
Control the headless daemon from another terminal:Docker Deployment
Run Surge server in a Docker container:/downloads- Download destination/config- Surge configuration and state
When to Use Server Mode
Servers
Run on headless Linux servers without X11/GUI
Automation
Integrate with scripts, cron jobs, or orchestration tools
Remote Access
Access downloads from anywhere via HTTP API
Low Resources
Minimal memory/CPU usage without TUI rendering
Remote TUI Mode (Connect)
Connect a TUI to a remote Surge server. Provides the interactive interface while downloads run on a different machine.Connecting to Remote Server
Surge automatically uses
http:// for loopback/private IPs and https:// for public/hostname targets.Architecture
- Commands sent via HTTP POST instead of direct function calls
- Events streamed via Server-Sent Events (SSE) or polling
- Network latency affects responsiveness
- Uses
RemoteDownloadServicewrapper instead ofLocalDownloadService
Environment Variables
Avoid typing host/token repeatedly:When to Use Remote TUI
NAS/Home Server
Downloads run on NAS, control from laptop
Cloud VM
Manage downloads on AWS/GCP from local terminal
SSH Alternative
Use local TUI instead of SSH + screen/tmux
Multiple Clients
Multiple developers controlling shared download server
Mode Comparison
| Feature | TUI Mode | Server Mode | Remote TUI |
|---|---|---|---|
| Visual Interface | ✅ Yes | ❌ No | ✅ Yes |
| HTTP API | ✅ Yes (background) | ✅ Yes | ✅ Yes (client) |
| Headless | ❌ No | ✅ Yes | ❌ No |
| Remote Control | Via API | Via API/CLI | Native |
| Resource Usage | Medium | Low | Low (server) + Medium (client) |
| Auto-Resume | ✅ Yes | ✅ Yes | ✅ Yes |
| Browser Extension | ✅ Yes | ✅ Yes | ✅ Yes (server-side) |
| Event Streaming | In-process | Stdout | HTTP SSE/polling |
Can I switch between modes?
Can I switch between modes?
Yes! You can:
-
Start in TUI, quit, resume in Server:
-
Start in Server, connect with Remote TUI:
-
Use CLI commands with any mode:
GlobalPool and SQLite database.