How tsl0922/ttyd works
ttyd serves a command's interactive terminal through a browser: the server exposes HTTP and WebSocket endpoints, authenticates clients, starts a PTY process, and transports terminal input/output; the frontend renders the session with xterm. README capabilities include file transfer, Sixel, TLS, configurable commands, authentication, and client limits. Backend relationships are grounded in excerpts or the SOURCE INDEX; HTTP routing internals and several documented optional capabilities were not sampled, so uncertain links are omitted or marked unverified.
Main entry points: protocol.c WebSocket protocol · index.ts Xterm and transport · server.c CLI configuration · pty.c PTY runtime
Components 20
Server and HTTP
- CLI configuration
src/server.c - HTTP endpoints
src/http.c - Embedded UI
src/html.h - WebSocket protocol
src/protocol.c - Server state
src/server.h
PTY session
- Command process
src/protocol.c - PTY runtime
src/pty.c - Event loop
src/server.h
Browser terminal
- Web client app
html/src/components/app.tsx - Terminal view
html/src/components/terminal/index.tsx - Xterm and transport
html/src/components/terminal/xterm/index.ts
Terminal extensions
- Resize overlay
html/src/components/terminal/xterm/addons/overlay.ts - File transfer
html/src/components/terminal/xterm/addons/zmodem.ts - Transfer dialog
html/src/components/modal/index.tsx
Other components
- Operator
- Browser user
- Configured command
- Browser WebSocket
- TLS support
- ZMODEM / trzsz
Connections 23
- Operator → CLI configuration: configures
README.md - CLI configuration → Server state: sets options
src/server.c - Browser user → Web client app: opens terminal
README.md - Web client app → Terminal view: renders
html/src/components/app.tsx - Terminal view → Xterm and transport: opens and connects
html/src/components/terminal/index.tsx - Xterm and transport → Browser WebSocket: uses
- Browser WebSocket → WebSocket protocol: sends messages
- HTTP endpoints → Embedded UI: serves UI
src/http.c - HTTP endpoints → Server state: reads configuration
src/http.c - WebSocket protocol → Server state: checks options
src/protocol.c - WebSocket protocol → Command process: spawns
src/protocol.c - Command process → PTY runtime: starts via
src/protocol.c - Command process → Configured command: executes
README.md - PTY runtime → Event loop: uses
- PTY runtime → WebSocket protocol: reports output
src/protocol.c - WebSocket protocol → Xterm and transport: streams terminal data
- Xterm and transport → Resize overlay: uses
html/src/components/terminal/xterm/index.ts - Xterm and transport → File transfer: uses
html/src/components/terminal/xterm/index.ts - Terminal view → Transfer dialog: renders
html/src/components/terminal/index.tsx - File transfer → Transfer dialog: requests file selection
- File transfer → ZMODEM / trzsz: supports
README.md - Operator → TLS support: can enable
README.md - CLI configuration → TLS support: configures