Merge pull request 'tui: drop the F9 menu that restates F6 and F7' (#178) from onionwire/t_7121b6ba-onionwire-tui-drop-the-menu-that-restate into main
Reviewed-on: #178
This commit is contained in:
commit
d89539e8b0
5 changed files with 391 additions and 1147 deletions
93
docs/TUI.md
93
docs/TUI.md
|
|
@ -25,15 +25,13 @@ ASCII chrome.
|
||||||
| `Wallet` | `F6` | Receive QR, balance, transfers |
|
| `Wallet` | `F6` | Receive QR, balance, transfers |
|
||||||
| `WalletSelect` | `F6` `w` | Saved wallets, pick one or create one |
|
| `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 |
|
| `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 |
|
| `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` |
|
| `Quit` | `Ctrl-Q` | Type `CLEAR` or `QUIT` |
|
||||||
|
|
||||||
Help (`?`) is an overlay, not a screen. `/who` / `F5` is an overlay on Main.
|
Help (`?`) is an overlay, not a screen. `/who` / `F5` is an overlay on Main.
|
||||||
|
|
||||||
Function keys that fire from Main, the settings menu, and
|
Function keys that fire from Main are:
|
||||||
peer-payments are:
|
|
||||||
|
|
||||||
| Key | `FunctionKey` | Action |
|
| Key | `FunctionKey` | Action |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
|
|
@ -44,33 +42,33 @@ peer-payments are:
|
||||||
| `F6` | Wallet | Wallet screen |
|
| `F6` | Wallet | Wallet screen |
|
||||||
| `F7` | Setup | Node & wallet setup: RPC endpoint, chain source, start/stop |
|
| `F7` | Setup | Node & wallet setup: RPC endpoint, chain source, start/stop |
|
||||||
| `F8` | RotatePrekey | Prekey hard cut |
|
| `F8` | RotatePrekey | Prekey hard cut |
|
||||||
| `F9` | OpenMenu | Wallets & settings |
|
|
||||||
|
|
||||||
`F9` is live on Main, the settings menu, and peer-payments so a printed shortcut
|
`F7` also fires on the wallet screen, which prints it. There is no `F9` and no
|
||||||
never no-ops there, and `F7` joins it for the same reason: `/settings` points at
|
`/settings`: that menu restated F6 and F7. A screen that does not name a
|
||||||
the setup screen. Other screens handle their own keys (Esc back, typed
|
function key does not answer one. Other screens handle their own keys (Esc
|
||||||
confirms).
|
back, typed confirms).
|
||||||
|
|
||||||
## Main
|
## Main
|
||||||
|
|
||||||
Focus starts on the composer. Footer hints (`main_footer_hints`):
|
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-specific (`pane_footer_hints`):
|
||||||
|
|
||||||
| Pane | Hint |
|
| Pane | Hint |
|
||||||
|---|---|
|
|---|---|
|
||||||
| Roster | `j k F3 add F6 wallet F7 setup F9 ? help` |
|
| Roster | `j k p pay F3 add F6 wallet F7 setup ? help` |
|
||||||
| Chat | `j k g G ends F4 rotate F7 setup F9 ? help` |
|
| Chat | `j k g G p pay F6 wallet F7 setup ? help` |
|
||||||
| Composer | `Enter send / commands F7 setup F9 ? 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
|
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
|
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
|
`main_footer_hints` never reaches an 80-column terminal. `F6` and `F7` are
|
||||||
in both, and the `F9` beside it is left bare so the whole hint still fits at 80.
|
therefore named in both, at the tail. `p` is named only on roster and chat:
|
||||||
|
the composer types the letter.
|
||||||
|
|
||||||
| Key | Action |
|
| 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 |
|
| `/file /path` | File send, 1 MiB, one-shot |
|
||||||
| `/wallet create` | Same as `F6` then `c` |
|
| `/wallet create` | Same as `F6` then `c` |
|
||||||
| `/wallet import` | Same as `F6` then `i` |
|
| `/wallet import` | Same as `F6` then `i` |
|
||||||
| `/settings` | Same as `F9` |
|
|
||||||
| `/backup /path` | Encrypted identity export |
|
| `/backup /path` | Encrypted identity export |
|
||||||
| `/restore /path` | Overwrite self keys |
|
| `/restore /path` | Overwrite self keys |
|
||||||
| `/wipe` | Type `WIPE` — chat/payments/outbox; identity stays |
|
| `/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`) |
|
| `F7` | Node & wallet setup (`WalletSetupConfig`) |
|
||||||
| Esc | Back to Main |
|
| Esc | Back to Main |
|
||||||
|
|
||||||
The child's state and the chain source are shown here (and on `F9`), but they are
|
The child's state and the chain source are shown here, but they are **set** on
|
||||||
**set** on `F7`: the start/stop/probe keys and the `1`/`2`/`3` in-process picker
|
`F7`: the start/stop/probe keys and the `1`/`2`/`3` in-process picker that used
|
||||||
that used to live on this screen are gone, so there is one place that configures
|
to live on this screen are gone, so there is one place that configures the chain.
|
||||||
the chain.
|
|
||||||
|
|
||||||
The chain line for an in-process source always carries
|
The chain line for an in-process source always carries
|
||||||
`testnet only — mainnet is unvalidated` (`cuprate::TESTNET_ONLY`). Starting
|
`testnet only — mainnet is unvalidated` (`cuprate::TESTNET_ONLY`). The default
|
||||||
Cuprate needs `--features cuprate-daemon`; without it, start fails with that
|
binary includes the in-process daemon. A build compiled without that feature
|
||||||
feature name.
|
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:
|
Create/import require the wallet RPC started with `--wallet-dir`. Filename:
|
||||||
`onionwire`. Seed is never collected on the composer.
|
`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
|
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
|
`?` 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.
|
`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`
|
Live from Main and from the wallet screen, which prints `F7 node`. Body is
|
||||||
row names `F7` as the key that edits it. Body is `WalletSetupConfigState`, a
|
`WalletSetupConfigState`, a snapshot taken when the screen opens — the render
|
||||||
snapshot taken when the screen opens — the render path never reads the store.
|
path never reads the store.
|
||||||
|
|
||||||
This is the only screen that sets up the chain: the wallet RPC endpoint, and the
|
This is the only screen that sets up the chain: the wallet RPC endpoint, and the
|
||||||
node that serves it.
|
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
|
traffic` — because that is the pick that moves chain trust off this box. The
|
||||||
address must parse as `host:port` first.
|
address must parse as `host:port` first.
|
||||||
|
|
||||||
A build without `cuprate-daemon` says so on the `chain` row, where the choice is
|
The default `onionwire` binary includes the in-process daemon. A build without
|
||||||
made, rather than offering it and refusing at start: the in-process wording is
|
that feature says so on the `chain` row, where the choice is made, rather than
|
||||||
followed by `this build has no in-process chain daemon — rebuild with --features
|
offering it and refusing at start: the in-process wording is followed by
|
||||||
cuprate-daemon` (`crate::cuprate::NO_FEATURE_MSG`, clamped to the frame width).
|
`NO_FEATURE_MSG` (clamped to the frame width). The pick is still offered — a
|
||||||
The pick is still offered — builds with the feature exist, and a stored
|
stored in-process source must still be readable — and that rebuild line appears
|
||||||
in-process source must still be readable.
|
only on a build that left the feature out.
|
||||||
|
|
||||||
Esc is the single exit and wipes the login buffer (`Zeroizing<String>`).
|
Esc is the single exit and wipes the login buffer (`Zeroizing<String>`).
|
||||||
|
|
||||||
## 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.
|
## Peer payments (`p` on Main)
|
||||||
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-scoped signed invoices and tips, not the wallet's own transfer list.
|
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)
|
## 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 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
|
cargo test --locked --test tui_select -- --nocapture wallet_select_frame_dumps
|
||||||
```
|
```
|
||||||
|
|
|
||||||
851
src/tui.rs
851
src/tui.rs
File diff suppressed because it is too large
Load diff
|
|
@ -49,8 +49,9 @@ fn help_overlay_lists_core_bindings() {
|
||||||
"F4",
|
"F4",
|
||||||
"F5",
|
"F5",
|
||||||
"F6",
|
"F6",
|
||||||
|
"F7",
|
||||||
"F8",
|
"F8",
|
||||||
"F9",
|
"p",
|
||||||
"send chat",
|
"send chat",
|
||||||
"/profile",
|
"/profile",
|
||||||
"/pay",
|
"/pay",
|
||||||
|
|
@ -61,7 +62,6 @@ fn help_overlay_lists_core_bindings() {
|
||||||
"/backup",
|
"/backup",
|
||||||
"/restore",
|
"/restore",
|
||||||
"/wipe-all",
|
"/wipe-all",
|
||||||
"/settings",
|
|
||||||
"Ctrl-Q",
|
"Ctrl-Q",
|
||||||
"?",
|
"?",
|
||||||
] {
|
] {
|
||||||
|
|
@ -182,29 +182,36 @@ fn pane_focus_cycles_roster_chat_composer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn menu_key_is_listed_in_help_and_in_the_main_footer() {
|
fn wallet_and_node_keys_are_listed_and_the_menu_key_is_not() {
|
||||||
// Discoverability: the WALLETS & SETTINGS menu has to be findable from the
|
// F6 is the wallet and F7 is the node. There is no second menu, so F9 and
|
||||||
// help overlay *and* from the main footer, or F9 is a secret.
|
// `/settings` must not be printed — a key that no longer exists is worse
|
||||||
|
// than a missing one.
|
||||||
let help = help_overlay_text();
|
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!(
|
assert!(
|
||||||
help.contains("/settings"),
|
!help.contains("F9"),
|
||||||
"/settings missing from help:\n{help}"
|
"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();
|
let hints = main_footer_hints();
|
||||||
assert!(
|
assert!(hints.contains("F6"), "F6 missing from footer hints: {hints:?}");
|
||||||
hints.contains("F9"),
|
assert!(hints.contains("F7"), "F7 missing from footer hints: {hints:?}");
|
||||||
"F9 missing from footer hints: {hints:?}"
|
assert!(!hints.contains("F9"), "F9 still in footer hints: {hints:?}");
|
||||||
);
|
|
||||||
let fp = "abcdef0123456789deadbeef";
|
let fp = "abcdef0123456789deadbeef";
|
||||||
let onion = "abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvwx.onion";
|
let onion = "abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvwx.onion";
|
||||||
for w in [80u16, 120, 200] {
|
for w in [80u16, 120, 200] {
|
||||||
let line = status_footer(w, fp, onion, None, hints);
|
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("? help"), "? help dropped at {w}: {line:?}");
|
||||||
assert!(line.contains("TOR"), "TOR dropped at {w}: {line:?}");
|
assert!(line.contains("TOR"), "TOR dropped at {w}: {line:?}");
|
||||||
assert!(
|
assert!(
|
||||||
line.chars().count() <= w as usize,
|
onionwire::tui::cell_width(&line) <= w as usize,
|
||||||
"footer wider than {w}: {line:?}"
|
"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("TOR"), "{compact:?}");
|
||||||
assert!(compact.contains("me:"), "{compact:?}");
|
assert!(compact.contains("me:"), "{compact:?}");
|
||||||
assert!(compact.contains("? help"), "{compact:?}");
|
assert!(compact.contains("? help"), "{compact:?}");
|
||||||
assert!(compact.chars().count() <= 80, "{compact:?}");
|
|
||||||
// The cells the onion gave up go to the hints.
|
|
||||||
assert!(
|
assert!(
|
||||||
compact.chars().count() > 0 && compact.contains("F9"),
|
onionwire::tui::cell_width(&compact) <= 80,
|
||||||
"compact footer lost the menu key: {compact:?}"
|
"{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]
|
#[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";
|
let fp = "abcdef0123456789deadbeef";
|
||||||
for pane in [Pane::Roster, Pane::Chat, Pane::Composer] {
|
for pane in [Pane::Roster, Pane::Chat, Pane::Composer] {
|
||||||
let hints = pane_footer_hints(pane);
|
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:?}");
|
assert!(hints.contains("? help"), "{pane:?} lost ? help: {hints:?}");
|
||||||
for w in [80u16, 120, 200] {
|
for w in [80u16, 120, 200] {
|
||||||
let line = status_footer_compact(w, fp, Some(TorPhase::Ready), None, hints);
|
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!(
|
assert!(
|
||||||
line.contains("? help"),
|
line.contains("? help"),
|
||||||
"{pane:?} at {w} lost ? help: {line:?}"
|
"{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.
|
// The hints actually change with the pane — that is the point of the lever.
|
||||||
|
|
|
||||||
|
|
@ -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
|
//! 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
|
//! of the TUI acts on: signed `/pay` invoices, `/tip` receipts and tips, with
|
||||||
|
|
@ -11,9 +11,9 @@
|
||||||
|
|
||||||
use onionwire::Payment;
|
use onionwire::Payment;
|
||||||
use onionwire::tui::{
|
use onionwire::tui::{
|
||||||
PeerPaymentRow, PeerPaymentsState, WalletMenuState, cell_width, draw_peer_payments,
|
Pane, PeerPaymentRow, PeerPaymentsState, cell_width, draw_peer_payments,
|
||||||
peer_payments_footer_hint, peer_payments_lines, peer_payments_text, status_footer,
|
main_opens_peer_payments, peer_payments_footer_hint, peer_payments_lines, peer_payments_text,
|
||||||
wallets_settings_menu_text,
|
status_footer,
|
||||||
};
|
};
|
||||||
use ratatui::Terminal;
|
use ratatui::Terminal;
|
||||||
use ratatui::backend::TestBackend;
|
use ratatui::backend::TestBackend;
|
||||||
|
|
@ -342,73 +342,38 @@ fn peer_payments_columns_drop_before_they_wrap() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn wallets_settings_menu_offers_the_peer_payments_row() {
|
fn peer_payments_opens_from_main_and_the_frame_is_the_history() {
|
||||||
let st = WalletMenuState {
|
use ratatui::crossterm::event::KeyCode;
|
||||||
transfers: 3,
|
|
||||||
peer: "lance".into(),
|
// The binding, not a menu row. Composer focus still types the letter.
|
||||||
peer_payments: Some(3),
|
assert!(main_opens_peer_payments(Pane::Roster, KeyCode::Char('p')));
|
||||||
..menu_state_defaults()
|
assert!(main_opens_peer_payments(Pane::Chat, KeyCode::Char('p')));
|
||||||
};
|
assert!(!main_opens_peer_payments(Pane::Composer, KeyCode::Char('p')));
|
||||||
let body = wallets_settings_menu_text(78, &st);
|
|
||||||
let row = body
|
let history = render(80, 24, &peer_state());
|
||||||
.lines()
|
assert!(history.contains("lance"), "peer missing:\n{history}");
|
||||||
.find(|l| l.contains("payments"))
|
assert!(history.contains("lunch money"), "history missing:\n{history}");
|
||||||
.expect("payments row");
|
assert!(history.contains("payments"), "title missing:\n{history}");
|
||||||
assert!(row.contains("lance"), "row does not name the peer: {row:?}");
|
// Not a menu row named `payments` beside a key column.
|
||||||
assert!(row.contains('p'), "row does not name its key: {row:?}");
|
assert!(!history.contains("F9"));
|
||||||
// The wallet's own transfer list keeps its F6 row; it is retitled so the
|
assert!(!history.lines().any(|l| l.contains("F7 ctrl")));
|
||||||
// two histories cannot be mistaken for each other.
|
|
||||||
assert!(
|
let empty = render(
|
||||||
body.lines().any(|l| l.contains("transfers")),
|
80,
|
||||||
"wallet transfer row lost:\n{body}"
|
24,
|
||||||
|
&PeerPaymentsState {
|
||||||
|
peer: String::new(),
|
||||||
|
rows: Vec::new(),
|
||||||
|
error: None,
|
||||||
|
selected: 0,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
assert!(
|
||||||
// No friend selected: the row is dim and offers no key that would do
|
empty.contains("no friend selected"),
|
||||||
// nothing.
|
"empty-friend line missing:\n{empty}"
|
||||||
let st = WalletMenuState {
|
);
|
||||||
peer: String::new(),
|
for line in empty.lines().chain(history.lines()) {
|
||||||
peer_payments: None,
|
assert!(cell_width(line) <= 80, "wider than 80: {line:?}");
|
||||||
..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,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,11 @@ use onionwire::Message;
|
||||||
use onionwire::outbox::{OutboxEntry, OutboxStatus};
|
use onionwire::outbox::{OutboxEntry, OutboxStatus};
|
||||||
use onionwire::qr;
|
use onionwire::qr;
|
||||||
use onionwire::tui::{
|
use onionwire::tui::{
|
||||||
OutboxSummary, SlashCmd, TorPhase, WalletMenuState, alert_line, ascii_chrome, cell_width,
|
OutboxSummary, alert_line, ascii_chrome, cell_width, chat_with_delivery, delivery_tag,
|
||||||
chat_with_delivery, delivery_tag, draw_chat, draw_share, draw_text_overlay,
|
draw_chat, draw_share, draw_text_overlay, empty_friend_chat_text,
|
||||||
draw_wallets_settings, empty_friend_chat_text, fit_cells, help_overlay_text, main_footer_hints,
|
help_overlay_text, main_footer_hints, main_header_line, osc52_copy_sequence, parse_cmd,
|
||||||
main_header_line, osc52_copy_sequence, parse_cmd, paste_screen_text, retry_in_text,
|
paste_screen_text, retry_in_text, roster_col_width, short_send_reason, status_footer,
|
||||||
roster_col_width, short_send_reason, status_footer, status_footer_phased,
|
wallet_screen_hint, wallet_screen_text, wallet_setup_keys_line, wrap_invite,
|
||||||
wallets_settings_footer_hint, wallets_settings_menu_lines, wallets_settings_menu_text,
|
|
||||||
wrap_invite,
|
|
||||||
};
|
};
|
||||||
use ratatui::Frame;
|
use ratatui::Frame;
|
||||||
use ratatui::Terminal;
|
use ratatui::Terminal;
|
||||||
|
|
@ -23,6 +21,8 @@ use std::sync::Mutex;
|
||||||
const FP: &str = "abcdef0123456789deadbeefcafebabe";
|
const FP: &str = "abcdef0123456789deadbeefcafebabe";
|
||||||
static ASCII_ENV: Mutex<()> = Mutex::new(());
|
static ASCII_ENV: Mutex<()> = Mutex::new(());
|
||||||
const ONION: &str = "abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvwx.onion";
|
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 {
|
fn screen_from(buf: &ratatui::buffer::Buffer, w: u16, h: u16) -> String {
|
||||||
let mut screen = String::new();
|
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
|
/// Those labels are not a second menu. F6 still shows the receive address,
|
||||||
/// not load-bearing, only that it is far wider than the value column).
|
/// the balance and create. F7 still names start (`ctrl-s`).
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn wallets_settings_menu_frame_shows_the_shipped_footer() {
|
fn wallet_and_node_are_the_screens_not_a_second_menu() {
|
||||||
// Both sides of the assertion read the process environment through
|
let help = help_overlay_text();
|
||||||
// `ascii_chrome()` / `color_mode()` (glyphs and alert ornaments), so this
|
for gone in ["F9", "/settings", "wallets & settings", "F7 ctrl-s/x"] {
|
||||||
// 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",
|
|
||||||
] {
|
|
||||||
assert!(
|
assert!(
|
||||||
body.contains(needle),
|
!help.contains(gone),
|
||||||
"WALLET row {needle:?} missing:\n{body}"
|
"help still restates a menu ({gone:?}):\n{help}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for needle in [
|
// Composer commands that were only named on the menu stay named in help.
|
||||||
"nickname", "profile", "identity", "colour", "backup", "restore", "wipe",
|
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!(
|
assert!(
|
||||||
body.contains(needle),
|
cell_width(line) <= 78,
|
||||||
"SETTINGS row {needle:?} missing:\n{body}"
|
"wallet body wider than the inner 80-column pane: {line:?}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Every actionable row names the key or command that fires it, including the
|
assert!(cell_width(wallet_screen_hint()) <= 78);
|
||||||
// keys that now live on F7, so the menu teaches the shortcuts it sits beside
|
assert!(cell_width(wallet_setup_keys_line()) <= 78);
|
||||||
// instead of hiding them. A row must never name a key that no longer works:
|
for w in [80u16, 120, 200] {
|
||||||
// `F6 s/x` and `F6 p` moved to `F7 ctrl-s/x` and `F7 ctrl-r` with the node
|
let line = status_footer(w, FP, ONION, None, main_footer_hints());
|
||||||
// screen, and naming the dead keys here is how they would keep looking live.
|
assert!(cell_width(&line) <= w as usize, "{w}: {line:?}");
|
||||||
for key in [
|
assert!(line.contains("F6"), "F6 dropped at {w}: {line:?}");
|
||||||
"F7 ctrl-s/x",
|
assert!(line.contains("F7"), "F7 dropped at {w}: {line:?}");
|
||||||
"F7 ctrl-r",
|
assert!(!line.contains("F9"), "F9 still rendered at {w}: {line:?}");
|
||||||
"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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1332,11 +1025,11 @@ fn osc52_copy_sequence_is_a_base64_clipboard_write() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn slash_settings_is_the_menu() {
|
fn settings_is_not_a_command_and_the_composer_commands_stay() {
|
||||||
assert!(matches!(parse_cmd("/settings"), Some(SlashCmd::Settings)));
|
assert!(parse_cmd("/settings").is_none(), "/settings must not open a menu");
|
||||||
assert!(matches!(
|
assert!(parse_cmd(" /settings ").is_none());
|
||||||
parse_cmd(" /settings "),
|
assert!(parse_cmd("/profile").is_some());
|
||||||
Some(SlashCmd::Settings)
|
assert!(parse_cmd("/wipe").is_some());
|
||||||
));
|
assert!(parse_cmd("/wipe-all").is_some());
|
||||||
assert!(parse_cmd("/settings now").is_none());
|
assert!(parse_cmd("/wallet create").is_some());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue