tui: extract pub ColorMode/TokenStyles/tokens_for for testable colour tokens #80

Merged
sirius merged 3 commits from wt/t_49b7c2b1 into main 2026-09-15 21:51:16 +00:00
Owner

All tests green. Clippy clean under --locked --all-targets -- -D warnings.

Summary

Extracted the colour token set into a public, testable API on src/tui.rs — the first card of the visual-identity-v2 foundation (C2 in the wallet-redesign plan).

  • ColorMode enum made pub (was private), color_mode() fn made pub, added Debug derive.
  • New TokenStyles struct + pub fn tokens_for(mode: ColorMode) -> TokenStyles as the single source of truth for every style_* helper (text / dim / accent / alert / stale / border / highlight).
  • style_fg removed (dead code after refactor); all locked helper names/signatures/return-types unchanged — they now delegate to tokens_for(color_mode()).
  • No runtime behaviour change: tokens_for(color_mode()) produces the same Styles as the old inline match arms.
  • ASCII/NO_COLOR behaviour preserved: alert_line still prefixes ! in None mode; delivery_glyph still falls back to ok/queued/sending/failed.

Test evidence

  • cargo test --locked: 26/26 tui_spec, 6/6 tui_frames, 10/10 tui_chrome, 25 node + 9 wallet + 8 zeroize — 0 failures.
  • cargo clippy --locked --all-targets -- -D warnings: clean.
  • New tests in tests/tui_spec.rs:
    • rgb_tokens_resolve_to_palette_fg — exact RGB fg for every role (highlight also asserts bg + bold).
    • none_tokens_strip_colour_fg_and_alert_keeps_bold — None mode strips all fg/bg; accent=bold-only, highlight=bold+reversed.
    • ansi16_tokens_use_ansi_colours — White/DarkGray/Red/Yellow; highlight=reversed+bold, no colour.
    • tokens_for_is_deterministic_across_calls.
    • alert_line_prefixes_when_no_color — NO_COLOR -> alert_line prepends ! .
  • cargo test --locked --test tui_spec -- --nocapture dump_spec_frames still dumps AFTER main/help/share at 80x24 and 120x40.
  • cargo test --locked --test tui_spec ascii_switch_80x24_frame_is_pure_ascii still green under NO_COLOR.

16-colour disambiguation (card deliverable 4)

tokens_for(ColorMode::Ansi16) gives alert=Red != stale=Yellow (no collapse), and stale is never signalled by colour alone — roster rows append the stale/ s word, focus uses the > marker, delivery states carry their word (queued/sending/failed) beside the glyph. Under NO_COLOR (ColorMode::None) every role emits no fg and no bg — only modifiers — so NO_COLOR terminals see no fg/bg Style at all.

Files

  • src/tui.rs — ColorMode pub, color_mode pub, TokenStyles + tokens_for added, style_fg removed, style_* helpers refactored to delegate.
  • tests/tui_spec.rs — 5 new token-set tests; one pre-existing is_none()+unwrap() clippy lint fixed.

PR

  • #80 — head wt/t_49b7c2b1, base main.
  • Commits: 6ce97a0 (token extraction) -> d4b0071 (clippy unnecessary_unwrap fix).
