tui: clean-look chrome redesign (one accent, honest tor phase, real frames)
All checks were successful
ci / test (pull_request) Successful in 5m42s
ci / sdk (pull_request) Successful in 1m29s
ci / fuzz (pull_request) Successful in 4m41s
android-ci / android (pull_request) Successful in 10m45s

Applies the bitchat-tui clean-look principles to the OnionWire main screen.

- Hierarchy: header, roster + one primary chat pane, one status line, one
  footer hint line. The header gives up the accent (the accent is reserved
  for focus), so it stops competing with the panes.
- Tor phase is a first-class state: Node::tor_state() -> TorPhase (glyph +
  word, header and footer) so connecting / ready / degraded / off are never
  colour-only and never implied. No new data field.
- Footer changes with the focused pane (pane_footer_hints) and the phase; the
  main footer drops the redundant onion (the header already prints it) and
  uses those cells for hints. status_footer keeps its signature and strings.
- Empty roster / empty chat / connecting / degraded / off are designed states
  with their own copy, not blank panes.
- draw_main_chrome + MainView: the real main render path is public and
  Node-free, so tests/tui_frames.rs dumps the actual chrome at 80x24, 120x40
  and 200x60 (12 tests, 5 states, real Message/OutboxEntry rows) instead of a
  reconstructed stand-in.
- Widths in cells everywhere touched: status_footer*, alert_line,
  main_header_line*, draw_text_overlay, roster_row_text. The roster spends its
  budget name-first, so a 22-cell pane reads `bob-the-sta…  stale` instead of
  `…  bbbbbbbb… stale`.
- draw_text_overlay is centered with a one-cell side margin and clears
  underneath; never full-bleed.

Also fixes a pre-existing race in tests/tui_spec.rs (the ellipsis-form
assertion did not tolerate ONIONWIRE_ASCII being set by a parallel test).

Co-Authored-By: Hermes <[email protected]>
This commit is contained in:
agent 2026-09-18 23:13:12 -04:00
commit eefa7e5cc6
No known key found for this signature in database
5 changed files with 1344 additions and 471 deletions

View file

@ -1,9 +1,11 @@
//! Main-screen chrome helpers: ASCII wordmark, compact fallback, help text.
use onionwire::hs::TorState;
use onionwire::qr;
use onionwire::tui::{
Pane, banner_for_width, compact_banner, draw_share, help_overlay_text, main_footer_hints,
onion_glyph, status_footer, wordmark_banner,
Pane, TorPhase, banner_for_width, compact_banner, draw_share, help_overlay_text,
main_footer_hints, onion_glyph, pane_footer_hints, status_footer, status_footer_compact,
status_footer_phased, tor_token, wordmark_banner,
};
#[test]
@ -212,6 +214,102 @@ fn restore_terminal_is_callable_without_panic() {
onionwire::tui::restore_terminal();
}
#[test]
fn tor_phase_projects_every_tor_state() {
assert_eq!(TorPhase::of(TorState::Bootstrapping), TorPhase::Connecting);
assert_eq!(TorPhase::of(TorState::Published), TorPhase::Ready);
assert_eq!(
TorPhase::of(TorState::DegradedReachable),
TorPhase::Degraded
);
assert_eq!(TorPhase::of(TorState::Stopped), TorPhase::Off);
// The phase-free token is still the bare word the chrome tests lock.
assert_eq!(tor_token(None), "TOR");
}
#[test]
fn footer_states_the_tor_phase_with_a_word_not_only_colour() {
let fp = "abcdef0123456789deadbeef";
let onion = "abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvwx.onion";
for (phase, word) in [
(TorPhase::Connecting, "connecting"),
(TorPhase::Ready, "ready"),
(TorPhase::Degraded, "degraded"),
(TorPhase::Off, "off"),
] {
assert!(!phase.glyph().is_empty(), "{phase:?} has no glyph");
for w in [80u16, 120, 200] {
let line = status_footer_phased(w, fp, onion, Some(phase), None, main_footer_hints());
assert!(
line.contains(word),
"{w} footer lacks phase word {word:?}: {line:?}"
);
assert!(line.contains("TOR"), "{w} footer lacks TOR: {line:?}");
assert!(line.contains("me:"), "{w} footer lacks me:: {line:?}");
assert!(
line.chars().count() <= w as usize,
"{w} footer wider than frame: {line:?}"
);
}
}
// A fail-closed note still wins over the hints, phase or not.
let crowded = status_footer_phased(
80,
fp,
onion,
Some(TorPhase::Off),
Some("send failed: peer onion down"),
main_footer_hints(),
);
assert!(crowded.contains("send failed"), "{crowded:?}");
assert!(crowded.contains("off"), "{crowded:?}");
assert!(crowded.contains("? help"), "{crowded:?}");
assert!(crowded.chars().count() <= 80, "{crowded:?}");
}
/// The main footer has its own variant: the header already prints the identity,
/// so the footer drops the onion and keeps `TOR` + `me:` + the hints.
#[test]
fn compact_footer_drops_the_onion_and_keeps_the_rest() {
let fp = "abcdef0123456789deadbeef";
let onion = "abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvwx.onion";
let full = status_footer_phased(80, fp, onion, Some(TorPhase::Ready), None, main_footer_hints());
let compact = status_footer_compact(80, fp, Some(TorPhase::Ready), None, main_footer_hints());
assert!(full.contains("onion:"), "{full:?}");
assert!(!compact.contains("onion:"), "{compact:?}");
assert!(compact.contains("TOR"), "{compact:?}");
assert!(compact.contains("me:"), "{compact:?}");
assert!(compact.contains("? help"), "{compact:?}");
assert!(compact.chars().count() <= 80, "{compact:?}");
// The cells the onion gave up go to the hints.
assert!(
compact.chars().count() > 0 && compact.contains("F9"),
"compact footer lost the menu key: {compact:?}"
);
}
#[test]
fn pane_footer_hints_keep_the_menu_and_help_on_every_pane() {
let fp = "abcdef0123456789deadbeef";
for pane in [Pane::Roster, Pane::Chat, Pane::Composer] {
let hints = pane_footer_hints(pane);
assert!(hints.contains("F9"), "{pane:?} lost the menu key: {hints:?}");
assert!(hints.contains("? help"), "{pane:?} lost ? help: {hints:?}");
for w in [80u16, 120, 200] {
let line = status_footer_compact(w, fp, Some(TorPhase::Ready), None, hints);
assert!(line.contains("F9"), "{pane:?} at {w} lost F9: {line:?}");
assert!(
line.contains("? help"),
"{pane:?} at {w} lost ? help: {line:?}"
);
assert!(line.chars().count() <= w as usize, "{pane:?} at {w}: {line:?}");
}
}
// The hints actually change with the pane — that is the point of the lever.
assert_ne!(pane_footer_hints(Pane::Roster), pane_footer_hints(Pane::Composer));
assert_ne!(pane_footer_hints(Pane::Chat), pane_footer_hints(Pane::Composer));
}
#[test]
fn share_screen_shows_invite_not_qr_at_80x24() {
use ratatui::Terminal;