tui: F9 works on the peer-payments screen, and frames dump the real footer
Review round 1 on the F9 `payments` row found two false affordances. 1. `footer_hints(Screen::PeerPayments)` prints `F9 menu`, and docs/TUI.md says F9 reopens the menu, but the `KeyCode::F(9)` arm opened it only from `Screen::Main`, so pressing F9 on the peer history did nothing. The function keys are now routed through one table, `function_key_for(screen, code)`, and the F9 arm no longer has the Main-only guard: it opens (or reopens) the menu from `Main`, `WalletsSettings` and `PeerPayments`. A screen that names a key has to answer it while it is open — that is what the table encodes, and `mod function_key_tests` locks it, including a test that reads the screen's own hint and asserts every `F<n>` it names is answered there. 2. The PR's frame dumps passed `"Esc back up/down select ? help"` to `status_footer` by hand, so every dumped frame showed a footer the app never renders. `peer_payments_footer_hint()` is now the single source both `footer_hints` and the fixture read, and `peer_payments_frame_shows_the_shipped_footer` pins the dumped frame's last line to the shipped one. Also restores the rustfmt-only reflow of unrelated tests in `tests/tui_spec.rs` (`queued_row`, a `failed_row` call, `rgb_tokens_…`, `alert_line_…`), keeping this card's real edits there. Presentation only: no wire, store, session, send-path or `Node` change.
This commit is contained in:
parent
2fa3466019
commit
b8fefe9c18
4 changed files with 185 additions and 54 deletions
|
|
@ -749,6 +749,12 @@ dumps the screen at 80x24, 120x40 and 200x60, populated and empty.
|
||||||
- The focused row is marked with `>` **and** bold, so focus survives a
|
- The focused row is marked with `>` **and** bold, so focus survives a
|
||||||
monochrome terminal. `up`/`down` (or `k`/`j`) move it, `Esc` returns to the
|
monochrome terminal. `up`/`down` (or `k`/`j`) move it, `Esc` returns to the
|
||||||
main screen, `F9` reopens the menu.
|
main screen, `F9` reopens the menu.
|
||||||
|
- `F9` is honoured **while this screen is open**, not only from the main screen:
|
||||||
|
the function-key table (`function_key_for`) answers it from `Main`,
|
||||||
|
`WalletsSettings` and `PeerPayments` alike, so the hint the screen prints
|
||||||
|
cannot be a no-op there. `peer_payments_footer_hint()` is the single place that
|
||||||
|
hint string is written, and the frame-dump fixture is driven from it — a dumped
|
||||||
|
frame cannot show a footer the app does not render.
|
||||||
- The selected row's `tx` and `addr` are spelled out under the rows: a 64-hex
|
- The selected row's `tx` and `addr` are spelled out under the rows: a 64-hex
|
||||||
txid is unusable truncated, and a 95-character base58 address is **wrapped**
|
txid is unusable truncated, and a 95-character base58 address is **wrapped**
|
||||||
over two lines rather than clipped to a prefix.
|
over two lines rather than clipped to a prefix.
|
||||||
|
|
|
||||||
187
src/tui.rs
187
src/tui.rs
|
|
@ -1257,6 +1257,44 @@ enum WalletSetup {
|
||||||
ImportPass { seed: Zeroizing<String>, entry: PassphraseEntry },
|
ImportPass { seed: Zeroizing<String>, entry: PassphraseEntry },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A function key the TUI answers before the per-screen `match`; the screen's
|
||||||
|
/// own key handler never sees it.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
enum FunctionKey {
|
||||||
|
Share,
|
||||||
|
Paste,
|
||||||
|
Rotate,
|
||||||
|
Who,
|
||||||
|
Wallet,
|
||||||
|
RotatePrekey,
|
||||||
|
OpenMenu,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The function key `screen` answers, or `None` when the key belongs to the
|
||||||
|
/// per-screen handler.
|
||||||
|
///
|
||||||
|
/// 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.
|
||||||
|
fn function_key_for(screen: &Screen, code: KeyCode) -> Option<FunctionKey> {
|
||||||
|
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(8) => Some(FunctionKey::RotatePrekey),
|
||||||
|
KeyCode::F(9) => Some(FunctionKey::OpenMenu),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
fn new(node: Arc<Node>, rt: tokio::runtime::Handle) -> Result<Self, String> {
|
fn new(node: Arc<Node>, rt: tokio::runtime::Handle) -> Result<Self, String> {
|
||||||
let friends = node.list_friends()?;
|
let friends = node.list_friends()?;
|
||||||
|
|
@ -1345,53 +1383,37 @@ impl App {
|
||||||
let mut payments_move = 0i32;
|
let mut payments_move = 0i32;
|
||||||
|
|
||||||
// The function-key shortcuts stay live on the WALLETS & SETTINGS screen
|
// The function-key shortcuts stay live on the WALLETS & SETTINGS screen
|
||||||
// too: that screen's whole point is naming the key that fires each row,
|
// and the peer history too: the settings screen's whole point is naming
|
||||||
// so a key it names has to work while it is open.
|
// the key that fires each row, and the history's footer names `F9
|
||||||
if matches!(
|
// menu`, so a key a screen names has to work while it is open.
|
||||||
self.screen,
|
if let Some(fk) = function_key_for(&self.screen, key.code) {
|
||||||
Screen::Main | Screen::WalletsSettings { .. } | Screen::PeerPayments { .. }
|
match fk {
|
||||||
) {
|
FunctionKey::Share => self.open_share()?,
|
||||||
match key.code {
|
FunctionKey::Paste => {
|
||||||
KeyCode::F(2) => {
|
|
||||||
self.open_share()?;
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
KeyCode::F(3) => {
|
|
||||||
self.screen = Screen::Paste {
|
self.screen = Screen::Paste {
|
||||||
buf: String::new(),
|
buf: String::new(),
|
||||||
err: None,
|
err: None,
|
||||||
};
|
};
|
||||||
return Ok(None);
|
|
||||||
}
|
}
|
||||||
KeyCode::F(4) => {
|
FunctionKey::Rotate => {
|
||||||
self.screen = Screen::Rotate {
|
self.screen = Screen::Rotate {
|
||||||
prompt: RotatePrompt::new(),
|
prompt: RotatePrompt::new(),
|
||||||
};
|
};
|
||||||
return Ok(None);
|
|
||||||
}
|
}
|
||||||
KeyCode::F(5) => {
|
FunctionKey::Who => self.who_open = true,
|
||||||
self.who_open = true;
|
FunctionKey::Wallet => self.open_wallet()?,
|
||||||
return Ok(None);
|
FunctionKey::RotatePrekey => {
|
||||||
}
|
|
||||||
KeyCode::F(6) => {
|
|
||||||
self.open_wallet()?;
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
KeyCode::F(8) => {
|
|
||||||
self.screen = Screen::RotatePrekey {
|
self.screen = Screen::RotatePrekey {
|
||||||
prompt: RotatePrompt::new(),
|
prompt: RotatePrompt::new(),
|
||||||
};
|
};
|
||||||
return Ok(None);
|
|
||||||
}
|
}
|
||||||
KeyCode::F(9) => {
|
// One level above the screen it is pressed on: F9 from Main
|
||||||
if matches!(self.screen, Screen::Main) {
|
// opens the menu, and from the menu or the peer history it
|
||||||
self.open_wallets_settings()?;
|
// reopens it rather than silently doing nothing.
|
||||||
|
FunctionKey::OpenMenu => self.open_wallets_settings()?,
|
||||||
}
|
}
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match &mut self.screen {
|
match &mut self.screen {
|
||||||
Screen::Main => match key.code {
|
Screen::Main => match key.code {
|
||||||
|
|
@ -2803,11 +2825,20 @@ match screen {
|
||||||
Screen::WalletSetup(WalletSetup::CreateSeed { .. }) => "type SEEN Esc cancel ? help",
|
Screen::WalletSetup(WalletSetup::CreateSeed { .. }) => "type SEEN Esc cancel ? help",
|
||||||
Screen::WalletSetup(WalletSetup::ImportSeed { .. }) => "paste seed Enter Esc ? help",
|
Screen::WalletSetup(WalletSetup::ImportSeed { .. }) => "paste seed Enter Esc ? help",
|
||||||
Screen::WalletsSettings { .. } => "Esc back c copy ? help",
|
Screen::WalletsSettings { .. } => "Esc back c copy ? help",
|
||||||
Screen::PeerPayments { .. } => "Esc back up/down select F9 menu ? help",
|
Screen::PeerPayments { .. } => peer_payments_footer_hint(),
|
||||||
Screen::Quit { .. } => "CLEAR or QUIT then Enter Esc cancel ? help",
|
Screen::Quit { .. } => "CLEAR or QUIT then Enter Esc cancel ? help",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The hint line the peer-payment-history screen prints. One source only: the
|
||||||
|
/// screen's frame tests build their fixture from this, so a dumped frame can
|
||||||
|
/// never show a footer the app does not render.
|
||||||
|
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";
|
||||||
|
|
||||||
fn apply_chrome_borders(block: Block<'_>) -> Block<'_> {
|
fn apply_chrome_borders(block: Block<'_>) -> Block<'_> {
|
||||||
let block = block.borders(Borders::ALL);
|
let block = block.borders(Borders::ALL);
|
||||||
if ascii_chrome() {
|
if ascii_chrome() {
|
||||||
|
|
@ -4105,6 +4136,98 @@ fn io_err(e: io::Error) -> String {
|
||||||
e.to_string()
|
e.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod function_key_tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn peer_payments_screen() -> Screen {
|
||||||
|
Screen::PeerPayments {
|
||||||
|
state: PeerPaymentsState::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The peer history's footer prints `F9 menu`, so F9 has to reach the menu
|
||||||
|
/// while that screen is open — not only from Main.
|
||||||
|
#[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"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Copy and behaviour agree: every `F<n>` the screen's own hint names must
|
||||||
|
/// be a key the screen answers. This is the test the defect class needs —
|
||||||
|
/// the hint string and the routing table are the two halves of the claim.
|
||||||
|
#[test]
|
||||||
|
fn every_function_key_named_by_the_peer_payments_hint_is_answered_there() {
|
||||||
|
let hint = peer_payments_footer_hint();
|
||||||
|
let screen = peer_payments_screen();
|
||||||
|
let mut named = 0;
|
||||||
|
for (at, _) in hint.match_indices('F') {
|
||||||
|
let digits: String = hint[at + 1..]
|
||||||
|
.chars()
|
||||||
|
.take_while(char::is_ascii_digit)
|
||||||
|
.collect();
|
||||||
|
let Ok(number) = digits.parse::<u8>() else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
named += 1;
|
||||||
|
assert!(
|
||||||
|
function_key_for(&screen, KeyCode::F(number)).is_some(),
|
||||||
|
"hint names F{number} ({hint:?}) but the screen does not answer it"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
assert!(named > 0, "the hint names no function key: {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.
|
||||||
|
#[test]
|
||||||
|
fn function_keys_stay_live_on_the_wallets_settings_screen() {
|
||||||
|
let screen = Screen::WalletsSettings {
|
||||||
|
state: WalletMenuState::default(),
|
||||||
|
};
|
||||||
|
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"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A screen that names no function key keeps the key to itself: the
|
||||||
|
/// composer's `F`-less screens must not steal F-keys they never advertise.
|
||||||
|
#[test]
|
||||||
|
fn screens_that_name_no_function_key_do_not_answer_one() {
|
||||||
|
for screen in [
|
||||||
|
Screen::Paste {
|
||||||
|
buf: String::new(),
|
||||||
|
err: None,
|
||||||
|
},
|
||||||
|
Screen::WalletSetup(WalletSetup::ImportSeed {
|
||||||
|
buf: Zeroizing::new(String::new()),
|
||||||
|
}),
|
||||||
|
] {
|
||||||
|
for key in [KeyCode::F(9), KeyCode::F(6)] {
|
||||||
|
assert!(
|
||||||
|
function_key_for(&screen, key).is_none(),
|
||||||
|
"{key:?} was answered on a screen that never names it"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod passphrase_buffer_tests {
|
mod passphrase_buffer_tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@
|
||||||
use onionwire::Payment;
|
use onionwire::Payment;
|
||||||
use onionwire::tui::{
|
use onionwire::tui::{
|
||||||
PeerPaymentRow, PeerPaymentsState, WalletMenuState, cell_width, draw_peer_payments,
|
PeerPaymentRow, PeerPaymentsState, WalletMenuState, cell_width, draw_peer_payments,
|
||||||
peer_payments_lines, peer_payments_text, status_footer, wallets_settings_menu_text,
|
peer_payments_footer_hint, peer_payments_lines, peer_payments_text, status_footer,
|
||||||
|
wallets_settings_menu_text,
|
||||||
};
|
};
|
||||||
use ratatui::Terminal;
|
use ratatui::Terminal;
|
||||||
use ratatui::backend::TestBackend;
|
use ratatui::backend::TestBackend;
|
||||||
|
|
@ -59,7 +60,9 @@ fn peer_state() -> PeerPaymentsState {
|
||||||
fn render(w: u16, h: u16, st: &PeerPaymentsState) -> String {
|
fn render(w: u16, h: u16, st: &PeerPaymentsState) -> String {
|
||||||
let backend = TestBackend::new(w, h);
|
let backend = TestBackend::new(w, h);
|
||||||
let mut terminal = Terminal::new(backend).expect("terminal");
|
let mut terminal = Terminal::new(backend).expect("terminal");
|
||||||
let footer = status_footer(w, FP, ONION, None, "Esc back up/down select ? help");
|
// The same two calls the app makes, so a dumped frame can never show a
|
||||||
|
// footer (or a hint) the app does not render.
|
||||||
|
let footer = status_footer(w, FP, ONION, None, peer_payments_footer_hint());
|
||||||
terminal
|
terminal
|
||||||
.draw(|f| draw_peer_payments(f, st, &footer))
|
.draw(|f| draw_peer_payments(f, st, &footer))
|
||||||
.expect("draw");
|
.expect("draw");
|
||||||
|
|
@ -74,6 +77,18 @@ fn render(w: u16, h: u16, st: &PeerPaymentsState) -> String {
|
||||||
screen
|
screen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn peer_payments_frame_shows_the_shipped_footer() {
|
||||||
|
let shipped = status_footer(80, FP, ONION, None, peer_payments_footer_hint());
|
||||||
|
let frame = render(80, 24, &peer_state());
|
||||||
|
let last = frame.lines().nth(23).unwrap_or_default();
|
||||||
|
assert_eq!(
|
||||||
|
last.trim_end(),
|
||||||
|
shipped.trim_end(),
|
||||||
|
"the dumped frame's footer is not the one the app renders"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn peer_payments_lists_every_required_field() {
|
fn peer_payments_lists_every_required_field() {
|
||||||
let body = peer_payments_text(78, 21, &peer_state());
|
let body = peer_payments_text(78, 21, &peer_state());
|
||||||
|
|
|
||||||
|
|
@ -429,14 +429,7 @@ fn pending_row(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn queued_row(message_id: i64, body: &str, attempts: u32, next_in: i64, now: i64) -> OutboxEntry {
|
fn queued_row(message_id: i64, body: &str, attempts: u32, next_in: i64, now: i64) -> OutboxEntry {
|
||||||
pending_row(
|
pending_row(message_id, body, OutboxStatus::Queued, attempts, next_in, now)
|
||||||
message_id,
|
|
||||||
body,
|
|
||||||
OutboxStatus::Queued,
|
|
||||||
attempts,
|
|
||||||
next_in,
|
|
||||||
now,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sending_row(message_id: i64, body: &str, now: i64) -> OutboxEntry {
|
fn sending_row(message_id: i64, body: &str, now: i64) -> OutboxEntry {
|
||||||
|
|
@ -562,12 +555,7 @@ fn delivery_markers_have_exercised_ascii_fallbacks() {
|
||||||
in_msg(5, "epsilon"),
|
in_msg(5, "epsilon"),
|
||||||
];
|
];
|
||||||
let pending = vec![
|
let pending = vec![
|
||||||
failed_row(
|
failed_row(1, "alpha", "connect peer.onion:80: connection timed out", now),
|
||||||
1,
|
|
||||||
"alpha",
|
|
||||||
"connect peer.onion:80: connection timed out",
|
|
||||||
now,
|
|
||||||
),
|
|
||||||
queued_row(2, "beta", 1, 30, now),
|
queued_row(2, "beta", 1, 30, now),
|
||||||
sending_row(3, "gamma", now),
|
sending_row(3, "gamma", now),
|
||||||
];
|
];
|
||||||
|
|
@ -853,7 +841,9 @@ fn rgb_tokens_resolve_to_palette_fg() {
|
||||||
assert_eq!(t.highlight.fg, Some(Color::Rgb(232, 165, 75)));
|
assert_eq!(t.highlight.fg, Some(Color::Rgb(232, 165, 75)));
|
||||||
assert_eq!(t.highlight.bg, Some(Color::Rgb(48, 42, 28)));
|
assert_eq!(t.highlight.bg, Some(Color::Rgb(48, 42, 28)));
|
||||||
assert!(
|
assert!(
|
||||||
t.highlight.add_modifier.contains(Modifier::BOLD),
|
t.highlight
|
||||||
|
.add_modifier
|
||||||
|
.contains(Modifier::BOLD),
|
||||||
"RGB highlight must be bold"
|
"RGB highlight must be bold"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -916,10 +906,7 @@ fn alert_line_prefixes_when_no_color() {
|
||||||
let _guard = std::env::var_os("NO_COLOR");
|
let _guard = std::env::var_os("NO_COLOR");
|
||||||
unsafe { std::env::set_var("NO_COLOR", "1") };
|
unsafe { std::env::set_var("NO_COLOR", "1") };
|
||||||
let line = alert_line("peer down", 80);
|
let line = alert_line("peer down", 80);
|
||||||
assert!(
|
assert!(line.starts_with("! "), "expected '! ' prefix in None mode: {line:?}");
|
||||||
line.starts_with("! "),
|
|
||||||
"expected '! ' prefix in None mode: {line:?}"
|
|
||||||
);
|
|
||||||
unsafe {
|
unsafe {
|
||||||
match _guard {
|
match _guard {
|
||||||
Some(v) => std::env::set_var("NO_COLOR", v),
|
Some(v) => std::env::set_var("NO_COLOR", v),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue