Skip to the content.

Docs home · Overview · Architecture · Workflows

Deep Dive: Terminal UI

Overview

Crankfire has two Bubble Tea front ends. They render live runs with the same view:

Both render live runs with internal/tui/runview.Model, which is assembled from internal/tui/widgets.

For the user guide, see Terminal UI and Dashboard & Reporting.

Responsibilities

Architecture

graph TB
  MAIN["tui.Run"] --> ROOT["tui.Root - screen stack"]
  ROOT --> LIST["screens.List - sessions"]
  LIST --> EDIT["Edit / Import / Detail"]
  LIST --> RUN["screens.Run"]
  LIST --> HIST["screens.History"]
  LIST --> SETS["SetsList"]
  SETS --> SDET["SetsDetail"]
  SDET --> SRUN["SetRun"]
  SDET --> SHIST["SetsHistory - Compare / Diff"]
  RUN --> RV["runview.Model"]
  LD["cli/livedash.Driver"] --> RV
  RV --> W["widgets"]

Key Files

Implementation Details

Screen stack

Root holds a []tea.Model stack, starting with screens.NewList. Messages are handled as follows:

Screens and keys

Screen Keys
Sessions list j/k or arrows to move. enter details, n new, e edit, i import, r run, h history, s sets, d delete (asks to confirm), / filter, x clear filter, q/ctrl+c quit.
Filter bar / opens it. enter applies. esc cancels. Syntax: spaces mean AND, commas mean OR.
Detail esc back, r run, h history
Edit (form) Fields: Name, Target, Protocol, Total, Rate, Duration, Concurrency, Timeout. tab/down and shift+tab/up move between fields; tab/down on the last field switches to YAML mode. F2 toggles YAML mode. ctrl+s saves. esc cancels.
Edit (YAML) Edits the whole Session document; the ID cannot be changed. F2 returns to the form. ctrl+s saves.
Import Fields: Path, Name. enter imports through ImportSessionFromConfigFile.
Run q/esc/ctrl+c cancel the run. The screen pops itself as soon as the run is finalized, so the final dashboard is not left on screen.
History Columns: Started, Status, Total, P95ms, Errors. o opens report.html with open, xdg-open or start. esc back.
Sets list n new, enter details, t template picker, d delete (no confirmation), r refresh, / filter, q/esc quit the app
Sets detail e edit, R run, h history, esc/q back
Sets edit Name and Description in a form. y switches to YAML, f back to the form. ctrl+s saves. esc cancels.
Set run Shows stage and item progress. esc/q cancel, or open Compare once the run has finished.
Sets history space marks a run, enter compares, d diffs two marked runs, esc back
Template picker Lists templates/*.yaml (in Init, which currently never runs; see Known Issues). Parameter grid: tab moves, ctrl+n adds a row, ctrl+s creates the set.

Single-session run (screens/run.go)

  1. Init calls store.CreateRun, which writes run.json with status running.
  2. It then calls cli.BuildRunner(runCtx, sess.Config) and runs the runner in a goroutine.
  3. A 250 ms tick calls collector.Snapshot() and passes the latest DataPoint to runview. The goroutine reports that it has finished through a package-level finishPending map, which the tick drains.
  4. On completion, finalizeCmd writes result.json (the JSON report) and report.html into the run directory, calls FinalizeRun, and pops the screen.

No thresholds are evaluated. If the run had any errors, the error message is set, and FinalizeRun changes the status to failed.

runview

runview.New(Options{Title, Total, Header, RequestContext, LoadPattern}) takes the SLO marker from RequestContext.LatencySLOMs. It consumes SnapshotMsg{Snap, Endpoints, Stats, StatusBuckets, ProtocolMetrics, Elapsed} and tea.WindowSizeMsg. It renders these panels:

At 80 columns or wider, rows are laid out side by side. Narrower terminals stack them.

livedash

livedash.New(collector, Opts, cancel) wraps a runview.Model in a Driver and runs it in tea.NewProgram(WithAltScreen()) on a goroutine.

Stop restores the terminal before cli.Run prints the final report.

Dependencies

API/Interface

func tui.Run(opts tui.Options) error              // Options{DataDir}
func tui.NewRoot(s store.Store) Root
type screens.PushMsg struct{ Model tea.Model }
type screens.PopMsg struct{}
func runview.New(opts runview.Options) runview.Model
func livedash.New(c *metrics.Collector, opts livedash.Opts, shutdown func()) *Driver
func livedash.BuildSnapshot(c *metrics.Collector, elapsed time.Duration) runview.SnapshotMsg

Testing

Known Issues & Improvement Opportunities