tui: drop the F9 menu that restates F6 and F7
All checks were successful
ci / test (pull_request) Successful in 7m40s
ci / sdk (pull_request) Successful in 1m42s

The Wallets & Settings screen only named keys that already work. F6 is the
wallet, F7 is the node, and p on the roster or chat opens peer payments.
Profile, backup and wipe stay composer commands, named in help.
This commit is contained in:
agent 2026-10-08 11:03:28 -04:00
commit 4e13242a44
No known key found for this signature in database
5 changed files with 391 additions and 1147 deletions

View file

@ -49,8 +49,9 @@ fn help_overlay_lists_core_bindings() {
"F4",
"F5",
"F6",
"F7",
"F8",
"F9",
"p",
"send chat",
"/profile",
"/pay",
@ -61,7 +62,6 @@ fn help_overlay_lists_core_bindings() {
"/backup",
"/restore",
"/wipe-all",
"/settings",
"Ctrl-Q",
"?",
] {
@ -182,29 +182,36 @@ fn pane_focus_cycles_roster_chat_composer() {
}
#[test]
fn menu_key_is_listed_in_help_and_in_the_main_footer() {
// Discoverability: the WALLETS & SETTINGS menu has to be findable from the
// help overlay *and* from the main footer, or F9 is a secret.
fn wallet_and_node_keys_are_listed_and_the_menu_key_is_not() {
// F6 is the wallet and F7 is the node. There is no second menu, so F9 and
// `/settings` must not be printed — a key that no longer exists is worse
// than a missing one.
let help = help_overlay_text();
assert!(help.contains("F9"), "F9 missing from help:\n{help}");
assert!(help.contains("F6"), "F6 missing from help:\n{help}");
assert!(help.contains("F7"), "F7 missing from help:\n{help}");
assert!(
help.contains("/settings"),
"/settings missing from help:\n{help}"
!help.contains("F9"),
"F9 is still a printed key:\n{help}"
);
assert!(
!help.contains("/settings"),
"/settings is still a printed command:\n{help}"
);
let hints = main_footer_hints();
assert!(
hints.contains("F9"),
"F9 missing from footer hints: {hints:?}"
);
assert!(hints.contains("F6"), "F6 missing from footer hints: {hints:?}");
assert!(hints.contains("F7"), "F7 missing from footer hints: {hints:?}");
assert!(!hints.contains("F9"), "F9 still in footer hints: {hints:?}");
let fp = "abcdef0123456789deadbeef";
let onion = "abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvwx.onion";
for w in [80u16, 120, 200] {
let line = status_footer(w, fp, onion, None, hints);
assert!(line.contains("F9"), "F9 dropped at {w}: {line:?}");
assert!(line.contains("F6"), "F6 dropped at {w}: {line:?}");
assert!(line.contains("F7"), "F7 dropped at {w}: {line:?}");
assert!(!line.contains("F9"), "F9 still rendered at {w}: {line:?}");
assert!(line.contains("? help"), "? help dropped at {w}: {line:?}");
assert!(line.contains("TOR"), "TOR dropped at {w}: {line:?}");
assert!(
line.chars().count() <= w as usize,
onionwire::tui::cell_width(&line) <= w as usize,
"footer wider than {w}: {line:?}"
);
}
@ -281,29 +288,38 @@ fn compact_footer_drops_the_onion_and_keeps_the_rest() {
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:?}"
onionwire::tui::cell_width(&compact) <= 80,
"{compact:?}"
);
// The cells the onion gave up go to the wallet and node keys.
assert!(compact.contains("F6"), "compact footer lost F6: {compact:?}");
assert!(compact.contains("F7"), "compact footer lost F7: {compact:?}");
assert!(!compact.contains("F9"), "compact footer still prints F9: {compact:?}");
}
#[test]
fn pane_footer_hints_keep_the_menu_and_help_on_every_pane() {
fn pane_footer_hints_name_the_wallet_and_the_node_not_a_menu() {
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("F6"), "{pane:?} lost the wallet key: {hints:?}");
assert!(hints.contains("F7"), "{pane:?} lost the node key: {hints:?}");
assert!(!hints.contains("F9"), "{pane:?} still prints 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("F6"), "{pane:?} at {w} lost F6: {line:?}");
assert!(line.contains("F7"), "{pane:?} at {w} lost F7: {line:?}");
assert!(!line.contains("F9"), "{pane:?} at {w} still prints F9: {line:?}");
assert!(
line.contains("? help"),
"{pane:?} at {w} lost ? help: {line:?}"
);
assert!(line.chars().count() <= w as usize, "{pane:?} at {w}: {line:?}");
assert!(
onionwire::tui::cell_width(&line) <= w as usize,
"{pane:?} at {w}: {line:?}"
);
}
}
// The hints actually change with the pane — that is the point of the lever.

View file

@ -1,4 +1,4 @@
//! Peer payment history screen (F9 → `payments` row).
//! Peer payment history screen (`p` on Main, roster or chat).
//!
//! The screen renders what `Node::list_payments` returns for the friend the rest
//! of the TUI acts on: signed `/pay` invoices, `/tip` receipts and tips, with
@ -11,9 +11,9 @@
use onionwire::Payment;
use onionwire::tui::{
PeerPaymentRow, PeerPaymentsState, WalletMenuState, cell_width, draw_peer_payments,
peer_payments_footer_hint, peer_payments_lines, peer_payments_text, status_footer,
wallets_settings_menu_text,
Pane, PeerPaymentRow, PeerPaymentsState, cell_width, draw_peer_payments,
main_opens_peer_payments, peer_payments_footer_hint, peer_payments_lines, peer_payments_text,
status_footer,
};
use ratatui::Terminal;
use ratatui::backend::TestBackend;
@ -342,73 +342,38 @@ fn peer_payments_columns_drop_before_they_wrap() {
}
#[test]
fn wallets_settings_menu_offers_the_peer_payments_row() {
let st = WalletMenuState {
transfers: 3,
peer: "lance".into(),
peer_payments: Some(3),
..menu_state_defaults()
};
let body = wallets_settings_menu_text(78, &st);
let row = body
.lines()
.find(|l| l.contains("payments"))
.expect("payments row");
assert!(row.contains("lance"), "row does not name the peer: {row:?}");
assert!(row.contains('p'), "row does not name its key: {row:?}");
// The wallet's own transfer list keeps its F6 row; it is retitled so the
// two histories cannot be mistaken for each other.
assert!(
body.lines().any(|l| l.contains("transfers")),
"wallet transfer row lost:\n{body}"
fn peer_payments_opens_from_main_and_the_frame_is_the_history() {
use ratatui::crossterm::event::KeyCode;
// The binding, not a menu row. Composer focus still types the letter.
assert!(main_opens_peer_payments(Pane::Roster, KeyCode::Char('p')));
assert!(main_opens_peer_payments(Pane::Chat, KeyCode::Char('p')));
assert!(!main_opens_peer_payments(Pane::Composer, KeyCode::Char('p')));
let history = render(80, 24, &peer_state());
assert!(history.contains("lance"), "peer missing:\n{history}");
assert!(history.contains("lunch money"), "history missing:\n{history}");
assert!(history.contains("payments"), "title missing:\n{history}");
// Not a menu row named `payments` beside a key column.
assert!(!history.contains("F9"));
assert!(!history.lines().any(|l| l.contains("F7 ctrl")));
let empty = render(
80,
24,
&PeerPaymentsState {
peer: String::new(),
rows: Vec::new(),
error: None,
selected: 0,
},
);
// No friend selected: the row is dim and offers no key that would do
// nothing.
let st = WalletMenuState {
peer: String::new(),
peer_payments: None,
..menu_state_defaults()
};
let body = wallets_settings_menu_text(78, &st);
let row = body
.lines()
.find(|l| l.contains("payments"))
.expect("payments row");
assert!(row.contains("no friend"), "{row:?}");
// A friend with no payment rows is the empty state, not an error.
let st = WalletMenuState {
peer: "lance".into(),
peer_payments: Some(0),
..menu_state_defaults()
};
let body = wallets_settings_menu_text(78, &st);
let row = body
.lines()
.find(|l| l.contains("payments"))
.expect("payments row");
assert!(row.contains("no history"), "{row:?}");
}
/// The F9 menu state with a healthy wallet, as `tests/tui_spec.rs` builds it.
fn menu_state_defaults() -> WalletMenuState {
WalletMenuState {
configured: true,
connected: true,
wallet_error: None,
receive_addr: ADDR.into(),
balance: "0.250000000000".into(),
transfers: 3,
child_state: "ready".into(),
child_source: "local node".into(),
child_error: None,
nickname: Some("lance".into()),
bio_set: true,
xmr_set: true,
me_fp: FP.into(),
peer: String::new(),
peer_payments: None,
assert!(
empty.contains("no friend selected"),
"empty-friend line missing:\n{empty}"
);
for line in empty.lines().chain(history.lines()) {
assert!(cell_width(line) <= 80, "wider than 80: {line:?}");
}
}

View file

@ -5,13 +5,11 @@ use onionwire::Message;
use onionwire::outbox::{OutboxEntry, OutboxStatus};
use onionwire::qr;
use onionwire::tui::{
OutboxSummary, SlashCmd, TorPhase, WalletMenuState, alert_line, ascii_chrome, cell_width,
chat_with_delivery, delivery_tag, draw_chat, draw_share, draw_text_overlay,
draw_wallets_settings, empty_friend_chat_text, fit_cells, help_overlay_text, main_footer_hints,
main_header_line, osc52_copy_sequence, parse_cmd, paste_screen_text, retry_in_text,
roster_col_width, short_send_reason, status_footer, status_footer_phased,
wallets_settings_footer_hint, wallets_settings_menu_lines, wallets_settings_menu_text,
wrap_invite,
OutboxSummary, alert_line, ascii_chrome, cell_width, chat_with_delivery, delivery_tag,
draw_chat, draw_share, draw_text_overlay, empty_friend_chat_text,
help_overlay_text, main_footer_hints, main_header_line, osc52_copy_sequence, parse_cmd,
paste_screen_text, retry_in_text, roster_col_width, short_send_reason, status_footer,
wallet_screen_hint, wallet_screen_text, wallet_setup_keys_line, wrap_invite,
};
use ratatui::Frame;
use ratatui::Terminal;
@ -23,6 +21,8 @@ use std::sync::Mutex;
const FP: &str = "abcdef0123456789deadbeefcafebabe";
static ASCII_ENV: Mutex<()> = Mutex::new(());
const ONION: &str = "abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvwx.onion";
/// A 94-character base58 receive address. Width, not the exact length, is what matters.
const SAMPLE_ADDR: &str = "4AdUndXHHZ6cfufTMvppY6JwXNouMBzSkbLYfpAV5Usx3skxNgYeYJKUGVktfzxayGbMWaC8iqPUE9XUBFGrLyDz4DpEBM";
fn screen_from(buf: &ratatui::buffer::Buffer, w: u16, h: u16) -> String {
let mut screen = String::new();
@ -931,376 +931,69 @@ fn alert_line_prefixes_when_no_color() {
}
// ---------------------------------------------------------------------------
// WALLETS & SETTINGS menu (F9 / `/settings`)
// One wallet screen (F6) and one node screen (F7). No second menu.
// ---------------------------------------------------------------------------
/// A 94-character base58 receive address (a real one is 95; the exact length is
/// not load-bearing, only that it is far wider than the value column).
const SAMPLE_ADDR: &str = "4AdUndXHHZ6cfufTMvppY6JwXNouMBzSkbLYfpAV5Usx3skxNgYeYJKUGVktfzxayGbMWaC8iqPUE9XUBFGrLyDz4DpEBM";
fn menu_state() -> WalletMenuState {
WalletMenuState {
configured: true,
connected: true,
wallet_error: None,
receive_addr: SAMPLE_ADDR.into(),
balance: "0.250000000000".into(),
transfers: 3,
child_state: "ready".into(),
child_source: "local node".into(),
child_error: None,
nickname: Some("lance".into()),
bio_set: true,
xmr_set: true,
me_fp: FP.into(),
peer: "lance".into(),
peer_payments: Some(3),
}
}
/// The menu as the user sees it: body plus its one status line.
fn render_menu(w: u16, h: u16, st: &WalletMenuState) -> String {
let backend = TestBackend::new(w, h);
let mut terminal = Terminal::new(backend).expect("terminal");
// The app's own two calls for this screen (see `App::draw`): the phased
// footer with the hint `footer_hints` returns. A phase-free footer here
// would be a footer the app never renders.
let footer = status_footer_phased(
w,
FP,
ONION,
Some(TorPhase::Ready),
None,
wallets_settings_footer_hint(),
);
terminal
.draw(|f| draw_wallets_settings(f, st, &footer))
.expect("draw");
screen_from(terminal.backend().buffer(), w, h)
}
/// Those labels are not a second menu. F6 still shows the receive address,
/// the balance and create. F7 still names start (`ctrl-s`).
#[test]
fn wallets_settings_menu_frame_shows_the_shipped_footer() {
// Both sides of the assertion read the process environment through
// `ascii_chrome()` / `color_mode()` (glyphs and alert ornaments), so this
// test must serialise with the other env-mutating tests in this binary.
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
// The app renders this screen's one status line with `status_footer_phased`
// (the chrome redesign put the Tor phase in it) and the hint from
// `footer_hints`; the fixture has to do the same or every menu frame in the
// PR is a frame the app never draws.
let shipped = status_footer_phased(
80,
FP,
ONION,
Some(TorPhase::Ready),
None,
wallets_settings_footer_hint(),
);
let frame = render_menu(80, 24, &menu_state());
let last = frame.lines().nth(23).unwrap_or_default();
assert_eq!(
last.trim_end(),
shipped.trim_end(),
"the dumped menu frame's footer is not the one the app renders"
);
}
#[test]
fn wallets_settings_menu_lists_both_groups_and_every_key() {
let body = wallets_settings_menu_text(78, &menu_state());
let wallet_at = body.find("WALLET").expect("wallet header");
let settings_at = body.find("SETTINGS").expect("settings header");
assert!(wallet_at < settings_at, "WALLET must come first:\n{body}");
for needle in [
"endpoint", "child", "sync", "receive", "balance", "payments", "create", "import",
] {
fn wallet_and_node_are_the_screens_not_a_second_menu() {
let help = help_overlay_text();
for gone in ["F9", "/settings", "wallets & settings", "F7 ctrl-s/x"] {
assert!(
body.contains(needle),
"WALLET row {needle:?} missing:\n{body}"
!help.contains(gone),
"help still restates a menu ({gone:?}):\n{help}"
);
}
for needle in [
"nickname", "profile", "identity", "colour", "backup", "restore", "wipe",
] {
// Composer commands that were only named on the menu stay named in help.
for kept in ["/profile", "/backup", "/restore", "/wipe", "/wipe-all"] {
assert!(help.contains(kept), "help dropped {kept:?}:\n{help}");
}
assert!(help.contains("receive"), "F6 help dropped receive:\n{help}");
assert!(help.contains("F6"), "{help}");
assert!(help.contains("F7"), "{help}");
let body = wallet_screen_text(SAMPLE_ADDR, "0.250000000000");
assert!(body.contains("address"), "receive row missing:\n{body}");
assert!(body.contains(SAMPLE_ADDR), "address missing:\n{body}");
assert!(body.contains("balance"), "balance missing:\n{body}");
assert!(body.contains("0.250000000000"), "balance value missing:\n{body}");
let hint = wallet_screen_hint();
assert!(hint.contains("create"), "create missing from the wallet hint: {hint}");
assert!(hint.contains("F7"), "the wallet hint must name the node: {hint}");
let keys = wallet_setup_keys_line();
assert!(keys.contains("ctrl-s"), "F7 no longer names start: {keys}");
assert!(keys.contains("ctrl-x"), "{keys}");
assert!(keys.contains("ctrl-r"), "{keys}");
// The old menu's row labels are not a screen of their own.
let surfaces = format!("{help}\n{body}\n{hint}\n{keys}\n{}", main_footer_hints());
assert!(!surfaces.contains("F9"));
assert!(!main_footer_hints().contains("F9"));
}
/// The wallet hint and the node start line are what those screens print, and
/// both fit the 80-column floor in cells.
#[test]
fn wallet_and_node_copy_fits_the_80_column_floor() {
// The receive address is longer than 80 cells; the screen wraps it. The
// labels and the keys are the lines that must fit unwrapped.
let body = wallet_screen_text("4Ada", "0.250000000000");
for line in body.lines() {
assert!(
body.contains(needle),
"SETTINGS row {needle:?} missing:\n{body}"
cell_width(line) <= 78,
"wallet body wider than the inner 80-column pane: {line:?}"
);
}
// Every actionable row names the key or command that fires it, including the
// keys that now live on F7, so the menu teaches the shortcuts it sits beside
// instead of hiding them. A row must never name a key that no longer works:
// `F6 s/x` and `F6 p` moved to `F7 ctrl-s/x` and `F7 ctrl-r` with the node
// screen, and naming the dead keys here is how they would keep looking live.
for key in [
"F7 ctrl-s/x",
"F7 ctrl-r",
"c copy F6 r",
"F6 c",
"F6 i",
"F6 r",
"F2",
"/profile",
"/backup",
"/restore",
"/wipe",
"/wipe-all",
] {
assert!(
body.contains(key),
"key {key:?} missing from the menu:\n{body}"
);
}
}
#[test]
fn wallets_settings_menu_never_renders_credentials() {
let st = WalletMenuState {
wallet_error: Some("rpc_login=user:hunter2 rejected".into()),
child_error: Some("chain: no login configured".into()),
..menu_state()
};
let body = wallets_settings_menu_text(78, &st);
// No passphrase, seed or login is ever a field on this screen.
assert!(!body.contains("passphrase"), "\n{body}");
assert!(!body.contains("seed word"), "\n{body}");
assert!(!body.contains("WalletConfig"), "\n{body}");
}
#[test]
fn wallets_settings_menu_keeps_one_row_per_cell_even_with_hostile_values() {
// A value that arrives multi-line or tab-separated still occupies one row:
// the row count is fixed, so nothing can be pushed off a 24-row screen.
let st = WalletMenuState {
wallet_error: Some("line one\nline two\nline three".into()),
nickname: Some("tab\there".into()),
..menu_state()
};
let fixed = wallets_settings_menu_lines(78, &menu_state()).len();
let messy = wallets_settings_menu_lines(78, &st);
assert_eq!(
messy.len(),
fixed,
"a multi-line value changed the row count"
);
let text = wallets_settings_menu_text(78, &st);
assert!(text.contains("line one"));
assert!(
text.lines().count() == messy.len(),
"a newline in a value split a row:\n{text}"
);
// The hostile value stays on the endpoint row it belongs to.
let endpoint = text
.lines()
.find(|l| l.starts_with(" endpoint"))
.expect("endpoint row");
assert!(endpoint.contains("line one"), "{endpoint:?}");
assert!(text.contains("tabhere"));
}
#[test]
fn wallets_settings_menu_words_every_state() {
let unconfigured = WalletMenuState {
configured: false,
connected: false,
balance: "off".into(),
receive_addr: String::new(),
transfers: 0,
child_state: "off".into(),
child_source: "receive-only".into(),
nickname: None,
bio_set: false,
xmr_set: false,
..menu_state()
};
let body = wallets_settings_menu_text(78, &unconfigured);
assert!(body.contains("not configured · receive-only"), "\n{body}");
assert!(!body.contains("connected"), "claimed a connection:\n{body}");
assert!(body.contains("no address yet"), "\n{body}");
assert!(body.contains("no transfers yet"), "\n{body}");
assert!(body.contains("not probing · no chain source"), "\n{body}");
assert!(body.contains("(none)"), "\n{body}");
assert!(body.contains("bio unset · xmr unset"), "\n{body}");
// An unconfigured wallet has no address, so there is nothing to copy and no
// copy key is offered.
assert!(
!body.contains("c copy"),
"offered copying with no address:\n{body}"
);
let stale = WalletMenuState {
configured: true,
connected: false,
child_state: "syncing".into(),
balance: "err".into(),
..menu_state()
};
let body = wallets_settings_menu_text(78, &stale);
assert!(body.contains("configured · not connected"), "\n{body}");
assert!(
body.contains("wallet answering · chain not at tip"),
"\n{body}"
);
let exited = WalletMenuState {
child_state: "exited".into(),
child_error: Some("cuprated died on start".into()),
..menu_state()
};
let body = wallets_settings_menu_text(78, &exited);
assert!(body.contains("child exited"), "\n{body}");
assert!(body.contains("cuprated died on start"), "\n{body}");
}
#[test]
fn wallets_settings_menu_truncates_wide_values_in_cells() {
for w in [78u16, 118, 198] {
for line in wallets_settings_menu_lines(w, &menu_state()) {
let text: String = line.spans.iter().map(|s| s.content.as_ref()).collect();
assert!(
cell_width(&text) <= w as usize,
"row wider than {w} cells ({}): {text:?}",
cell_width(&text)
);
}
}
// At 80 columns the 94-character address cannot fit: it is cut with the
// chrome's ellipsis and never pushes the `c copy` key off the row.
let narrow = wallets_settings_menu_text(78, &menu_state());
let receive = narrow
.lines()
.find(|l| l.contains("receive"))
.expect("receive row");
assert!(
receive.contains('…') || receive.contains("..."),
"{receive:?}"
);
assert!(receive.contains("c copy"), "{receive:?}");
// A double-width CJK name is measured in cells, so it truncates after half
// as many characters as an ASCII name of the same budget.
let cjk = WalletMenuState {
nickname: Some("私の名前はとても長い".into()),
..menu_state()
};
for line in wallets_settings_menu_lines(78, &cjk) {
let text: String = line.spans.iter().map(|s| s.content.as_ref()).collect();
assert!(cell_width(&text) <= 78, "{text:?}");
}
assert!(
wallets_settings_menu_text(78, &cjk).contains("私の"),
"CJK name dropped"
);
// Double-width characters cannot always fill the last cell, so the contract
// is "never over budget, never more than one cell of slack".
let cut = fit_cells("私の名前はとても長い", 8);
assert!(cell_width(&cut) <= 8, "{cut:?}");
assert!(cell_width(&cut) >= 6, "wasted cells: {cut:?}");
assert!(
cut.ends_with('…') || cut.ends_with("..."),
"no ellipsis: {cut:?}"
);
// ASCII chrome swaps the ellipsis and the section rule, never the width
// contract. Either ellipsis form is accepted, like the two assertions above:
// `ONIONWIRE_ASCII` is process-wide, so this test cannot assume which form
// is active while other tests run in parallel.
let ascii = fit_cells("abcdefghij", 8);
assert!(cell_width(&ascii) <= 8, "{ascii:?}");
assert!(
ascii.starts_with("abcde") && ascii != "abcdefghij",
"truncation kept the whole string or dropped too much: {ascii:?}"
);
assert!(
ascii.ends_with('…') || ascii.ends_with("..."),
"no ellipsis: {ascii:?}"
);
assert_eq!(cell_width("名"), 2);
assert_eq!(cell_width("abc"), 3);
}
#[test]
fn wallets_settings_menu_fits_80x24_and_120x40() {
for (w, h) in [(80u16, 24u16), (120, 40)] {
let screen = render_menu(w, h, &menu_state());
let rows = wallets_settings_menu_lines(w - 2, &menu_state());
// Nothing scrolls off: the body gets h - 1 rows for its footer, less the
// block's two borders.
assert!(
rows.len() <= (h - 3) as usize,
"menu needs {} rows, {w}x{h} shows {}:\n{screen}",
rows.len(),
h - 3
);
assert!(screen.contains("WALLET"), "{w}x{h}:\n{screen}");
assert!(screen.contains("SETTINGS"), "{w}x{h}:\n{screen}");
assert!(
screen.contains("wipe-all"),
"last row clipped at {w}x{h}:\n{screen}"
);
assert!(
screen.contains("? help"),
"footer clipped at {w}x{h}:\n{screen}"
);
for line in screen.lines() {
assert!(
cell_width(line) <= w as usize,
"row wider than {w} at {w}x{h}: {line:?}"
);
}
}
// 200x60 must not break, and the full address fits there.
let wide = render_menu(200, 60, &menu_state());
assert!(
wide.contains(SAMPLE_ADDR),
"200x60 truncated the address:\n{wide}"
);
}
#[test]
fn wallets_settings_menu_unconfigured_frame_is_not_a_blank_screen() {
let st = WalletMenuState {
configured: false,
balance: "off".into(),
receive_addr: String::new(),
transfers: 0,
child_state: "off".into(),
child_source: "receive-only".into(),
nickname: None,
bio_set: false,
xmr_set: false,
..menu_state()
};
for (w, h) in [(80u16, 24u16), (120, 40)] {
let screen = render_menu(w, h, &st);
// The empty state still names the way out of it.
assert!(screen.contains("not configured"), "{w}x{h}:\n{screen}");
assert!(screen.contains("/wallet create"), "{w}x{h}:\n{screen}");
assert!(screen.contains("/wallet import"), "{w}x{h}:\n{screen}");
assert!(screen.contains("no address yet"), "{w}x{h}:\n{screen}");
assert!(screen.contains("? help"), "{w}x{h}:\n{screen}");
}
}
#[test]
fn wallets_settings_menu_frame_dumps() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
unsafe { std::env::remove_var("ONIONWIRE_ASCII") };
let unconfigured = WalletMenuState {
configured: false,
balance: "off".into(),
receive_addr: String::new(),
transfers: 0,
child_state: "off".into(),
child_source: "receive-only".into(),
..menu_state()
};
for (w, h) in [(80u16, 24u16), (120, 40), (200, 60)] {
println!("===== WALLETS & SETTINGS {w}x{h} =====");
print!("{}", render_menu(w, h, &menu_state()));
println!("===== WALLETS & SETTINGS (unconfigured) {w}x{h} =====");
print!("{}", render_menu(w, h, &unconfigured));
assert!(cell_width(wallet_screen_hint()) <= 78);
assert!(cell_width(wallet_setup_keys_line()) <= 78);
for w in [80u16, 120, 200] {
let line = status_footer(w, FP, ONION, None, main_footer_hints());
assert!(cell_width(&line) <= w as usize, "{w}: {line:?}");
assert!(line.contains("F6"), "F6 dropped at {w}: {line:?}");
assert!(line.contains("F7"), "F7 dropped at {w}: {line:?}");
assert!(!line.contains("F9"), "F9 still rendered at {w}: {line:?}");
}
}
@ -1332,11 +1025,11 @@ fn osc52_copy_sequence_is_a_base64_clipboard_write() {
}
#[test]
fn slash_settings_is_the_menu() {
assert!(matches!(parse_cmd("/settings"), Some(SlashCmd::Settings)));
assert!(matches!(
parse_cmd(" /settings "),
Some(SlashCmd::Settings)
));
assert!(parse_cmd("/settings now").is_none());
fn settings_is_not_a_command_and_the_composer_commands_stay() {
assert!(parse_cmd("/settings").is_none(), "/settings must not open a menu");
assert!(parse_cmd(" /settings ").is_none());
assert!(parse_cmd("/profile").is_some());
assert!(parse_cmd("/wipe").is_some());
assert!(parse_cmd("/wipe-all").is_some());
assert!(parse_cmd("/wallet create").is_some());
}