refactor(cli): unify scalar presentation formatting #91

Merged
Lochnair merged 1 commits from refactor/cli-scalar-formatting into main 2026-08-15 02:49:51 +00:00
Lochnair commented 2026-08-14 18:11:56 +00:00 (Migrated from github.com)

Summary

  • Stream output (cmd/client/output.rs), the run summary (cmd/client/summary.rs), and the TUI (cmd/tui/ui.rs) each carried a private copy of the same scalar vocabulary, and the copies had drifted:
    • the TUI spelled microseconds us, the other two µs;
    • percentages guarded non-finite values in the TUI but not in the summary (a NaN% was reachable);
    • the absent-value placeholder "-" was spelled inline at a dozen sites;
    • one copy pre-rounded to whole nanoseconds, another did not.
  • New CLI-internal cmd::format module owns nanosecond scalars, percentages, ratios, counts, and the absent placeholder, with one documented unit-selection and rounding policy: ns whole below 1µs, µs/ms to one decimal, s to three, sign preserved by formatting the magnitude, non-finite rendered as -.
  • The frontends keep their own metric sets and layouts. The TUI's coarse wall-clock display is still its own policy — renamed format_span, documented as deliberately coarser (0s, one-decimal seconds, 1m30s) — but it now delegates everything below one second to the shared vocabulary instead of repeating it.

Behavior

  • Microseconds are now µs everywhere, including the TUI's stat rows and graph axis labels. This is the intended fix for the known discrepancy.
  • The summary no longer renders NaN% for a non-finite percentage, and non-finite nanosecond scalars render as - rather than NaN…; both were unreachable in normal runs and are now defined.
  • No other user-visible value, row, column, or layout changed. Verified by the existing output/summary/TUI tests, which pass unchanged apart from the us → µs spelling.

Scope

Explicitly not changed:

  • Which metrics each frontend displays, and in what layout — no rows or columns added, removed, or reordered.
  • The TUI graph-axis label policy (variable precision to fit a narrow axis) and the coarse span policy, both of which remain deliberately distinct from the scalar policy.
  • irtt-stats — no presentation formatting was moved into it.
  • No generic formatting framework, traits, or builders were introduced; the module holds exactly the vocabulary more than one frontend needs.

Verification

Run from the task worktree, all successful:

  • cargo fmt --all -- --check
  • cargo check --workspace --all-targets --all-features --locked
  • cargo test --workspace --all-targets --all-features --locked
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --all-features --no-deps --locked
  • cargo check -p irtt-cli --no-default-features --features client --all-targets --locked
  • cargo check -p irtt-cli --no-default-features --features tui --all-targets --locked
  • cargo check -p irtt-cli --no-default-features --features server --all-targets --locked
  • git diff --check
## Summary - Stream output (`cmd/client/output.rs`), the run summary (`cmd/client/summary.rs`), and the TUI (`cmd/tui/ui.rs`) each carried a private copy of the same scalar vocabulary, and the copies had drifted: - the TUI spelled microseconds `us`, the other two `µs`; - percentages guarded non-finite values in the TUI but not in the summary (a `NaN%` was reachable); - the absent-value placeholder `"-"` was spelled inline at a dozen sites; - one copy pre-rounded to whole nanoseconds, another did not. - New CLI-internal `cmd::format` module owns nanosecond scalars, percentages, ratios, counts, and the absent placeholder, with one documented unit-selection and rounding policy: `ns` whole below 1µs, `µs`/`ms` to one decimal, `s` to three, sign preserved by formatting the magnitude, non-finite rendered as `-`. - The frontends keep their own metric sets and layouts. The TUI's coarse wall-clock display is still its own policy — renamed `format_span`, documented as deliberately coarser (`0s`, one-decimal seconds, `1m30s`) — but it now delegates everything below one second to the shared vocabulary instead of repeating it. ## Behavior - Microseconds are now `µs` everywhere, including the TUI's stat rows and graph axis labels. This is the intended fix for the known discrepancy. - The summary no longer renders `NaN%` for a non-finite percentage, and non-finite nanosecond scalars render as `-` rather than `NaN…`; both were unreachable in normal runs and are now defined. - No other user-visible value, row, column, or layout changed. Verified by the existing output/summary/TUI tests, which pass unchanged apart from the `us` → `µs` spelling. ## Scope Explicitly not changed: - Which metrics each frontend displays, and in what layout — no rows or columns added, removed, or reordered. - The TUI graph-axis label policy (variable precision to fit a narrow axis) and the coarse span policy, both of which remain deliberately distinct from the scalar policy. - `irtt-stats` — no presentation formatting was moved into it. - No generic formatting framework, traits, or builders were introduced; the module holds exactly the vocabulary more than one frontend needs. ## Verification Run from the task worktree, all successful: - `cargo fmt --all -- --check` - `cargo check --workspace --all-targets --all-features --locked` - `cargo test --workspace --all-targets --all-features --locked` - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` - `RUSTDOCFLAGS="-D warnings" cargo doc --workspace --all-features --no-deps --locked` - `cargo check -p irtt-cli --no-default-features --features client --all-targets --locked` - `cargo check -p irtt-cli --no-default-features --features tui --all-targets --locked` - `cargo check -p irtt-cli --no-default-features --features server --all-targets --locked` - `git diff --check`
Sign in to join this conversation.