tui: F9 works on the peer-payments screen, and frames dump the real footer
Some checks failed
ci / test (pull_request) Successful in 6m33s
ci / sdk (pull_request) Successful in 1m31s
ci / fuzz (pull_request) Successful in 4m49s
android-ci / android (pull_request) Has been cancelled

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:
agent 2026-09-19 00:31:42 -04:00
commit b8fefe9c18
No known key found for this signature in database
4 changed files with 185 additions and 54 deletions

View file

@ -1257,6 +1257,44 @@ enum WalletSetup {
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 {
fn new(node: Arc<Node>, rt: tokio::runtime::Handle) -> Result<Self, String> {
let friends = node.list_friends()?;
@ -1345,52 +1383,36 @@ impl App {
let mut payments_move = 0i32;
// 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,
// so a key it names has to work while it is open.
if matches!(
self.screen,
Screen::Main | Screen::WalletsSettings { .. } | Screen::PeerPayments { .. }
) {
match key.code {
KeyCode::F(2) => {
self.open_share()?;
return Ok(None);
}
KeyCode::F(3) => {
// 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.
if let Some(fk) = function_key_for(&self.screen, key.code) {
match fk {
FunctionKey::Share => self.open_share()?,
FunctionKey::Paste => {
self.screen = Screen::Paste {
buf: String::new(),
err: None,
};
return Ok(None);
}
KeyCode::F(4) => {
FunctionKey::Rotate => {
self.screen = Screen::Rotate {
prompt: RotatePrompt::new(),
};
return Ok(None);
}
KeyCode::F(5) => {
self.who_open = true;
return Ok(None);
}
KeyCode::F(6) => {
self.open_wallet()?;
return Ok(None);
}
KeyCode::F(8) => {
FunctionKey::Who => self.who_open = true,
FunctionKey::Wallet => self.open_wallet()?,
FunctionKey::RotatePrekey => {
self.screen = Screen::RotatePrekey {
prompt: RotatePrompt::new(),
};
return Ok(None);
}
KeyCode::F(9) => {
if matches!(self.screen, Screen::Main) {
self.open_wallets_settings()?;
}
return Ok(None);
}
_ => {}
// 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);
}
match &mut self.screen {
@ -2803,11 +2825,20 @@ match screen {
Screen::WalletSetup(WalletSetup::CreateSeed { .. }) => "type SEEN Esc cancel ? help",
Screen::WalletSetup(WalletSetup::ImportSeed { .. }) => "paste seed Enter Esc ? 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",
}
}
/// 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<'_> {
let block = block.borders(Borders::ALL);
if ascii_chrome() {
@ -4105,6 +4136,98 @@ fn io_err(e: io::Error) -> 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)]
mod passphrase_buffer_tests {
use super::*;