cmd/flow/ flag parsing and process wiring
internal/
animate/ spring dynamics and easing for value animation
collector/ per-OS interface counters
sampler/ counter deltas -> rates
history/ ring buffers, today totals, persistence
ping/ latency measurement with timeouts
processes/ per-process socket enumeration
theme/ semantic tokens, 12 built-ins, custom TOML themes
render/ braille canvas, area fill, gradients, glyph fallbacks
sparkline/ velocity glyphs and compact braille graphs
format/ --format templates
ui/ Bubble Tea models and all rendering (incl. big digits)
ui composes render and theme. render knows nothing about Bubble Tea or
lipgloss, which is what makes it unit-testable and benchmarkable in isolation.
collector ──► sampler ──► Sample{DownBps, UpBps} ──► ui.Model
│
┌─────────────────────────────┼──────────────┐
▼ ▼ ▼
history.Ring (raw) rollingMax tracker
│ (scale) (peaks/today)
▼ │ │
render.Smooth ───────────────────► ▼ ▼
(display only) hero waveform stats row
Rates come from counter deltas over a sliding window, so a single dropped read
does not spike the graph. The sampler reports a failed read and retries on the
next sampling cadence; the UI keeps the last good frame visible and clears the
warning after the next successful sample. Display smoothing is applied at
render time only; peaks, today totals, and JSON output stay honest.
The hero view is drawn onto a braille canvas: each terminal cell holds 2x4
dots (U+2800 plus a dot mask). That gives 2x the horizontal and 4x the
vertical resolution of the character grid, which is why the waveform has a
smooth interpolated crest instead of a staircase.
DrawAreaFill walks each of the 2*W dot columns, interpolates the sample at
that position with a Catmull-Rom spline (clamped so it never overshoots below
the baseline), and fills from the baseline outward. ColorRows then assigns a
color per row band rather than per cell: per-cell coloring produced
vertical striping artifacts, while horizontal bands read as a smooth gradient.
The mirrored view renders two half-canvases sharing a centre axis — download fills upward from the axis, upload fills downward.
The peak-hold rule was removed after it rendered as visual noise on a filled waveform. Gridlines stay as a single faint midpoint rule, visible only where the wave has no fill. Braille color is per-cell (2x4 dots), so a rule can only be drawn through empty cells — meaning a reference line behind the data is either invisible or a row of stray dots. The rule therefore stays subtle by construction: one faint midpoint dotted line, never over data.
Hero numbers are a 5x5 bitmap font (one full block per "on" pixel, technique adapted from timr-tui). Two-pixel-thick strokes plus solid fills is what makes them legible at a glance; the earlier 3-row zigzag font blurred into itself at large sizes. Glyphs are tabular (5 columns + 1 column of spacing) so a changing value never shifts the layout, and the decimal point is a narrow 2-wide block on the baseline.
They use five vertically shaded steps from the active download or upload gradient. The same fixed bitmap geometry is retained, so color adds depth without shifting digits or changing the measured values.
Two rules keep the block visually stable:
- The five digit rows must be identical width. The arrow and unit
therefore live on the caption row below (
↓ KB/s · peak 4.5 MB/s), not on the baseline. Putting them on the baseline made the last row wider, so the block stopped being tabular and part of the number read as detached debris. - Trailing zeros are stripped.
4B/s must render as4, not4.00; otherwise a one-digit value silently costs four glyphs. - The pair is two equal columns. Each hero block gets half the content width minus the gap — a width derived from the layout, never measured from the content. Every row is centered inside its column and the pair is centered together. Rule of thumb for this UI: content changes, geometry doesn't.
A pure linear axis is wrong for real traffic: a 70 KB/s idle floor next to an
8 MB/s burst is a 120x range, and linear crushes everything below the peak
into an invisible sliver. The default auto mode applies a gentle compression
curve (v^0.65). S cycles to linear and sqrt for people who want them. Each
half scales independently by default so a small upload next to a large
download stays visible.
make check # gofmt, go vet, golangci-lint, go test
make test # go test ./...
make build # build ./bin/flow
go test -race ./...
go test ./internal/ui -run Golden -update-golden
go test -bench=. ./internal/renderInvariants of the render path are asserted in
internal/ui/render_audit_test.go (fill is a faithful 1:1 dot mapping,
gridlines never overwrite data, mirrored halves are symmetric) because each
past regression in this pipeline was visual rather than a crash.
Contracts enforced by tests and should not be broken:
TestFooterGoldenContractlocks the exact footer bytes of the home screen.TestGoldenHeroFramessnapshots the hero view at 60x20, 80x24, 100x30, and 140x40 from deterministic synthetic data.
ui.Model coordinates application state rather than owning each concern
directly. Three small state groups keep the value pipeline and the overlay
model legible in one place:
| group | holds |
|---|---|
rateState |
sampled values, spring animation, decaying scale ceiling, emphasis pulses, ping |
overlayState |
which modal is visible, its scroll/theme cursor, and the toast |
ifaceState |
the interface list, the selected index, and its name |
Model keeps presentation knobs (window, scale mode, glyph set, colour
capability) directly, since only the view reads them.
collector goroutine (sampler) owns OS counter access and sampling cadence
└── reads interface counters, emits Sample on a buffered channel
Bubble Tea loop (UI) owns all UI state, renders, handles keys
└── commands run on Bubble Tea's own goroutines and return messages
The sampler never blocks on a slow UI consumer. Counter read errors are sent through the same sample channel as transient status events, then sampling continues. Cancellation remains the only normal way to stop the sampler.
There is no shared mutable state: the sampler writes only to its own channel,
and the UI reads from it. Every UI mutation happens on the Bubble Tea loop, so
the go test -race suite runs without suppressions.
sampler.New takes a collector.Reader interface, so counter behaviour —
idle links, resets, uint64 wraparound — is tested against scripted readings
rather than a live interface.