From 4e13242a4441de31dcfed8880c5b8c80e6841b62 Mon Sep 17 00:00:00 2001 From: agent Date: Thu, 8 Oct 2026 11:03:28 -0400 Subject: [PATCH] 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. --- docs/TUI.md | 93 ++--- src/tui.rs | 851 +++++++++++------------------------------- tests/tui_chrome.rs | 60 +-- tests/tui_payments.rs | 105 ++---- tests/tui_spec.rs | 443 ++++------------------ 5 files changed, 398 insertions(+), 1154 deletions(-) diff --git a/docs/TUI.md b/docs/TUI.md index 6de7305..bcd8e7a 100644 --- a/docs/TUI.md +++ b/docs/TUI.md @@ -25,15 +25,13 @@ ASCII chrome. | `Wallet` | `F6` | Receive QR, balance, transfers | | `WalletSelect` | `F6` `w` | Saved wallets, pick one or create one | | `WalletSetup` | `F6` `c` / `i`, or `/wallet create` / `import` | Spend warning, seed, optional seed-offset passphrase, import | -| `WalletsSettings` | `F9` or `/settings` | Discovery menu (does not replace F-keys) | | `WalletSetupConfig` | `F7` | Node & wallet setup: RPC endpoint, chain source, start/stop, live node state | -| `PeerPayments` | F9 then `p` | Peer-scoped `/pay` / `/tip` history | +| `PeerPayments` | `p` on Main (roster or chat) | Peer-scoped `/pay` / `/tip` history | | `Quit` | `Ctrl-Q` | Type `CLEAR` or `QUIT` | Help (`?`) is an overlay, not a screen. `/who` / `F5` is an overlay on Main. -Function keys that fire from Main, the settings menu, and -peer-payments are: +Function keys that fire from Main are: | Key | `FunctionKey` | Action | |---|---|---| @@ -44,33 +42,33 @@ peer-payments are: | `F6` | Wallet | Wallet screen | | `F7` | Setup | Node & wallet setup: RPC endpoint, chain source, start/stop | | `F8` | RotatePrekey | Prekey hard cut | -| `F9` | OpenMenu | Wallets & settings | -`F9` is live on Main, the settings menu, and peer-payments so a printed shortcut -never no-ops there, and `F7` joins it for the same reason: `/settings` points at -the setup screen. Other screens handle their own keys (Esc back, typed -confirms). +`F7` also fires on the wallet screen, which prints it. There is no `F9` and no +`/settings`: that menu restated F6 and F7. A screen that does not name a +function key does not answer one. Other screens handle their own keys (Esc +back, typed confirms). ## Main Focus starts on the composer. Footer hints (`main_footer_hints`): ``` -Tab F2 F3 F4 F5 F6 F7 F9 ? help Ctrl-Q +Tab F2 F3 F4 F5 Ctrl-Q F6 F7 ? help ``` Pane-specific (`pane_footer_hints`): | Pane | Hint | |---|---| -| Roster | `j k F3 add F6 wallet F7 setup F9 ? help` | -| Chat | `j k g G ends F4 rotate F7 setup F9 ? help` | -| Composer | `Enter send / commands F7 setup F9 ? help` | +| Roster | `j k p pay F3 add F6 wallet F7 setup ? help` | +| Chat | `j k g G p pay F6 wallet F7 setup ? help` | +| Composer | `Enter send / commands F6 wallet F7 setup ? help` | The status line is drawn from the focused pane's hint, and the compactor drops tokens from the front until the line fits, so a key that only appears in -`main_footer_hints` never reaches an 80-column terminal. `F7` is therefore named -in both, and the `F9` beside it is left bare so the whole hint still fits at 80. +`main_footer_hints` never reaches an 80-column terminal. `F6` and `F7` are +therefore named in both, at the tail. `p` is named only on roster and chat: +the composer types the letter. | Key | Action | |---|---| @@ -96,7 +94,6 @@ in both, and the `F9` beside it is left bare so the whole hint still fits at 80. | `/file /path` | File send, 1 MiB, one-shot | | `/wallet create` | Same as `F6` then `c` | | `/wallet import` | Same as `F6` then `i` | -| `/settings` | Same as `F9` | | `/backup /path` | Encrypted identity export | | `/restore /path` | Overwrite self keys | | `/wipe` | Type `WIPE` — chat/payments/outbox; identity stays | @@ -134,15 +131,15 @@ c create i import r qr w wallets F7 node Esc back ? help | `F7` | Node & wallet setup (`WalletSetupConfig`) | | Esc | Back to Main | -The child's state and the chain source are shown here (and on `F9`), but they are -**set** on `F7`: the start/stop/probe keys and the `1`/`2`/`3` in-process picker -that used to live on this screen are gone, so there is one place that configures -the chain. +The child's state and the chain source are shown here, but they are **set** on +`F7`: the start/stop/probe keys and the `1`/`2`/`3` in-process picker that used +to live on this screen are gone, so there is one place that configures the chain. The chain line for an in-process source always carries -`testnet only — mainnet is unvalidated` (`cuprate::TESTNET_ONLY`). Starting -Cuprate needs `--features cuprate-daemon`; without it, start fails with that -feature name. +`testnet only — mainnet is unvalidated` (`cuprate::TESTNET_ONLY`). The default +binary includes the in-process daemon. A build compiled without that feature +still shows the rebuild message on the chain row, and start fails with that +feature name only on such a build. Create/import require the wallet RPC started with `--wallet-dir`. Filename: `onionwire`. Seed is never collected on the composer. @@ -187,9 +184,9 @@ The compactor drops tokens from the front, and at 80 columns the status line leaves about 25 cells, so the tail is what the default terminal shows. `Tab` and `?` are universal; the node's own keys (`ctrl-s`, `ctrl-x`, `ctrl-r`) and `Ctrl-U` are named in the body, on the row they act on. -Live from Main, the `F9` settings menu, and peer payments; the menu's `endpoint` -row names `F7` as the key that edits it. Body is `WalletSetupConfigState`, a -snapshot taken when the screen opens — the render path never reads the store. +Live from Main and from the wallet screen, which prints `F7 node`. Body is +`WalletSetupConfigState`, a snapshot taken when the screen opens — the render +path never reads the store. This is the only screen that sets up the chain: the wallet RPC endpoint, and the node that serves it. @@ -246,41 +243,25 @@ so in the same frame — `a daemon you do not run sees this wallet's chain traffic` — because that is the pick that moves chain trust off this box. The address must parse as `host:port` first. -A build without `cuprate-daemon` says so on the `chain` row, where the choice is -made, rather than offering it and refusing at start: the in-process wording is -followed by `this build has no in-process chain daemon — rebuild with --features -cuprate-daemon` (`crate::cuprate::NO_FEATURE_MSG`, clamped to the frame width). -The pick is still offered — builds with the feature exist, and a stored -in-process source must still be readable. +The default `onionwire` binary includes the in-process daemon. A build without +that feature says so on the `chain` row, where the choice is made, rather than +offering it and refusing at start: the in-process wording is followed by +`NO_FEATURE_MSG` (clamped to the frame width). The pick is still offered — a +stored in-process source must still be readable — and that rebuild line appears +only on a build that left the feature out. Esc is the single exit and wipes the login buffer (`Zeroizing`). -## Wallets & settings (`F9` / `/settings`) +`/profile`, `/backup`, `/restore`, `/wipe` and `/wipe-all` stay composer +commands. They are named in help (`?`). There is no settings menu that restates +them, and no `F9`. -Discovery layer, not a replacement. Function keys stay live on this screen. -Rows name the shortcut they sit beside (`F6 c`, `F6 i`, `F6 r`, `/profile`, -`/backup`, `/wipe`, …). - -- **No credentials** on this screen. Login, seed, and passphrase are never - passed into the menu snapshot. -- `c` copies the receive address (OSC 52). -- `p` opens peer payment history for the selected friend (`Node::list_payments`). -- Esc back to Main. - -The menu **shows** endpoint state; it does not edit it. The `endpoint` row names -`F7`, which is the key that opens `WalletSetupConfig` and the key the “open F7” -copy in `src/wallet.rs` now points at — that error is no longer advice for a key -that does not exist. - -Chain source is stored via `Node::set_wallet_child_config`. `F7` is the one -screen that sets any of the four sources — receive-only, a local `monerod`, a -remote daemon, or the in-process Cuprate node — along with the external RPC URL -and the chain datadir. - -## Peer payments (`F9` then `p`) +## Peer payments (`p` on Main) Peer-scoped signed invoices and tips, not the wallet's own transfer list. -`j`/`k` or arrows select. Esc back. Footer: `Esc back up/down select F9 menu ? help`. +`p` opens it from the roster or the chat (the composer types the letter). With +no friend selected the screen says `no friend selected`. `j`/`k` or arrows +select. Esc back. Footer: `Esc back up/down select ? help`. ## Delivery markers (chat) @@ -302,6 +283,6 @@ Floor **80×24**. Target **120×40**. Frame dumps: ``` cargo test --locked --test tui_spec -- --nocapture dump_spec_frames -cargo test --locked --test tui_spec -- --nocapture wallets_settings_menu_frame_dumps +cargo test --locked --lib f6_and_f7_frames_fit -- --nocapture cargo test --locked --test tui_select -- --nocapture wallet_select_frame_dumps ``` diff --git a/src/tui.rs b/src/tui.rs index 782b107..5068dac 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -553,7 +553,7 @@ OnionWire keys\n\ F6 wallet (receive QR, create/import)\n\ F7 wallet setup: RPC endpoint, chain source\n\ F8 rotate prekey\n\ - F9 wallets & settings menu\n\ + p peer payments (roster or chat)\n\ /profile edit name, bio, Monero address\n\ /pay [memo] invoice to receive\n\ /tip [memo] pay selected friend\n\ @@ -564,7 +564,6 @@ OnionWire keys\n\ /restore /path overwrite self keys\n\ /wipe wipe messages; identity and friends stay\n\ /wipe-all wipe identity too — you become a new person\n\ - /settings wallets & settings menu\n\ ? this help\n\ Ctrl-Q quit; type CLEAR or QUIT\n\ \n\ @@ -715,8 +714,6 @@ pub enum SlashCmd { Wipe(WipeKind), Profile, Who, - /// `/settings` — the WALLETS & SETTINGS menu (same screen as F9). - Settings, Pay { atomic: String, memo: String }, Tip { atomic: String, memo: String }, Backup { path: String }, @@ -873,7 +870,6 @@ pub fn parse_cmd(raw: &str) -> Option { return parse_path_cmd(rest).map(|path| SlashCmd::File { path }); } match s { - "/settings" => return Some(SlashCmd::Settings), "/wallet create" => return Some(SlashCmd::WalletCreate), "/wallet import" => return Some(SlashCmd::WalletImport), _ => {} @@ -1295,15 +1291,10 @@ enum Screen { WalletSetupConfig { state: WalletSetupConfigState, }, - /// F9 / `/settings`: the WALLETS & SETTINGS discovery menu. Holds the - /// snapshot, not a pre-rendered body, so a resize re-fits and nothing stale - /// survives a repaint. - WalletsSettings { - state: WalletMenuState, - }, - /// F9 → `payments`: the peer-scoped history from `Node::list_payments`. - /// Holds the same kind of snapshot as the menu (a resize re-fits it), so a - /// repaint never re-reads the store mid-frame. + /// `p` on Main (roster or chat): the peer-scoped history from + /// `Node::list_payments`. Holds a snapshot, so a resize re-fits it and a + /// repaint never re-reads the store mid-frame. An empty peer is the + /// no-friend state — the screen says so, it does not pretend "no history". PeerPayments { state: PeerPaymentsState, }, @@ -1784,7 +1775,6 @@ enum FunctionKey { Who, Wallet, RotatePrekey, - OpenMenu, Setup, } @@ -1794,22 +1784,26 @@ enum FunctionKey { /// The function keys stay live on every screen that names one — in its footer /// or in its body: a shortcut the user can read has to work while that screen /// is open. +/// `p` on Main opens peer payments when the composer is not taking the key. +/// Typing `p` in the composer still inserts the letter — the composer is the +/// default focus, and a chat has to be able to contain the letter p. +pub fn main_opens_peer_payments(focus: Pane, code: KeyCode) -> bool { + focus != Pane::Composer && matches!(code, KeyCode::Char('p')) +} + fn function_key_for(screen: &Screen, code: KeyCode) -> Option { - if !matches!( - screen, - Screen::Main | Screen::WalletsSettings { .. } | Screen::PeerPayments { .. } - ) { - return None; - } - match code { - KeyCode::F(2) => Some(FunctionKey::Share), - KeyCode::F(3) => Some(FunctionKey::Paste), - KeyCode::F(4) => Some(FunctionKey::Rotate), - KeyCode::F(5) => Some(FunctionKey::Who), - KeyCode::F(6) => Some(FunctionKey::Wallet), - KeyCode::F(7) => Some(FunctionKey::Setup), - KeyCode::F(8) => Some(FunctionKey::RotatePrekey), - KeyCode::F(9) => Some(FunctionKey::OpenMenu), + // A printed shortcut has to work on the screen that prints it, and a screen + // that does not name a function key must not answer one. Main names F2–F8. + // The wallet screen names F7 in its own hint. F9 is not a key. + match (screen, code) { + (Screen::Main, KeyCode::F(2)) => Some(FunctionKey::Share), + (Screen::Main, KeyCode::F(3)) => Some(FunctionKey::Paste), + (Screen::Main, KeyCode::F(4)) => Some(FunctionKey::Rotate), + (Screen::Main, KeyCode::F(5)) => Some(FunctionKey::Who), + (Screen::Main, KeyCode::F(6)) => Some(FunctionKey::Wallet), + (Screen::Main, KeyCode::F(7)) => Some(FunctionKey::Setup), + (Screen::Main, KeyCode::F(8)) => Some(FunctionKey::RotatePrekey), + (Screen::Wallet { .. }, KeyCode::F(7)) => Some(FunctionKey::Setup), _ => None, } } @@ -1906,7 +1900,6 @@ impl App { let mut wipe_confirm = None; let mut quit_clear = None; - let mut copy_addr = false; let mut profile_save = None; let mut open_profile = false; let mut pay_cmd = None; @@ -1921,10 +1914,8 @@ impl App { let mut select_move = 0i32; let mut select_enter = false; - // The function-key shortcuts stay live on the WALLETS & SETTINGS screen - // and the peer history too: the settings screen's whole point is naming - // the key that fires each row, and the history's footer names `F9 - // menu`, so a key a screen names has to work while it is open. + // A function key a screen names has to work while that screen is open. + // Screens that name none keep the key to themselves. if let Some(fk) = function_key_for(&self.screen, key.code) { match fk { FunctionKey::Share => self.open_share()?, @@ -1941,18 +1932,13 @@ impl App { } FunctionKey::Who => self.who_open = true, FunctionKey::Wallet => self.open_wallet()?, - // The setup screen opens from Main, the settings menu and the - // peer history: those are the screens that name `F7`. + // Main and the wallet screen both name F7. It is the node. FunctionKey::Setup => self.open_setup_config(), FunctionKey::RotatePrekey => { self.screen = Screen::RotatePrekey { prompt: RotatePrompt::new(), }; } - // One level above the screen it is pressed on: F9 from Main - // opens the menu, and from the menu or the peer history it - // reopens it rather than silently doing nothing. - FunctionKey::OpenMenu => self.open_wallets_settings()?, } return Ok(None); } @@ -1986,10 +1972,6 @@ impl App { self.composer.clear(); self.who_open = true; } - Some(ComposerAction::Cmd(SlashCmd::Settings)) => { - self.composer.clear(); - self.open_wallets_settings()?; - } Some(ComposerAction::Cmd(SlashCmd::Pay { atomic, memo })) => { self.composer.clear(); pay_cmd = Some((atomic, memo)); @@ -2040,6 +2022,14 @@ impl App { } None => {} }, + // `p` opens peer payments from the roster or the chat. The + // composer still types the letter — see `main_opens_peer_payments`. + KeyCode::Char('p') + if !key.modifiers.contains(KeyModifiers::CONTROL) + && main_opens_peer_payments(self.focus, key.code) => + { + open_payments = true; + } KeyCode::Char(c) if !key.modifiers.contains(KeyModifiers::CONTROL) => { self.handle_main_char(c); } @@ -2183,13 +2173,6 @@ impl App { }, Screen::WalletSetup(_) => self.handle_wallet_setup(key)?, Screen::WalletSetupConfig { .. } => self.handle_wallet_setup_config(key), - Screen::WalletsSettings { .. } => match key.code { - KeyCode::Esc => self.screen = Screen::Main, - KeyCode::Char('c') => copy_addr = true, - // `p` is the key the menu's `payments` row prints. - KeyCode::Char('p') => open_payments = true, - _ => {} - }, Screen::PeerPayments { .. } => match key.code { KeyCode::Esc => payments_back = true, KeyCode::Up | KeyCode::Char('k') => payments_move = -1, @@ -2253,9 +2236,6 @@ impl App { if open_payments { self.open_peer_payments()?; } - if copy_addr { - self.copy_receive_address(); - } if let Some(clear) = quit_clear { if clear { self.node.wipe_messages()?; @@ -2467,9 +2447,9 @@ impl App { fn open_wallet(&mut self) -> Result<(), String> { // An install with no wallet is a normal state on this screen, not a - // fatal one: `F9` already degrades the same call to an empty address. - // Propagating the `Err` here ran out of `App::run` and out of `main`, so - // pressing `F6` killed the process. + // fatal one: the call degrades to an empty address and the screen's + // own create/import keys. Propagating the `Err` here ran out of + // `App::run` and out of `main`, so pressing `F6` killed the process. let addr = match self.rt.block_on(self.node.wallet_receive_address()) { Ok(addr) => addr, Err(_) => { @@ -2494,78 +2474,19 @@ impl App { Ok(()) } - /// F9 / `/settings`: snapshot the state the WALLETS & SETTINGS menu shows. - /// - /// Credential-free by construction: it reads `Node`'s status/label getters - /// only — never `WalletConfig::rpc_login`, `secret()`, a seed, or a - /// passphrase — so nothing on the screen can leak one. - /// - /// It blocks on the same three wallet calls the F6 screen already blocks on - /// (address, balance, recent transfers); `wallet_status` and - /// `wallet_child_status` are lock-only reads and never dial. - fn open_wallets_settings(&mut self) -> Result<(), String> { - let wstat = self.node.wallet_status(); - let child = self.node.wallet_child_status(); - let balance = self.rt.block_on(self.node.wallet_balance()); - let receive_addr = self - .rt - .block_on(self.node.wallet_receive_address()) - .unwrap_or_default(); - let transfers = self - .rt - .block_on(self.node.wallet_recent_transfers(8)) - .map(|rows| rows.len()) - .unwrap_or(0); - let profile = self.node.self_profile().ok(); - let nickname = profile - .as_ref() - .and_then(|p| (!p.display_name.is_empty()).then(|| p.display_name.clone())); - let bio_set = profile.as_ref().is_some_and(|p| !p.bio.is_empty()); - let xmr_set = profile.as_ref().is_some_and(|p| !p.xmr_addr.is_empty()); - // The friend the rest of the TUI acts on is the chat's selected friend. - // `list_payments` is a lock-only read: no dial, no RPC, so this snapshot - // stays cheap and works while Tor is still bootstrapping. - let friend = self.friends.get(self.selected); - let peer = friend - .map(|f| f.petname.clone().unwrap_or_else(|| f.fingerprint.clone())) - .unwrap_or_default(); - let peer_payments = friend.and_then(|f| { - self.node - .list_payments(&f.pubkey) - .ok() - .map(|rows| rows.len()) - }); - self.screen = Screen::WalletsSettings { - state: WalletMenuState { - configured: wstat.configured, - connected: wstat.connected, - wallet_error: wstat.last_error, - receive_addr, - balance, - transfers, - child_state: child.state.as_str().to_string(), - child_source: child.chain_source, - child_error: child.last_error, - nickname, - bio_set, - xmr_set, - me_fp: self.me_fp.clone(), - peer, - peer_payments, - }, - }; - Ok(()) - } - - /// The F9 menu's `payments` row: the selected friend's payment history from + /// `p` on Main: the selected friend's payment history from /// `Node::list_payments`. /// /// Read-only and fail-closed: the call takes the store lock and nothing /// else, so it never dials and is safe while offline. A friend with no rows - /// is `Ok(vec![])` — an empty history, not an error. + /// is `Ok(vec![])` — an empty history, not an error. No selected friend + /// still opens the screen: the body says `no friend selected`, which is a + /// different statement from an empty history. fn open_peer_payments(&mut self) -> Result<(), String> { let Some(friend) = self.friends.get(self.selected) else { - self.status_note = Some("no friend selected".into()); + self.screen = Screen::PeerPayments { + state: PeerPaymentsState::default(), + }; return Ok(()); }; let peer = friend @@ -2666,31 +2587,9 @@ impl App { self.screen = Screen::WalletSelect { state }; } - /// `c` on the WALLETS & SETTINGS menu: copy the receive address through the - /// terminal's own clipboard (OSC 52 — no crate, and it survives SSH). The - /// address never touches a file. - fn copy_receive_address(&mut self) { - let addr = match &self.screen { - Screen::WalletsSettings { state } => state.receive_addr.clone(), - _ => return, - }; - if addr.is_empty() { - self.status_note = Some("no receive address to copy".into()); - return; - } - let seq = osc52_copy_sequence(&addr); - let wrote = { - let mut out = io::stdout(); - out.write_all(seq.as_bytes()).is_ok() && out.flush().is_ok() - }; - self.status_note = Some(if wrote { - "copied receive address".into() - } else { - "could not write the clipboard sequence".into() - }); - } - - /// `C` on the invite screen: the same OSC 52 handoff as the receive address, + /// `C` on the invite screen: OSC 52, so a terminal that blocks the write + /// still leaves the mouse selection as the way out. The payload never + /// touches a file. /// so a terminal that blocks the write still leaves the mouse selection as /// the way out. The payload never touches a file. fn copy_invite(&mut self) { @@ -3399,20 +3298,6 @@ impl App { ); draw_wallet_setup_config(f, state, &footer) } - Screen::WalletsSettings { state } => { - // The one status line the screen carries: same `status_footer` - // shape as Main, so TOR / identity / the copy confirmation read - // in the same place on every screen — including the phase. - let footer = status_footer_phased( - f.area().width, - &self.me_fp, - &self.me_onion, - Some(TorPhase::of(self.node.tor_state())), - self.status_note.as_deref(), - footer_hints(&self.screen), - ); - draw_wallets_settings(f, state, &footer) - } Screen::PeerPayments { state } => { let footer = status_footer( f.area().width, @@ -4008,30 +3893,24 @@ fn footer_fits(parts: &[String], extra: &[&str], help: &str, gap: &str, w: usize cell_width(&all.join(gap)) <= w } -/// Main-screen key hints. `F6` (wallet) and `F9` (wallets & settings) are named -/// here on purpose: the menu is the discoverable surface, and the footer is how -/// a user finds the menu in the first place. Kept short so width 80 still shows -/// TOR + identity + `? help`. +/// Main-screen key hints. `F6` is the wallet and `F7` is the node. They sit at +/// the tail so the compactor, which drops tokens from the front, still shows +/// both at 80 columns. There is no F9: that key was a menu that restated these. pub fn main_footer_hints() -> &'static str { - "Tab F2 F3 F4 F5 F6 F7 F9 ? help Ctrl-Q" + "Tab F2 F3 F4 F5 Ctrl-Q F6 F7 ? help" } /// Footer hints for one focused main pane. /// -/// The footer is the only place the keys are visible without opening `?`, so it -/// changes with the pane you are actually in — and every variant keeps `F9` -/// (the discoverable menu) and `? help`, which `tests/tui_chrome.rs` asserts are -/// reachable from the footer at 80, 120 and 200. +/// The status line is drawn from the focused pane's hint, so a key only in +/// `main_footer_hints` never reaches an 80-column terminal. Every pane therefore +/// names `F6` and `F7` at the tail. `p` is named only on the panes where it +/// opens peer payments — the composer types the letter, so it must not print it. pub fn pane_footer_hints(pane: Pane) -> &'static str { - // `F7` is named here as well as in `main_footer_hints`: the status line is - // drawn from the focused pane's hint, so a key only in the main list would - // never reach the 80-column terminal. The tokens have to fit whole — the - // compactor drops them from the front — so the words that matter to F7 stay - // and the neighbouring `F9` is left bare. match pane { - Pane::Roster => "j k F3 add F6 wallet F7 setup F9 ? help", - Pane::Chat => "j k g G ends F4 rotate F7 setup F9 ? help", - Pane::Composer => "Enter send / commands F7 setup F9 ? help", + Pane::Roster => "j k p pay F3 add F6 wallet F7 setup ? help", + Pane::Chat => "j k g G p pay F6 wallet F7 setup ? help", + Pane::Composer => "Enter send / commands F6 wallet F7 setup ? help", } } @@ -4071,7 +3950,6 @@ match screen { Screen::WalletSetup(WalletSetup::ImportOffsetSeen { .. }) => "type SEEN ? help", Screen::WalletSetup(WalletSetup::CreateSeed { .. }) => "type SEEN Esc cancel ? help", Screen::WalletSetup(WalletSetup::ImportSeed { .. }) => "paste seed Enter Esc ? help", - Screen::WalletsSettings { .. } => wallets_settings_footer_hint(), Screen::PeerPayments { .. } => peer_payments_footer_hint(), Screen::WalletSetupConfig { .. } => wallet_setup_config_footer_hint(), Screen::WalletSelect { .. } => wallet_select_footer_hint(), @@ -4086,17 +3964,7 @@ pub fn peer_payments_footer_hint() -> &'static str { PEER_PAYMENTS_FOOTER_HINT } -const PEER_PAYMENTS_FOOTER_HINT: &str = "Esc back up/down select F9 menu ? help"; - -/// The hint line the WALLETS & SETTINGS menu prints, single-sourced for the -/// same reason as [`peer_payments_footer_hint`]: the menu's frame-dump fixture -/// must not hand-copy it (and must not pair it with the phase-free footer the -/// app stopped using when the chrome redesign landed). -pub fn wallets_settings_footer_hint() -> &'static str { - WALLETS_SETTINGS_FOOTER_HINT -} - -const WALLETS_SETTINGS_FOOTER_HINT: &str = "Esc back c copy ? help"; +const PEER_PAYMENTS_FOOTER_HINT: &str = "Esc back up/down select ? help"; /// The hint line the F7 setup screen prints, single-sourced like the other /// screens': its frame test builds the fixture from this, so a dumped frame can @@ -4385,69 +4253,15 @@ pub fn draw_text_overlay(f: &mut Frame, title: &str, text: &str) { } // --------------------------------------------------------------------------- -// WALLETS & SETTINGS menu (F9 / `/settings`) -// -// One screen that names every wallet and settings capability the TUI can -// actually reach, together with the key or command that fires each one. It is a -// discoverability layer over the existing shortcuts, not a replacement: F2, F3, -// F4, F5, F6 and F8 keep working, and they stay live *on this screen* so no row -// can name a key that does nothing here. -// -// Copy, never credentials. `WalletMenuState` carries booleans, labels and -// display-ready error strings from `Node`'s getters; it has no field that can -// hold `WalletConfig::rpc_login`, `secret()`, a seed, or a passphrase. +// Cell measurement and one-line sanitizing. Shared by the wallet, the node +// screen and peer payments. `unicode-width` is not a dependency; `Span::width` +// is the same measurement the renderer truncates with. // --------------------------------------------------------------------------- -/// Label column in cells. Every label is short ASCII, so this is also its -/// character count. -const MENU_LABEL_W: usize = 9; -/// Key column in cells: the widest key string the menu emits. -const MENU_KEYS_W: usize = 12; - -/// State the WALLETS & SETTINGS menu draws. Built once by the caller from -/// `Node`'s getters and carried raw (un-sanitized) — the render path strips -/// control/bidi characters and truncates in cells. -#[derive(Clone, Debug, Default)] -pub struct WalletMenuState { - /// A wallet endpoint resolved to a usable wallet (stored or env config). - pub configured: bool, - /// The last probe answered. Never inferred from `configured`. - pub connected: bool, - /// `WalletStatus::last_error`, display-ready. - pub wallet_error: Option, - /// Receive address; empty when the wallet is unreachable. - pub receive_addr: String, - /// Human-readable balance, or `off` / `err` from `Node::wallet_balance`. - pub balance: String, - /// How many recent transfers `Node::wallet_recent_transfers` returned. - pub transfers: usize, - /// `WalletChildState` display word: off / connecting / syncing / ready / - /// exited. - pub child_state: String, - /// Chain-source label: `receive-only` / `local node` / `remote daemon`. - pub child_source: String, - /// `WalletChildStatus::last_error`, display-ready. - pub child_error: Option, - /// Self-profile display name, if one is set. - pub nickname: Option, - pub bio_set: bool, - pub xmr_set: bool, - /// Our own fingerprint (identity = pubkey), full hex. - pub me_fp: String, - /// Display name of the friend the F9 screen's friend-scoped rows act on (the - /// chat's selected friend), or empty when there is none. - pub peer: String, - /// `Some(rows)` when `Node::list_payments` answered for that friend; - /// `None` when the read itself failed (which is not "no history"). - pub peer_payments: Option, -} - /// Width of `s` in terminal **cells**, measured by ratatui's own text type. /// -/// `unicode-width` is not a direct dependency of this crate, so this goes -/// through `Span::width` — the same measurement the renderer truncates with — -/// rather than `chars().count()`: CJK and emoji are double-width, combining -/// marks zero-width, and a char count gets both wrong. +/// CJK and emoji are double-width, combining marks zero-width, and a char +/// count gets both wrong. pub fn cell_width(s: &str) -> usize { ratatui::text::Span::raw(s).width() } @@ -4486,238 +4300,6 @@ fn menu_cell_text(raw: &str) -> String { .collect() } -fn menu_yn(set: bool) -> &'static str { - if set { "set" } else { "unset" } -} - -/// Which `style_*` token a row's value carries. Colour is never the only -/// signal: every value also spells its state out in words. -#[derive(Clone, Copy, PartialEq, Eq)] -enum MenuTone { - Normal, - Dim, - Alert, - Stale, -} - -struct MenuRow { - label: &'static str, - value: String, - keys: &'static str, - tone: MenuTone, -} - -impl MenuRow { - fn new(label: &'static str, value: String, keys: &'static str, tone: MenuTone) -> Self { - Self { - label, - value, - keys, - tone, - } - } -} - -/// The two groups, in the order the card fixes: WALLET, then SETTINGS. -/// -/// Two payment-ish rows, and they are not the same thing: `transfers` is the -/// wallet's own list (F6, `wallet_recent_transfers`), `payments` is the -/// peer-scoped history (`Node::list_payments`) opened by `p`. -fn menu_groups(s: &WalletMenuState) -> (Vec, Vec) { - let endpoint_word = if !s.configured { - "not configured · receive-only" - } else if s.connected { - "configured · connected" - } else { - "configured · not connected" - }; - let endpoint_tone = if s.wallet_error.is_some() { - MenuTone::Alert - } else if !s.configured { - MenuTone::Dim - } else if s.connected { - MenuTone::Normal - } else { - MenuTone::Stale - }; - let endpoint_value = match &s.wallet_error { - Some(e) => format!("{endpoint_word} · {}", menu_cell_text(e)), - None => endpoint_word.to_string(), - }; - - let running = matches!(s.child_state.as_str(), "connecting" | "syncing" | "ready"); - let child_value = format!( - "{} · {}", - menu_cell_text(&s.child_source), - if running { "running" } else { "not started" } - ); - let (sync_word, sync_tone) = match s.child_state.as_str() { - "ready" => ("chain at tip · wallet answering", MenuTone::Normal), - "syncing" => ("wallet answering · chain not at tip", MenuTone::Stale), - "connecting" => ("wallet RPC not answering yet", MenuTone::Stale), - "exited" => ("child exited", MenuTone::Alert), - _ => ("not probing · no chain source", MenuTone::Dim), - }; - let sync_value = match &s.child_error { - Some(e) => format!("{sync_word} · {}", menu_cell_text(e)), - None => sync_word.to_string(), - }; - - let receive_empty = s.receive_addr.is_empty(); - let wallet = vec![ - // `F7` is the key that edits this row, so the row names it: the menu is - // the discovery layer, and the endpoint is the one thing only F7 writes. - MenuRow::new("endpoint", endpoint_value, "F7", endpoint_tone), - MenuRow::new("child", child_value, "F7 ctrl-s/x", MenuTone::Normal), - MenuRow::new("sync", sync_value, "F7 ctrl-r", sync_tone), - MenuRow::new( - "receive", - if receive_empty { - "no address yet · wallet unreachable".to_string() - } else { - menu_cell_text(&s.receive_addr) - }, - if receive_empty { "" } else { "c copy F6 r" }, - if receive_empty { - MenuTone::Dim - } else { - MenuTone::Normal - }, - ), - MenuRow::new( - "balance", - menu_cell_text(&s.balance), - "F6", - match s.balance.as_str() { - "err" => MenuTone::Alert, - "off" | "" => MenuTone::Dim, - _ => MenuTone::Normal, - }, - ), - MenuRow::new( - "transfers", - if s.transfers == 0 { - "no transfers yet".to_string() - } else { - format!("{} recent", s.transfers) - }, - "F6", - if s.transfers == 0 { - MenuTone::Dim - } else { - MenuTone::Normal - }, - ), - // The peer-scoped history: signed `/pay` invoices and `/tip` receipts - // that peer sent. Distinct from the wallet's own transfer list above, - // and labelled so — `Payments` here means `payments` rows, not the - // wallet's `transfers`. - MenuRow::new( - "payments", - if s.peer.is_empty() { - "no friend selected".to_string() - } else { - let peer = menu_cell_text(&s.peer); - match s.peer_payments { - None => format!("history unreadable {}{peer}", "\u{b7} "), - Some(0) => format!("no history with {peer}"), - Some(n) => format!("{n} with {peer}"), - } - }, - if s.peer.is_empty() { "" } else { "p" }, - if s.peer.is_empty() || s.peer_payments == Some(0) { - MenuTone::Dim - } else { - MenuTone::Normal - }, - ), - MenuRow::new( - "create", - "/wallet create · seed shown once".to_string(), - "F6 c", - MenuTone::Normal, - ), - MenuRow::new( - "import", - "/wallet import · 25-word seed".to_string(), - "F6 i", - MenuTone::Normal, - ), - ]; - - let settings = vec![ - MenuRow::new( - "nickname", - match &s.nickname { - Some(n) => menu_cell_text(n), - None => "(none)".to_string(), - }, - "/profile", - if s.nickname.is_some() { - MenuTone::Normal - } else { - MenuTone::Dim - }, - ), - MenuRow::new( - "profile", - format!("bio {} · xmr {}", menu_yn(s.bio_set), menu_yn(s.xmr_set)), - "/profile", - if s.bio_set || s.xmr_set { - MenuTone::Normal - } else { - MenuTone::Dim - }, - ), - MenuRow::new( - "identity", - format!("{} · identity = pubkey", truncate_fp(&s.me_fp)), - "F2", - MenuTone::Normal, - ), - MenuRow::new( - "colour", - "auto · follows NO_COLOR / TERM".to_string(), - "", - MenuTone::Dim, - ), - MenuRow::new( - "backup", - "encrypted identity export".to_string(), - "/backup", - MenuTone::Normal, - ), - MenuRow::new( - "restore", - "overwrite self keys from a backup".to_string(), - "/restore", - MenuTone::Normal, - ), - MenuRow::new( - "wipe", - "messages · identity and friends stay".to_string(), - "/wipe", - MenuTone::Normal, - ), - MenuRow::new( - "wipe-all", - "deletes your identity key · new person".to_string(), - "/wipe-all", - MenuTone::Normal, - ), - ]; - (wallet, settings) -} - -fn menu_tone_style(tone: MenuTone) -> Style { - match tone { - MenuTone::Normal => style_text(), - MenuTone::Dim => style_dim(), - MenuTone::Alert => style_alert(), - MenuTone::Stale => style_stale(), - } -} - /// Section header: the title in the accent, ruled off in the dim tone. The rule /// glyph degrades to `-` under `ONIONWIRE_ASCII` / `NO_COLOR`. fn menu_section_line(width: usize, title: &str) -> Line<'static> { @@ -4732,90 +4314,6 @@ fn menu_section_line(width: usize, title: &str) -> Line<'static> { ]) } -/// One row, padded out to exactly `width` cells: ` label value … keys`. -/// -/// The key column is right-aligned so the eye can run down it, and the value is -/// truncated (never allowed to push the key off the row) so no row can wrap, -/// clip or scroll at 80 columns. -fn menu_row_line(width: usize, row: &MenuRow) -> Line<'static> { - let head = format!(" {: Vec> { - let w = width as usize; - let (wallet, settings) = menu_groups(s); - let mut out = vec![menu_section_line(w, "WALLET")]; - out.extend(wallet.iter().map(|row| menu_row_line(w, row))); - out.push(Line::default()); - out.push(menu_section_line(w, "SETTINGS")); - out.extend(settings.iter().map(|row| menu_row_line(w, row))); - out -} - -/// The menu body as plain text, for width/needle assertions. -pub fn wallets_settings_menu_text(width: u16, s: &WalletMenuState) -> String { - wallets_settings_menu_lines(width, s) - .iter() - .map(|line| { - line.spans - .iter() - .map(|span| span.content.as_ref()) - .collect::() - }) - .collect::>() - .join("\n") -} - -/// WALLETS & SETTINGS: a full screen, never a popup — body plus the one status -/// line every other screen shares. `footer` is an already-built `status_footer` -/// line, so the caller owns TOR / identity / the transient note. -pub fn draw_wallets_settings(f: &mut Frame, state: &WalletMenuState, footer: &str) { - let area = f.area(); - let rows = Layout::vertical([Constraint::Min(3), Constraint::Length(1)]).split(area); - let inner = rows[0].width.saturating_sub(2); - f.render_widget( - Paragraph::new(wallets_settings_menu_lines(inner, state)) - .block(themed_block("(o) wallets & settings")), - rows[0], - ); - f.render_widget( - Paragraph::new(fit_cells(footer, area.width as usize)).style(style_dim()), - rows[1], - ); -} - // --------------------------------------------------------------------------- // F7 wallet setup: the RPC endpoint and the chain source, on screen. // @@ -4930,10 +4428,7 @@ pub fn wallet_setup_config_lines(width: u16, s: &WalletSetupConfigState) -> Vec< // same reason the login row names `ctrl-u`: at 80 columns the footer has // room for one group and the status line already spends half the width. out.push(Line::from( - Span::raw(fit_cells( - "keys ctrl-s save + start ctrl-x stop ctrl-r re-read", - w, - )) + Span::raw(fit_cells(wallet_setup_keys_line(), w)) .style(style_dim()), )); out.push(Line::from( @@ -4942,6 +4437,12 @@ pub fn wallet_setup_config_lines(width: u16, s: &WalletSetupConfigState) -> Vec< out } +/// The F7 line that names start. The screen renders this on the NODE section, +/// because at 80 columns the footer has no room for it. +pub fn wallet_setup_keys_line() -> &'static str { + "keys ctrl-s save + start ctrl-x stop ctrl-r re-read" +} + /// The F7 body as plain text, for width and needle assertions. pub fn wallet_setup_config_text(width: u16, s: &WalletSetupConfigState) -> String { wallet_setup_config_lines(width, s) @@ -5259,6 +4760,20 @@ pub fn peer_payments_lines(width: u16, height: u16, s: &PeerPaymentsState) -> Ve ]; } let peer = menu_cell_text(&s.peer); + // An empty peer is "no friend selected", not an empty history with a blank + // name. `p` opens this screen either way, so the frame always has a line. + if peer.is_empty() && s.rows.is_empty() { + return vec![ + Line::from(vec![Span::styled( + fit_cells(" no friend selected", w.max(1)), + style_dim(), + )]), + Line::from(vec![Span::styled( + fit_cells(" select a friend, then p", w.max(1)), + style_dim(), + )]), + ]; + } if s.rows.is_empty() { return vec![ Line::from(vec![Span::styled( @@ -6045,7 +5560,6 @@ fn draw_wallet( let cols = Layout::vertical([ Constraint::Length(2), Constraint::Min(4), - Constraint::Length(3), Constraint::Length(1), ]) .split(area); @@ -6057,20 +5571,10 @@ fn draw_wallet( cols[0], ); - let addr_line = if receive_addr.is_empty() { - "no address".into() - } else { - receive_addr.to_string() - }; - let body = format!( - "address - {addr_line} - -balance - {balance} -" - ); - let mut lines: Vec = body.lines().map(str::to_string).collect(); + let mut lines: Vec = wallet_screen_text(receive_addr, balance) + .lines() + .map(str::to_string) + .collect(); // Only rendered when a chain source is configured or a child was started, so // an unconfigured install shows the same screen it always did. if !child.is_empty() { @@ -6087,8 +5591,6 @@ balance lines.push(format!(" {} {} XMR", t.txid.chars().take(16).collect::(), xmr)); } } - let help = "c create i import r qr w wallets F7 node Esc back"; - lines.push("".into()); f.render_widget( Paragraph::new(lines.join("\n")) .style(style_text()) @@ -6097,7 +5599,24 @@ balance cols[1], ); - f.render_widget(Paragraph::new(help).style(style_dim()), cols[2]); + f.render_widget(Paragraph::new(wallet_screen_hint()).style(style_dim()), cols[2]); +} + +/// The wallet screen's receive and balance rows. The hint (`c create`) is drawn +/// under them; together they are what F6 shows. +pub fn wallet_screen_text(receive_addr: &str, balance: &str) -> String { + let addr_line = if receive_addr.is_empty() { + "no address" + } else { + receive_addr + }; + format!("address\n {addr_line}\n\nbalance\n {balance}\n") +} + +/// The hint the wallet screen prints. `c` creates, `F7` is the node. One source +/// so a test can pin the words the screen actually shows. +pub fn wallet_screen_hint() -> &'static str { + "c create i import r qr w wallets F7 node Esc back" } fn draw_wallet_setup(f: &mut Frame, setup: &WalletSetup) { @@ -6182,15 +5701,18 @@ mod function_key_tests { } } - /// The peer history's footer prints `F9 menu`, so F9 has to reach the menu - /// while that screen is open — not only from Main. + /// F9 was the menu. The peer-payments screen no longer names it, so it must + /// not answer it — a printed dead key is worse, and an unanswered key that + /// the footer does not name is the other half of the same rule. #[test] - fn f9_opens_the_menu_from_the_peer_payments_screen() { - assert_eq!( - function_key_for(&peer_payments_screen(), KeyCode::F(9)), - Some(FunctionKey::OpenMenu), - "the screen's footer names F9 but F9 does nothing there" + fn f9_is_not_a_key_on_peer_payments_or_main() { + assert!( + !peer_payments_footer_hint().contains("F9"), + "peer payments still prints F9: {}", + peer_payments_footer_hint() ); + assert_eq!(function_key_for(&peer_payments_screen(), KeyCode::F(9)), None); + assert_eq!(function_key_for(&Screen::Main, KeyCode::F(9)), None); } /// Copy and behaviour agree: every `F` the screen's own hint names must @@ -6215,30 +5737,29 @@ mod function_key_tests { "hint names F{number} ({hint:?}) but the screen does not answer it" ); } - assert!(named > 0, "the hint names no function key: {hint:?}"); + assert_eq!( + named, 0, + "peer payments names a function key it should not: {hint:?}" + ); } - /// The menu screen names `c` and `Esc`, not the function keys, but it is - /// the screen the `payments` row came from — its own keys stay its own. + /// The wallet screen prints `F7 node`. That key has to open the node screen, + /// and F9 — which this screen does not print — must not be answered. #[test] - fn function_keys_stay_live_on_the_wallets_settings_screen() { - let screen = Screen::WalletsSettings { - state: WalletMenuState::default(), + fn the_wallet_screen_answers_f7_and_not_the_removed_menu_key() { + let screen = Screen::Wallet { + receive_addr: String::new(), + balance: String::new(), + transfers: Vec::new(), + qr_modal: None, }; - for key in [ - KeyCode::F(2), - KeyCode::F(3), - KeyCode::F(4), - KeyCode::F(5), - KeyCode::F(6), - KeyCode::F(8), - KeyCode::F(9), - ] { - assert!( - function_key_for(&screen, key).is_some(), - "{key:?} is named on the menu but is not answered there" - ); - } + assert_eq!( + function_key_for(&screen, KeyCode::F(7)), + Some(FunctionKey::Setup) + ); + assert_eq!(function_key_for(&screen, KeyCode::F(9)), None); + assert!(wallet_screen_hint().contains("F7")); + assert!(wallet_screen_hint().contains("create")); } /// The wallet list names `Esc`, `j k` and `Enter`, no function key — so it @@ -7043,10 +6564,9 @@ mod wallet_offset_tests { } } -/// F7 (`/settings` → wallet setup, or the key anywhere the footer names it) is -/// the screen that puts the wallet RPC endpoint and the chain source in the -/// user's hands. These tests drive it through the real key path and the real -/// node, and read the frames the app actually paints. +/// F7 is the screen that puts the wallet RPC endpoint and the chain source in +/// the user's hands. These tests drive it through the real key path and the +/// real node, and read the frames the app actually paints. #[cfg(test)] mod wallet_setup_config_tests { use super::*; @@ -7450,39 +6970,108 @@ mod wallet_setup_config_tests { ); } - /// The never-no-op invariant: `F7` is named on Main, on the settings menu and - /// on peer payments, so it has to work on all three. + /// F7 is named on Main and on the wallet screen, so it opens the node there. + /// F9 is not a key. Peer payments does not name F7, so F7 must not leave it. #[test] - fn f7_is_live_on_the_three_screens_that_name_it() { + fn f7_is_live_where_it_is_named_and_f9_is_gone() { let dir = tempfile::tempdir().unwrap(); let (mut app, _rt) = app(&dir.path().join("home")); - // Main. app.handle_key(key(KeyCode::F(7))).expect("F7"); assert!(matches!(app.screen, Screen::WalletSetupConfig { .. })); app.handle_key(key(KeyCode::Esc)).expect("esc"); - // The settings menu, where `/settings` lands. app.handle_key(key(KeyCode::F(9))).expect("F9"); - assert!(matches!(app.screen, Screen::WalletsSettings { .. })); - app.handle_key(key(KeyCode::F(7))).expect("F7"); + assert!( + matches!(app.screen, Screen::Main), + "F9 must not open a menu" + ); + + app.handle_key(key(KeyCode::F(6))).expect("F6"); + assert!(matches!(app.screen, Screen::Wallet { .. })); + app.handle_key(key(KeyCode::F(7))).expect("F7 from wallet"); assert!( matches!(app.screen, Screen::WalletSetupConfig { .. }), - "F7 must not no-op on the settings menu" + "F7 is printed on the wallet screen and must open the node" ); app.handle_key(key(KeyCode::Esc)).expect("esc"); - // Peer payments (F9 then `p`), built directly: the roster is empty here. app.screen = Screen::PeerPayments { state: PeerPaymentsState::from_payments("alice".to_string(), &[]), }; app.handle_key(key(KeyCode::F(7))).expect("F7"); assert!( - matches!(app.screen, Screen::WalletSetupConfig { .. }), - "F7 must not no-op on peer payments" + matches!(app.screen, Screen::PeerPayments { .. }), + "peer payments does not name F7, so F7 must not leave it" ); } + /// `p` on the roster opens peer payments. With no friend, the frame says so + /// rather than sitting on Main with a note that the next paint can hide. + #[test] + fn p_on_the_roster_opens_peer_payments() { + let dir = tempfile::tempdir().unwrap(); + let (mut app, _rt) = app(&dir.path().join("home")); + app.focus = Pane::Roster; + app.handle_key(key(KeyCode::Char('p'))).expect("p"); + assert!(matches!(app.screen, Screen::PeerPayments { .. })); + let frame = frame_on(&app, 80, 24); + assert!( + frame.contains("no friend selected"), + "empty-friend line missing:\n{frame}" + ); + assert!(!frame.contains("F9"), "dead menu key on the payments frame:\n{frame}"); + + // The composer still types the letter. + app.handle_key(key(KeyCode::Esc)).expect("esc"); + app.focus = Pane::Composer; + app.handle_key(key(KeyCode::Char('p'))).expect("typed p"); + assert!(matches!(app.screen, Screen::Main)); + assert_eq!(app.composer, "p"); + } + + /// Real `App::draw` frames of the two screens that remain: the wallet and + /// the node. 80x24 is the floor, 120x40 the target. + #[test] + fn f6_and_f7_frames_fit_and_name_their_own_actions() { + let dir = tempfile::tempdir().unwrap(); + let (mut app, _rt) = app(&dir.path().join("home")); + + app.handle_key(key(KeyCode::F(6))).expect("F6"); + for (w, h) in [(80u16, 24u16), (120, 40)] { + let frame = frame_on(&app, w, h); + println!("===== F6 WALLET {w}x{h} =====\n{frame}"); + assert!(frame.contains("address"), "receive row missing at {w}x{h}:\n{frame}"); + assert!(frame.contains("balance"), "balance missing at {w}x{h}:\n{frame}"); + assert!(frame.contains("create"), "create missing at {w}x{h}:\n{frame}"); + assert!(!frame.contains("F9"), "menu key on the wallet frame:\n{frame}"); + for line in frame.lines() { + assert!( + cell_width(line) <= w as usize, + "F6 line wider than {w}: {line:?}" + ); + } + } + + app.handle_key(key(KeyCode::Esc)).expect("esc"); + app.handle_key(key(KeyCode::F(7))).expect("F7"); + for (w, h) in [(80u16, 24u16), (120, 40)] { + let frame = frame_on(&app, w, h); + println!("===== F7 NODE {w}x{h} =====\n{frame}"); + assert!( + frame.contains("ctrl-s"), + "start key missing at {w}x{h}:\n{frame}" + ); + assert!(!frame.contains("F9"), "menu key on the node frame:\n{frame}"); + for line in frame.lines() { + assert!( + cell_width(line) <= w as usize, + "F7 line wider than {w}: {line:?}" + ); + } + } + } + /// The login never leaves in a message: not in the frame, not in the app's /// status line, not in a `PingResult::line()`, and not through `Debug`. #[test] diff --git a/tests/tui_chrome.rs b/tests/tui_chrome.rs index 13bf224..c1632ac 100644 --- a/tests/tui_chrome.rs +++ b/tests/tui_chrome.rs @@ -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. diff --git a/tests/tui_payments.rs b/tests/tui_payments.rs index 9b59667..709675a 100644 --- a/tests/tui_payments.rs +++ b/tests/tui_payments.rs @@ -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:?}"); } } diff --git a/tests/tui_spec.rs b/tests/tui_spec.rs index a49b2fe..87d4887 100644 --- a/tests/tui_spec.rs +++ b/tests/tui_spec.rs @@ -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()); } -- 2.52.0