Skip to main content

Module theme

Module theme 

Source
Expand description

Centralized colour palette. Set once at startup from crate::config::UiConfig::theme; read by screens via active.

Themes are deliberately slot-based: each slot is a semantic intent (Pass / Warn / Fail / Header / etc.), not a literal colour. Components ask the active theme “what colour for Warn?” rather than hard-coding Color::Yellow — that’s what makes a mono variant possible without rewriting every component.

The migration is incremental: components flip from hard-coded Color literals to [active().pass] etc. as their commits land. The first migrated component (S1 Health) ships in the same commit as the theme module.

Structs§

Glyphs
Slot-based glyph set, sibling of Theme. Components ask theme::active().glyphs.pass for the “Pass” glyph rather than hardcoding "✓" — that’s what makes --ascii work without touching every screen.
Theme
Slot-based colour palette. New slots get added as components are migrated; never break a slot’s meaning between releases.

Functions§

active
Read the active theme. Returns the default palette if install was never called (e.g. in unit tests that don’t go through App::new).
advance_spinner
Bump the spinner counter — called from the central Tick handler so every screen sees the same frame at the same time.
classify_header_error
Classify a header-line error message into a render colour + a friendlier prefix. Bee returns HTTP 503: Node is syncing. This endpoint is unavailable. Try again later. for almost every endpoint during the first few minutes after startup; rendering that in red as a hard error gives a terrible first impression. We detect the syncing case and render it in warn colour with a one-sentence explanation.
from_name
Resolve a theme name to a Theme. Unknown names fall back to the default palette with a single tracing warning so the operator notices the typo without the binary refusing to start.
install
Set the active theme from the [ui] config section. Called once during crate::app::App::new. Re-calling silently no-ops; full runtime theme switching is a v0.6 feature.
install_with_overrides
Resolution rules for --ascii / --no-color / NO_COLOR, applied on top of the [ui] config section. CLI flags win over env, env wins over config — the operator who typed --ascii gets ASCII, and a NO_COLOR=1 runtime override on a coloured [ui].theme = "default" config still demotes to mono.
no_color_env
Detect whether the host terminal asked us to suppress colour. Honours the no-color.org convention — any non-empty NO_COLOR env var means “no colour”.
spinner_glyph
Current spinner glyph. Resolves against the active glyph set (Unicode or ASCII) so cold-start polish honours --ascii. Detection is by content equality against the canonical pass glyph ( vs OK) — pointer comparison is unreliable across builds because the compiler may or may not dedup the string literal.