All tests green. Clippy clean under `--locked --all-targets -- -D warnings`. ## Summary Extracted the colour token set into a public, testable API on `src/tui.rs` — the first card of the visual-identity-v2 foundation (C2 in the wallet-redesign plan). - `ColorMode` enum made `pub` (was private), `color_mode()` fn made `pub`, added `Debug` derive. - New `TokenStyles` struct + `pub fn tokens_for(mode: ColorMode) -> TokenStyles` as the single source of truth for every `style_*` helper (text / dim / accent / alert / stale / border / highlight). - `style_fg` removed (dead code after refactor); all locked helper names/signatures/return-types unchanged — they now delegate to `tokens_for(color_mode())`. - No runtime behaviour change: `tokens_for(color_mode())` produces the same Styles as the old inline match arms. - ASCII/NO_COLOR behaviour preserved: `alert_line` still prefixes `! ` in None mode; `delivery_glyph` still falls back to `ok`/`queued`/`sending`/`failed`. ## Test evidence - `cargo test --locked`: 26/26 tui_spec, 6/6 tui_frames, 10/10 tui_chrome, 25 node + 9 wallet + 8 zeroize — **0 failures**. - `cargo clippy --locked --all-targets -- -D warnings`: clean. - New tests in `tests/tui_spec.rs`: - `rgb_tokens_resolve_to_palette_fg` — exact RGB fg for every role (highlight also asserts bg + bold). - `none_tokens_strip_colour_fg_and_alert_keeps_bold` — None mode strips all fg/bg; accent=bold-only, highlight=bold+reversed. - `ansi16_tokens_use_ansi_colours` — White/DarkGray/Red/Yellow; highlight=reversed+bold, no colour. - `tokens_for_is_deterministic_across_calls`. - `alert_line_prefixes_when_no_color` — NO_COLOR -> `alert_line` prepends `! `. - `cargo test --locked --test tui_spec -- --nocapture dump_spec_frames` still dumps AFTER main/help/share at 80x24 and 120x40. - `cargo test --locked --test tui_spec ascii_switch_80x24_frame_is_pure_ascii` still green under `NO_COLOR`. ## 16-colour disambiguation (card deliverable 4) `tokens_for(ColorMode::Ansi16)` gives alert=`Red` != stale=`Yellow` (no collapse), and stale is never signalled by colour alone — roster rows append the `stale`/` s` word, focus uses the `> ` marker, delivery states carry their word (`queued`/`sending`/`failed`) beside the glyph. Under `NO_COLOR` (`ColorMode::None`) every role emits **no fg and no bg** — only modifiers — so `NO_COLOR` terminals see no fg/bg `Style` at all. ## Files - `src/tui.rs` — `ColorMode` pub, `color_mode` pub, `TokenStyles` + `tokens_for` added, `style_fg` removed, `style_*` helpers refactored to delegate. - `tests/tui_spec.rs` — 5 new token-set tests; one pre-existing `is_none()+unwrap()` clippy lint fixed. ## PR - https://forgejo.siriusdevops.com/sirius/onionwire/pulls/80 — head `wt/t_49b7c2b1`, base `main`. - Commits: `6ce97a0` (token extraction) -> `d4b0071` (clippy unnecessary_unwrap fix).
tui: extract pub ColorMode/TokenStyles/tokens_for for testable colour tokens
Some checks failed
ci / test (pull_request) Failing after 4m22s
ci / sdk (pull_request) Successful in 1m16s
android-ci / android (pull_request) Successful in 8m16s
6ce97a0e3c
Make ColorMode a pub enum with pub color_mode() fn, add TokenStyles
struct and tokens_for(mode) as the single source of truth for the
style_* helpers. Tests assert RGB/None/Ansi16 fg/bg/modifier resolution
without depending on process environment.
tui: fix clippy unnecessary_unwrap in NO_COLOR cleanup
All checks were successful
ci / test (pull_request) Successful in 3m58s
ci / sdk (pull_request) Successful in 56s
android-ci / android (pull_request) Successful in 8m16s
d4b0071d1a
The alert_line_prefixes_when_no_color test stashed the prior NO_COLOR
value and restored it with is_none() + unwrap() — a clippy lint failure
under -D warnings. Replace with a match that takes ownership.

No behavior change; the restored env var is identical.

Co-authored-by: openhands <[email protected]>
Merge branch 'main' into wt/t_49b7c2b1
Some checks failed
ci / sdk (pull_request) Successful in 1m8s
android-ci / android (pull_request) Has been cancelled
ci / test (pull_request) Successful in 4m3s
3a17a564d3
sirius merged commit 3eee27fd09 into main 2026-09-15 21:51:16 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/onionwire!80
No description provided.