tui: WALLETS and SETTINGS menu (F9 / /settings) over the landed wallet + node features
The Monero wallet and the cuprate node shipped behind function keys only, so a
user who did not already know F6 opened the wallet could not find wallet setup,
the child wallet, the chain source or the settings.
F9 (also /settings) now opens one discoverable screen with the two groups the
card fixes: WALLET (endpoint, child, sync, receive, balance, payments, create,
import) then SETTINGS (nickname, profile, identity, colour, backup, restore,
wipe, wipe-all). Every actionable row prints the key or command that fires it,
including the F6 wallet screen's own keys, and those keys stay live on the
screen so no row can name a dead key.
- Screen, not popup: 19 rows at 80x24 against 21 inner rows; 120x40 and 200x60
hold. The footer is the shared status_footer, so TOR / identity / ? help stay
put.
- No credentials: WalletMenuState carries booleans, labels and display-ready
error strings only. rpc_login, secret(), seeds and passphrases have no field
to travel in.
- Untrusted values are display data: sanitize + newline/tab strip, then
truncated in cells.
- Cells, not chars: cell_width() measures through ratatui's own Span::width, so
no unicode-width dependency was added and chars().count() is never a width.
- Copy without a clipboard crate: c writes the receive address as an OSC 52
sequence; the terminal owns the clipboard and it survives SSH.
- Colour is never the only signal: every state also spells itself out.
- F7 stays free for the endpoint config screen that names it (db208be,
docs/WALLET.md).
F2/F3/F4/F5/F6/F8 keep working: the function keys are now handled once, for Main
and this screen, instead of inside the Main arm.
This commit is contained in:
parent
0af97e144a
commit
0131803f9c
4 changed files with 1058 additions and 16 deletions
|
|
@ -47,6 +47,7 @@ fn help_overlay_lists_core_bindings() {
|
|||
"F5",
|
||||
"F6",
|
||||
"F8",
|
||||
"F9",
|
||||
"send chat",
|
||||
"/profile",
|
||||
"/pay",
|
||||
|
|
@ -56,6 +57,8 @@ fn help_overlay_lists_core_bindings() {
|
|||
"/file",
|
||||
"/backup",
|
||||
"/restore",
|
||||
"/wipe-all",
|
||||
"/settings",
|
||||
"Ctrl-Q",
|
||||
"?",
|
||||
] {
|
||||
|
|
@ -175,6 +178,35 @@ fn pane_focus_cycles_roster_chat_composer() {
|
|||
assert_eq!(Pane::Composer.prev(), Pane::Chat);
|
||||
}
|
||||
|
||||
#[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.
|
||||
let help = help_overlay_text();
|
||||
assert!(help.contains("F9"), "F9 missing from help:\n{help}");
|
||||
assert!(
|
||||
help.contains("/settings"),
|
||||
"/settings missing from help:\n{help}"
|
||||
);
|
||||
let hints = main_footer_hints();
|
||||
assert!(
|
||||
hints.contains("F9"),
|
||||
"F9 missing from 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("? help"), "? help dropped at {w}: {line:?}");
|
||||
assert!(line.contains("TOR"), "TOR dropped at {w}: {line:?}");
|
||||
assert!(
|
||||
line.chars().count() <= w as usize,
|
||||
"footer wider than {w}: {line:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restore_terminal_is_callable_without_panic() {
|
||||
onionwire::tui::restore_terminal();
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@ use onionwire::Message;
|
|||
use onionwire::outbox::{OutboxEntry, OutboxStatus};
|
||||
use onionwire::qr;
|
||||
use onionwire::tui::{
|
||||
OutboxSummary, alert_line, ascii_chrome, 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, paste_screen_text, retry_in_text, roster_col_width, short_send_reason,
|
||||
status_footer, wrap_invite,
|
||||
OutboxSummary, SlashCmd, 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, wallets_settings_menu_lines, wallets_settings_menu_text,
|
||||
wrap_invite,
|
||||
};
|
||||
use ratatui::Frame;
|
||||
use ratatui::Terminal;
|
||||
|
|
@ -912,3 +914,347 @@ fn alert_line_prefixes_when_no_color() {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// WALLETS & SETTINGS menu (F9 / `/settings`)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// 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(),
|
||||
}
|
||||
}
|
||||
|
||||
/// 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");
|
||||
let footer = status_footer(w, FP, ONION, None, "Esc back c copy ? help");
|
||||
terminal
|
||||
.draw(|f| draw_wallets_settings(f, st, &footer))
|
||||
.expect("draw");
|
||||
screen_from(terminal.backend().buffer(), w, h)
|
||||
}
|
||||
|
||||
#[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",
|
||||
] {
|
||||
assert!(
|
||||
body.contains(needle),
|
||||
"WALLET row {needle:?} missing:\n{body}"
|
||||
);
|
||||
}
|
||||
for needle in [
|
||||
"nickname", "profile", "identity", "colour", "backup", "restore", "wipe",
|
||||
] {
|
||||
assert!(
|
||||
body.contains(needle),
|
||||
"SETTINGS row {needle:?} missing:\n{body}"
|
||||
);
|
||||
}
|
||||
// Every actionable row names the key or command that fires it, including the
|
||||
// F6 wallet screen's own keys, so the menu teaches the shortcuts it sits
|
||||
// beside instead of hiding them.
|
||||
for key in [
|
||||
"F6 s/x", "F6 p", "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.
|
||||
let ascii = fit_cells("abcdefghij", 8);
|
||||
assert!(cell_width(&ascii) <= 8, "{ascii:?}");
|
||||
assert!(ascii.starts_with("abcdef"), "{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));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn osc52_copy_sequence_is_a_base64_clipboard_write() {
|
||||
// OSC 52: ESC ] 52 ; c ; <base64> BEL — the terminal owns the clipboard, so
|
||||
// the address never touches a file and no crate is needed.
|
||||
assert_eq!(osc52_copy_sequence("4Ada"), "\u{1b}]52;c;NEFkYQ==\u{7}");
|
||||
|
||||
let seq = osc52_copy_sequence(SAMPLE_ADDR);
|
||||
let payload = seq
|
||||
.strip_prefix("\u{1b}]52;c;")
|
||||
.and_then(|s| s.strip_suffix('\u{7}'))
|
||||
.expect("osc52 envelope");
|
||||
assert_eq!(payload.len(), 128, "94 bytes base64 to 128 characters");
|
||||
assert!(payload.ends_with("=="), "{payload:?}");
|
||||
assert!(
|
||||
payload
|
||||
.chars()
|
||||
.all(|c| c.is_ascii_alphanumeric() || c == '+' || c == '/' || c == '='),
|
||||
"{payload:?}"
|
||||
);
|
||||
|
||||
// Junk cannot escape the sequence: bidi/control characters, a newline and a
|
||||
// stray BEL are stripped before encoding, and surrounding space is trimmed.
|
||||
let seq = osc52_copy_sequence("4Ada\u{202e}\n\u{7}");
|
||||
assert_eq!(seq, "\u{1b}]52;c;NEFkYQ==\u{7}");
|
||||
assert_eq!(osc52_copy_sequence(" 4Ada "), "\u{1b}]52;c;NEFkYQ==\u{7}");
|
||||
}
|
||||
|
||||
#[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());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue