wiki

Architecture

A friendly tour of how T-Strip is put together. T-Strip is about 6,800 lines of Go with just a handful of external dependencies (creack/pty, BurntSushi/toml, golang.org/x/term).

πŸ“Έ Screenshot coming here: A diagram of client and server talking over a unix socket. 🎬 Video coming here: A visual walkthrough of the packages and how data flows.

Two shapes: attached and local

Attached (default): a thin client inside your terminal talks to a background server over a unix socket.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   unix socket, framed messages   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  T-Strip client    β”‚ <───────────────────────────────>β”‚ T-Strip server      β”‚
β”‚  relays keystrokes β”‚  MsgInput  ->   <- MsgOutput     β”‚ owns every PTY,     β”‚
β”‚  draws frames      β”‚  MsgResize ->   <- MsgSetup      β”‚ mux, and emulator   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   <- MsgEnded                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Local (tst local): one process does everything in your terminal. Nothing survives when the terminal closes.

Package map

Package What it does
cmd/tst Command-line entry: flags, new/attach/ls/kill/local/init
internal/session Persistent sessions: the unix-socket protocol, the daemon, the attaching client
internal/app β€œLocal” mode: a raw input loop around the mux
internal/config TOML loading, keymap compilation, action table, themes
internal/input Turns raw terminal bytes into named key/mouse chords
internal/screen Cell grid and diffing renderer (no tears mid-frame)
internal/vt Terminal emulator with scrollback (vendored vt10x fork)
internal/pane One PTY, one emulator, one reader goroutine
internal/mux The multiplexer β€” all user-visible behaviour
internal/stats /proc and /sys sampling plus custom command widgets
internal/clipboard OSC 52 packing plus native clipboard tool drivers
internal/width Display width of text (CJK / emoji take 2 cells)

The mux sub-packages, in a good reading order for new contributors:

mux.go β†’ layout.go β†’ actions.go β†’ keyboard.go β†’ mouse.go β†’ render.go β†’
bar.go β†’ help.go β†’ selection.go β†’ copymode.go β†’ scrollback.go β†’
wallpaper.go β†’ control.go

The main loop (mux)

Mux.Loop owns all mutable layout and selection state. It waits on:

A render frame is emitted only when something changed or an animation is still running. If nothing looks different, the tick costs almost nothing.

Thread safety in one sentence

Everything that changes layout or selection lives on the loop goroutine. The only mutex of note guards each pane’s VT state while the PTY reader parses chunks and the render briefly reads it. The session server hands state changes in through post, never by writing fields directly.

The wire protocol (client ↔ server)

Every frame is 1 byte type + uint32 BE length + payload (16 MiB payload limit):

Type Direction Meaning
H client β†’ server Hello: JSON {Cols, Rows}
I client β†’ server Raw terminal bytes
R client β†’ server Resize: JSON size
K client β†’ server Kill session
P / p both Info request / response (used by tst ls)
S server β†’ client Setup: escape sequences to paint and tear down
O server β†’ client Bytes to paint on screen
X server β†’ client β€œYou were detached” (payload = reason)
Q server β†’ client Session ended

Attach sequence: H β†’ S β†’ (input/output loop) β†’ X or Q. One client per session; a second attach displaces the first.

Terminal emulator (internal/vt)

A vendored fork of vt10x (MIT) β€” a Go port of suckless st’s state table β€” with glyph grids, attributes, cursor management, DEC private modes, and OSC/D scanners. On top:

Renderer (internal/screen)

A double-buffered cell grid. Each frame is composed into cur, diffed against prev, and only changed cells are written with absolute cursor positioning plus attribute runs. Frames are bounded by synchronized-update markers (CSI ? 2026 h/l) and blinking-cursor suppression, so no tearing appears mid-frame.

Extending T-Strip

Testing

make test   # go test ./...
make vet    # go vet ./...

Test coverage is thin today, focused on: key parsing (input), config normalisation, the session protocol round-trip, detach keeping panes alive, and the vt scrollback ring.

🎬 Video coming here: Adding a new action from start to finish.