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,55 +1,44 @@
//! Visual audit dumps of the current OnionWire TUI.
//!
//! This crate cannot construct `App` (private, needs `Node` / Arti). Public
//! draw path used where it exists (`draw_share`, chrome helpers, overlay copy).
//! Main / profile / confirm screens labeled RECONSTRUCTED copy the layout
//! constants and copy from `src/tui.rs` so a reviewer can see the shape.
//! The main screen is the **real** render path: `draw_main_chrome` takes a
//! `MainView` of plain data, so this test draws exactly what `App::draw_main`
//! draws (no stand-in layout constants, no stub widget). Screens that are still
//! private (`draw_paste`, `draw_rotate`, …) are labelled RECONSTRUCTED and copy
//! the layout constants and copy from `src/tui.rs`.
//!
//! Print frames:
//! cargo test --locked --test tui_frames -- --nocapture dump_audit_frames
//!
//! `chars().count()` width checks here match `tests/tui_chrome.rs` on purpose.
//! They are the known-wrong metric (see `chars_count_is_not_terminal_cells`).
//! Widths are asserted in terminal **cells** via `onionwire::tui::cell_width`
//! (`Span::width`), never `chars().count()`.
use onionwire::outbox::{OutboxEntry, OutboxStatus};
use onionwire::qr;
use onionwire::tui::{
backup_screen_text, banner_for_width, compact_banner, draw_share, fingerprint_mismatch_banner,
help_overlay_text, main_footer_hints, onion_glyph, quit_screen_text, restore_screen_text,
rotate_screen_text, status_footer, who_overlay_text, wipe_screen_text, wordmark_banner,
ProfileEditor, WipeKind,
ChatRowStyle, FriendRow, MainView, Pane, TorPhase, backup_screen_text, banner_for_width,
cell_width, chat_no_friends_lines, chat_with_delivery, compact_banner, draw_main_chrome,
draw_share, draw_text_overlay, fingerprint_mismatch_banner, help_overlay_text,
main_footer_hints, onion_glyph, quit_screen_text, restore_screen_text, rotate_screen_text,
status_footer, who_overlay_text, wipe_screen_text, wordmark_banner, ProfileEditor, WipeKind,
};
use onionwire::FriendProfile;
use ratatui::backend::TestBackend;
use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::widgets::{Block, Borders, Clear, List, ListItem, ListState, Paragraph, Wrap};
use onionwire::{FriendProfile, Message};
use ratatui::Frame;
use ratatui::Terminal;
use ratatui::backend::TestBackend;
use ratatui::buffer::Buffer;
use ratatui::layout::{Constraint, Layout};
use ratatui::widgets::{Block, Borders, Paragraph, Wrap};
const SIZES: [(u16, u16); 3] = [(80, 24), (120, 40), (200, 60)];
const FP: &str = "abcdef0123456789deadbeefcafebabe";
const ONION: &str = "abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvwx.onion";
const LONG_MSG: &str = "them: this is a very long chat line that should wrap inside the chat pane instead of running off the right edge of an 80-column terminal and colliding with the roster border";
struct FriendRow {
name: &'static str,
fp: &'static str,
last_ok: bool,
}
const LONG_BODY: &str = "this is a very long chat line that should wrap inside the chat pane instead of running off the right edge of an 80-column terminal and colliding with the roster border";
fn fp8(s: &str) -> String {
s.chars().take(8).collect()
}
struct MainStandin<'a> {
friends: &'a [FriendRow],
selected: usize,
chat_lines: &'a [&'a str],
composer: &'a str,
alert: Option<&'a str>,
status_note: Option<&'a str>,
}
fn dump_buffer(label: &str, w: u16, h: u16, buf: &ratatui::buffer::Buffer) {
fn dump_buffer(label: &str, w: u16, h: u16, buf: &Buffer) {
println!();
println!("===== {label} {w}x{h} =====");
for y in 0..h {
@ -57,10 +46,10 @@ fn dump_buffer(label: &str, w: u16, h: u16, buf: &ratatui::buffer::Buffer) {
for x in 0..w {
row.push_str(buf[(x, y)].symbol());
}
let cells = row.chars().count();
let cells = cell_width(&row);
assert!(
cells <= w as usize,
"{label} row {y} chars().count()={cells} > {w}: {row:?}"
"{label} row {y} width {cells} cells > {w}: {row:?}"
);
println!("{row}");
}
@ -73,158 +62,100 @@ fn draw_to(w: u16, h: u16, label: &str, render: impl FnOnce(&mut Frame)) {
dump_buffer(label, w, h, terminal.backend().buffer());
}
fn pane_block(title: &str) -> Block<'_> {
// Real `App::pane_block` only changes border/title color. TestBackend
// dumps are glyphs, so focused chat/composer look identical to unfocused.
Block::default().borders(Borders::ALL).title(title)
fn draw_frame(w: u16, h: u16, render: impl FnOnce(&mut Frame)) -> Buffer {
let backend = TestBackend::new(w, h);
let mut terminal = Terminal::new(backend).expect("terminal");
terminal.draw(render).expect("draw");
terminal.backend().buffer().clone()
}
/// Layout constants copied from `App::draw_main` (`src/tui.rs`).
impl MainStandin<'_> {
fn draw(self, f: &mut Frame) {
let friends = self.friends;
let selected = self.selected;
let chat_lines = self.chat_lines;
let composer = self.composer;
let alert = self.alert;
let status_note = self.status_note;
let area = f.area();
let banner = banner_for_width(area.width);
let banner_h = banner.lines().count() as u16;
let alert_h = u16::from(alert.is_some());
let cols = Layout::vertical([
Constraint::Length(banner_h),
Constraint::Length(alert_h),
Constraint::Min(3),
Constraint::Length(3),
Constraint::Length(1),
])
.split(area);
f.render_widget(Paragraph::new(banner), cols[0]);
if let Some(msg) = alert {
f.render_widget(Paragraph::new(msg), cols[1]);
fn screen_of(buf: &Buffer, w: u16, h: u16) -> String {
let mut screen = String::new();
for y in 0..h {
for x in 0..w {
screen.push_str(buf[(x, y)].symbol());
}
screen.push('\n');
}
screen
}
let panes =
Layout::horizontal([Constraint::Percentage(36), Constraint::Min(10)]).split(cols[2]);
// ---------------------------------------------------------------------------
// Real main-screen states
// ---------------------------------------------------------------------------
let stale_n = friends.iter().filter(|fr| !fr.last_ok).count();
let roster_title = if stale_n > 0 {
format!("roster {} {stale_n} stale", friends.len())
} else {
format!("roster {}", friends.len())
};
let items: Vec<ListItem> = friends
.iter()
.map(|friend| {
let mut line = format!("{} {}…", friend.name, fp8(friend.fp));
if !friend.last_ok {
line.push_str(" stale");
}
ListItem::new(line)
})
.collect();
let roster = List::new(items)
.highlight_symbol("> ")
.block(pane_block(&roster_title));
let mut roster_state = ListState::default();
if !friends.is_empty() {
roster_state.select(Some(selected));
}
f.render_stateful_widget(roster, panes[0], &mut roster_state);
fn friend_rows() -> Vec<FriendRow> {
vec![
FriendRow {
label: "alice".into(),
fingerprint: "aaaaaaaaaaaaaaaa".into(),
stale: false,
},
FriendRow {
label: "bob-the-stale-peer".into(),
fingerprint: "bbbbbbbbbbbbbbbb".into(),
stale: true,
},
]
}
let inner_h = panes[1].height.saturating_sub(2);
let nlines = chat_lines.len();
let overflow = nlines > inner_h as usize && inner_h > 0;
let chat_title = {
let mut t = match friends.get(selected) {
Some(fr) => format!("chat {}", fr.name),
None => "chat".to_string(),
};
if overflow {
let end = inner_h as usize;
t.push_str(&format!(" 1-{end}/{nlines}"));
}
t
};
f.render_widget(
Paragraph::new(chat_lines.join("\n"))
.wrap(Wrap { trim: false })
.block(pane_block(&chat_title)),
panes[1],
);
let cmd = if composer.is_empty() {
"/wipe /wipe-all /profile /who /pay /tip /file".to_string()
} else {
composer.to_string()
};
f.render_widget(Paragraph::new(cmd).block(pane_block("composer")), cols[3]);
let footer = status_footer(area.width, FP, ONION, status_note, main_footer_hints());
f.render_widget(Paragraph::new(footer), cols[4]);
fn out_msg(id: i64, body: &str) -> Message {
Message {
id,
dir: "out".into(),
plaintext: body.as_bytes().to_vec(),
}
}
/// Rect math copied from private `draw_text_overlay` (`src/tui.rs`).
fn draw_text_overlay_standin(f: &mut Frame, title: &str, text: &str) {
let area = f.area();
let lines = text.lines().count() as u16 + 2;
let text_w = text
.lines()
.map(|l| l.chars().count() as u16)
.max()
.unwrap_or(40)
.saturating_add(4);
let width = text_w.min(area.width.saturating_sub(2)).max(10);
let height = lines.min(area.height.saturating_sub(2)).max(3);
let popup = Rect {
x: area.x + (area.width.saturating_sub(width)) / 2,
y: area.y + (area.height.saturating_sub(height)) / 2,
width,
height,
};
f.render_widget(Clear, popup);
f.render_widget(
Paragraph::new(text).block(Block::default().borders(Borders::ALL).title(title)),
popup,
);
fn in_msg(id: i64, body: &str) -> Message {
Message {
id,
dir: "in".into(),
plaintext: body.as_bytes().to_vec(),
}
}
fn draw_overlay_screen(f: &mut Frame, title: &str, body: &str) {
f.render_widget(
Paragraph::new(body)
.wrap(Wrap { trim: false })
.block(Block::default().borders(Borders::ALL).title(title)),
f.area(),
);
fn queued_row(message_id: i64, body: &str, attempts: u32, next_in: i64, now: i64) -> OutboxEntry {
OutboxEntry {
id: 1,
friend_pk: vec![9u8; 32],
message_id,
body: body.as_bytes().to_vec(),
payload: None,
attempts,
next_attempt_at: now + next_in,
created_at: now,
status: OutboxStatus::Queued,
last_error: None,
}
}
fn sample_invite() -> String {
qr::encode(&[7u8; 32], ONION, &[1u8; 32]).expect("encode")
/// Transcript rows through the real helper: markers included.
fn chat_ok() -> Vec<String> {
let msgs = [out_msg(1, "ping"), in_msg(2, "pong"), in_msg(3, LONG_BODY)];
chat_with_delivery(&msgs, &[], 1000).0
}
fn empty_chat_lines() -> &'static [&'static str] {
&["no friends yet", "F3 paste an invite to add one"]
/// Transcript with one row still held by the outbox, so the footer carries the
/// reachability note instead of a bare `sent`.
fn chat_queued() -> (Vec<String>, String) {
let now = 1000;
let msgs = [out_msg(1, "ping"), in_msg(2, "pong"), out_msg(3, "are you there?")];
let pending = [queued_row(3, "are you there?", 1, 45, now)];
let (lines, summary) = chat_with_delivery(&msgs, &pending, now);
(lines, summary.note().unwrap_or_default())
}
fn empty_chat(phase: TorPhase) -> Vec<String> {
chat_no_friends_lines(Some(phase))
}
#[test]
fn dump_audit_frames() {
let invite = sample_invite();
let friends = [
FriendRow {
name: "alice",
fp: "aaaaaaaaaaaaaaaa",
last_ok: true,
},
FriendRow {
name: "bob-the-stale-peer",
fp: "bbbbbbbbbbbbbbbb",
last_ok: false,
},
];
let chat_ok: [&str; 3] = ["you: ping", "them: pong", LONG_MSG];
let invite = qr::encode(&[7u8; 32], ONION, &[1u8; 32]).expect("encode");
let friends = friend_rows();
let chat = chat_ok();
let (queued_chat, queued_note) = chat_queued();
let editor = ProfileEditor::new("lance", "tor messenger", "");
let profile_body = {
let labels = ["name", "bio", "xmr"];
@ -248,7 +179,6 @@ fn dump_audit_frames() {
updated_at: 0,
}),
);
let who_empty = who_overlay_text(FP, ONION, None);
println!("invite payload length (chars) = {}", invite.chars().count());
println!("wordmark:\n{}", wordmark_banner());
@ -260,7 +190,7 @@ fn dump_audit_frames() {
);
for (w, h) in SIZES {
draw_to(w, h, "chrome banner+footer", |f| {
draw_to(w, h, "chrome banner+footer (real helpers)", |f| {
let banner = banner_for_width(f.area().width);
let banner_h = banner.lines().count() as u16;
let chunks = Layout::vertical([
@ -274,100 +204,179 @@ fn dump_audit_frames() {
f.render_widget(Paragraph::new(footer), chunks[2]);
});
draw_to(w, h, "chrome long-onion + send-failed", |f| {
let banner = banner_for_width(f.area().width);
let banner_h = banner.lines().count() as u16;
let chunks = Layout::vertical([
Constraint::Length(banner_h),
Constraint::Min(3),
Constraint::Length(1),
])
.split(f.area());
f.render_widget(Paragraph::new(banner), chunks[0]);
let footer = status_footer(
f.area().width,
FP,
ONION,
Some("send failed: connection timed out"),
main_footer_hints(),
draw_to(w, h, "main: chat + stale roster, focus chat, tor ready", |f| {
draw_main_chrome(
f,
&MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(TorPhase::Ready),
friends: &friends,
selected: 0,
focus: Pane::Chat,
chat_lines: &chat,
chat_style: ChatRowStyle::Text,
chat_name: Some("alice"),
chat_scroll: 0,
composer: "",
alert: None,
note: None,
},
);
f.render_widget(Paragraph::new(footer), chunks[2]);
});
draw_to(w, h, "RECONSTRUCTED main empty", |f| {
MainStandin {
friends: &[],
selected: 0,
chat_lines: empty_chat_lines(),
composer: "",
alert: None,
status_note: None,
}
.draw(f);
draw_to(w, h, "main: focus roster, tor connecting", |f| {
draw_main_chrome(
f,
&MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(TorPhase::Connecting),
friends: &friends,
selected: 1,
focus: Pane::Roster,
chat_lines: &chat,
chat_style: ChatRowStyle::Text,
chat_name: Some("bob-the-stale-peer"),
chat_scroll: 0,
composer: "",
alert: None,
note: None,
},
);
});
draw_to(w, h, "RECONSTRUCTED main chat+stale", |f| {
MainStandin {
friends: &friends,
selected: 0,
chat_lines: &chat_ok,
composer: "hello from composer",
alert: Some("passphrases do not match"),
status_note: Some("sent"),
}
.draw(f);
draw_to(w, h, "main: focus composer, promoted identity", |f| {
draw_main_chrome(
f,
&MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(TorPhase::Degraded),
friends: &friends,
selected: 0,
focus: Pane::Composer,
chat_lines: &chat,
chat_style: ChatRowStyle::Text,
chat_name: Some("alice"),
chat_scroll: 0,
composer: "hello from composer",
alert: None,
note: None,
},
);
});
draw_to(w, h, "RECONSTRUCTED main pay/file footer only", |f| {
MainStandin {
friends: &friends,
selected: 0,
chat_lines: &["you: /pay 0.1 coffee", "them: (no invoice pane exists)"],
composer: "",
alert: None,
status_note: Some("invoice sent"),
}
.draw(f);
draw_to(w, h, "main: EMPTY roster, tor connecting", |f| {
draw_main_chrome(
f,
&MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(TorPhase::Connecting),
friends: &[],
selected: 0,
focus: Pane::Roster,
chat_lines: &empty_chat(TorPhase::Connecting),
chat_style: ChatRowStyle::State,
chat_name: None,
chat_scroll: 0,
composer: "",
alert: None,
note: None,
},
);
});
draw_to(w, h, "RECONSTRUCTED main file-send-failed", |f| {
MainStandin {
friends: &friends,
selected: 1,
chat_lines: &["no messages"],
composer: "",
alert: None,
status_note: Some("send failed: peer onion down"),
}
.draw(f);
draw_to(w, h, "main: EMPTY roster, tor off (disconnected)", |f| {
draw_main_chrome(
f,
&MainView {
me_fp: FP,
me_onion: "",
phase: Some(TorPhase::Off),
friends: &[],
selected: 0,
focus: Pane::Roster,
chat_lines: &empty_chat(TorPhase::Off),
chat_style: ChatRowStyle::State,
chat_name: None,
chat_scroll: 0,
composer: "",
alert: Some("fingerprint mismatch"),
note: None,
},
);
});
draw_to(w, h, "main: ERROR alert + fail-closed note", |f| {
draw_main_chrome(
f,
&MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(TorPhase::Degraded),
friends: &friends,
selected: 0,
focus: Pane::Composer,
chat_lines: &chat,
chat_style: ChatRowStyle::Text,
chat_name: Some("alice"),
chat_scroll: 0,
composer: "",
alert: Some("send failed: peer onion down"),
note: Some("send failed: peer onion down"),
},
);
});
draw_to(w, h, "main: outbox queued (peer unreachable)", |f| {
draw_main_chrome(
f,
&MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(TorPhase::Ready),
friends: &friends,
selected: 0,
focus: Pane::Roster,
chat_lines: &queued_chat,
chat_style: ChatRowStyle::Text,
chat_name: Some("alice"),
chat_scroll: 0,
composer: "",
alert: None,
note: Some(&queued_note),
},
);
});
draw_to(w, h, "draw_share (real)", |f| draw_share(f, &invite));
draw_to(w, h, "RECONSTRUCTED help overlay on empty main", |f| {
MainStandin {
friends: &[],
selected: 0,
chat_lines: empty_chat_lines(),
composer: "",
alert: None,
status_note: None,
}
.draw(f);
draw_text_overlay_standin(f, "? help", help_overlay_text());
draw_to(w, h, "main + ? help overlay (real draw_text_overlay)", |f| {
draw_main_chrome(
f,
&MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(TorPhase::Ready),
friends: &friends,
selected: 0,
focus: Pane::Chat,
chat_lines: &chat,
chat_style: ChatRowStyle::Text,
chat_name: Some("alice"),
chat_scroll: 0,
composer: "",
alert: None,
note: None,
},
);
draw_text_overlay(f, "? help", help_overlay_text());
});
draw_to(w, h, "RECONSTRUCTED /who overlay", |f| {
MainStandin {
friends: &friends,
selected: 0,
chat_lines: &chat_ok,
composer: "",
alert: None,
status_note: None,
}
.draw(f);
draw_text_overlay_standin(f, "/who", &who);
draw_to(w, h, "main + /who overlay (real draw_text_overlay)", |f| {
draw_text_overlay(f, "/who", &who);
});
draw_to(w, h, "RECONSTRUCTED profile", |f| {
@ -407,13 +416,6 @@ fn dump_audit_frames() {
&format!("{}\n\nWI", wipe_screen_text(WipeKind::Messages)),
);
});
draw_to(w, h, "RECONSTRUCTED wipe-all", |f| {
draw_overlay_screen(
f,
"(o) wipe all",
&format!("{}\n\n", wipe_screen_text(WipeKind::All)),
);
});
draw_to(w, h, "RECONSTRUCTED quit", |f| {
draw_overlay_screen(f, "(o) quit", &format!("{}\n\nQUI", quit_screen_text()));
});
@ -427,19 +429,243 @@ fn dump_audit_frames() {
draw_to(w, h, "RECONSTRUCTED restore", |f| {
draw_overlay_screen(f, "(o) restore", &format!("{}\n\n", restore_screen_text()));
});
draw_to(w, h, "RECONSTRUCTED passphrase", |f| {
draw_overlay_screen(
f,
"(o) passphrase",
"Enter passphrase\n\n****\n\nEnter submit Esc cancel",
);
});
draw_to(w, h, "who copy (no profile)", |f| {
draw_overlay_screen(f, "/who", &who_empty);
});
}
}
fn draw_overlay_screen(f: &mut Frame, title: &str, body: &str) {
f.render_widget(
Paragraph::new(body)
.wrap(Wrap { trim: false })
.block(Block::default().borders(Borders::ALL).title(title)),
f.area(),
);
}
/// Every real main-screen state must fit every supported size in cells.
#[test]
fn main_chrome_fits_80x24_120x40_and_200x60() {
let friends = friend_rows();
let chat = chat_ok();
let (queued_chat, queued_note) = chat_queued();
let empty_connecting = empty_chat(TorPhase::Connecting);
let states: Vec<(&str, MainView<'_>, Option<&str>)> = vec![ (
"chat+stale",
MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(TorPhase::Ready),
friends: &friends,
selected: 0,
focus: Pane::Chat,
chat_lines: &chat,
chat_style: ChatRowStyle::Text,
chat_name: Some("alice"),
chat_scroll: 0,
composer: "",
alert: None,
note: None,
},
None,
),
(
"empty+connecting",
MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(TorPhase::Connecting),
friends: &[],
selected: 0,
focus: Pane::Roster,
chat_lines: &empty_connecting,
chat_style: ChatRowStyle::State,
chat_name: None,
chat_scroll: 0,
composer: "",
alert: None,
note: None,
},
None,
),
(
"error+alert",
MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(TorPhase::Degraded),
friends: &friends,
selected: 0,
focus: Pane::Composer,
chat_lines: &chat,
chat_style: ChatRowStyle::Text,
chat_name: Some("alice"),
chat_scroll: 0,
composer: "",
alert: Some("send failed: peer onion down"),
note: Some("send failed: peer onion down"),
},
None,
),
(
"queued outbox",
MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(TorPhase::Ready),
friends: &friends,
selected: 0,
focus: Pane::Roster,
chat_lines: &queued_chat,
chat_style: ChatRowStyle::Text,
chat_name: Some("alice"),
chat_scroll: 0,
composer: "",
alert: None,
note: Some(&queued_note),
},
None,
),
];
for (name, view, _) in states {
for (w, h) in SIZES {
let buf = draw_frame(w, h, |f| draw_main_chrome(f, &view));
let screen = screen_of(&buf, w, h);
for (y, row) in screen.lines().enumerate() {
assert!(
cell_width(row) <= w as usize,
"{name} at {w}x{h}: row {y} is {} cells: {row:?}",
cell_width(row)
);
}
}
}
}
/// The frame dump must show the phase, and the phase must not be colour-only.
#[test]
fn main_frame_states_are_legible_without_colour() {
let friends = friend_rows();
let chat = chat_ok();
for (phase, word) in [
(TorPhase::Connecting, "connecting"),
(TorPhase::Ready, "ready"),
(TorPhase::Degraded, "degraded"),
(TorPhase::Off, "off"),
] {
let buf = draw_frame(80, 24, |f| {
draw_main_chrome(
f,
&MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(phase),
friends: &friends,
selected: 0,
focus: Pane::Chat,
chat_lines: &chat,
chat_style: ChatRowStyle::Text,
chat_name: Some("alice"),
chat_scroll: 0,
composer: "",
alert: None,
note: None,
},
)
});
let screen = screen_of(&buf, 80, 24);
let header = screen.lines().next().unwrap_or_default().to_string();
let footer = screen.lines().last().unwrap_or_default().to_string();
assert!(header.contains(word), "header lacks {word:?}: {header:?}");
assert!(footer.contains(word), "footer lacks {word:?}: {footer:?}");
assert!(header.contains("onionwire"), "{header:?}");
assert!(footer.contains("TOR"), "{footer:?}");
}
}
/// Focus must be visible with the colour stripped: a marker on the focused
/// pane, not just a coloured border.
#[test]
fn focus_is_a_marker_not_only_colour() {
let friends = friend_rows();
let chat = chat_ok();
let marker_of = |focus: Pane, w: u16| -> String {
let buf = draw_frame(w, 24, |f| {
draw_main_chrome(
f,
&MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(TorPhase::Ready),
friends: &friends,
selected: 0,
focus,
chat_lines: &chat,
chat_style: ChatRowStyle::Text,
chat_name: Some("alice"),
chat_scroll: 0,
composer: "",
alert: None,
note: None,
},
)
});
screen_of(&buf, w, 24)
};
for w in [80u16, 120] {
let roster_focus = marker_of(Pane::Roster, w);
let chat_focus = marker_of(Pane::Chat, w);
assert!(
roster_focus.contains("> alice"),
"roster focus has no row marker at {w}: {roster_focus}"
);
assert!(
chat_focus.contains("> chat"),
"chat focus has no title marker at {w}"
);
assert!(
!roster_focus.contains("> chat"),
"chat title keeps the focus marker while roster is focused"
);
assert_eq!(
roster_focus.lines().count(),
24,
"frame height changed with focus"
);
}
}
/// The empty roster is a state, not a blank box.
#[test]
fn empty_roster_and_empty_chat_are_designed_states() {
let buf = draw_frame(80, 24, |f| {
draw_main_chrome(
f,
&MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(TorPhase::Connecting),
friends: &[],
selected: 0,
focus: Pane::Roster,
chat_lines: &empty_chat(TorPhase::Connecting),
chat_style: ChatRowStyle::State,
chat_name: None,
chat_scroll: 0,
composer: "",
alert: None,
note: None,
},
)
});
let screen = screen_of(&buf, 80, 24);
assert!(screen.contains("no friends"), "{screen}");
assert!(screen.contains("F3 adds one"), "{screen}");
assert!(screen.contains("F3 paste an invite"), "{screen}");
assert!(
screen.contains("tor connecting"),
"connecting state is not on screen:\n{screen}"
);
}
#[test]
fn public_copy_fits_80_by_chars_count() {
for (name, text) in [
@ -518,7 +744,7 @@ fn status_footer_drops_send_failed_when_crowded() {
#[test]
fn share_invite_wraps_at_three_sizes() {
let invite = sample_invite();
let invite = qr::encode(&[7u8; 32], ONION, &[1u8; 32]).expect("encode");
for (w, h) in SIZES {
let backend = TestBackend::new(w, h);
let mut terminal = Terminal::new(backend).expect("terminal");
@ -536,6 +762,34 @@ fn share_invite_wraps_at_three_sizes() {
}
}
/// The help overlay is cleared underneath and never wider than the frame.
#[test]
fn help_overlay_keeps_a_margin_and_shows_the_tail() {
for (w, h) in SIZES {
let buf = draw_frame(w, h, |f| {
f.render_widget(Paragraph::new("underlying frame junk"), f.area());
draw_text_overlay(f, "? help", help_overlay_text());
});
let screen = screen_of(&buf, w, h);
assert!(
!screen.contains("underlying frame junk"),
"{w}x{h} overlay punched through:\n{screen}"
);
assert!(
screen.contains("Esc closes this overlay"),
"{w}x{h} help tail clipped"
);
// A one-cell margin on each side: no border glyph in column 0.
for line in screen.lines() {
let first = line.chars().next().unwrap_or(' ');
assert!(
first != '┌' && first != '│',
"{w}x{h} overlay is full-bleed: {line:?}"
);
}
}
}
/// Documented defect in `tests/tui_chrome.rs`: `chars().count()` is not cells.
/// Do not add `unicode-width` on this card.
#[test]
@ -553,3 +807,34 @@ fn chars_count_is_not_terminal_cells() {
let ellipsis = "…";
assert_eq!(ellipsis.chars().count(), 1);
}
/// Sanity: the real main renderer is the one under test here.
#[test]
fn main_chrome_draws_the_same_frame_as_the_app_layout() {
let friends = friend_rows();
let chat = chat_ok();
let buf = draw_frame(80, 24, |f| {
draw_main_chrome(
f,
&MainView {
me_fp: FP,
me_onion: ONION,
phase: Some(TorPhase::Ready),
friends: &friends,
selected: 0,
focus: Pane::Chat,
chat_lines: &chat,
chat_style: ChatRowStyle::Text,
chat_name: Some("alice"),
chat_scroll: 0,
composer: "",
alert: None,
note: None,
},
)
});
let screen = screen_of(&buf, 80, 24);
assert!(screen.contains("roster 2 1 stale"), "{screen}");
assert!(screen.contains("> chat alice"), "{screen}");
assert!(screen.contains("message"), "composer placeholder: {screen}");
}