tui: drop the F9 menu that restates F6 and F7
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:
parent
c550a197ac
commit
4e13242a44
5 changed files with 391 additions and 1147 deletions
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue