2026-09-12 00:15:19 -04:00
//! Spec implementation tests for docs/TUI.md (this card).
//! Does not own `tests/tui_frames.rs` (PR #23).
2026-09-12 14:22:38 -04:00
use onionwire ::Message ;
use onionwire ::outbox ::{ OutboxEntry , OutboxStatus } ;
2026-09-12 00:54:16 -04:00
use onionwire ::qr ;
2026-09-12 00:15:19 -04:00
use onionwire ::tui ::{
2026-09-19 01:18:47 -04:00
OutboxSummary , SlashCmd , TorPhase , WalletMenuState , alert_line , ascii_chrome , cell_width ,
tui: peer payment history behind the F9 `payments` row (key p)
The F9 / `/settings` menu's only payment row showed the wallet's own transfer
list (`Node::wallet_recent_transfers`, F6). The signed `/pay` invoices and
`/tip` receipts a peer sent live in the `payments` table and had no path from
the TUI, so they were invisible. `Node::list_payments` (PR #119) closes that
gap; this wires it into a screen.
- `Screen::PeerPayments { state }` + `PeerPaymentsState` /
`PeerPaymentRow`, built by `PeerPaymentsState::from_payments` from
`Node::list_payments`' rows (newest first: the store returns `payments.id`
ascending, the screen windows the vector).
- Key handler: `p` on the F9 screen opens it (`open_peer_payments`); `up`/`down`
(or `k`/`j`) move the selection, `Esc` goes back, `F9` reopens the menu.
- Rows carry direction, kind, amount (`pay::atomic_to_xmr_str`, the same
piconero formatter the chat lines use), memo (sanitized at draw time) and the
receipt's `verified` / `unverified` word; the focused row is marked with `>`
and bold. The selected row's txid and address sit under the rows — the
address wrapped over two lines rather than clipped.
- States: populated, `no payments with {peer}`, `could not read payments`, and
a menu row that refuses when no friend is selected. An empty history is a
state, never an error.
- Menu: the wallet's own list is retitled `transfers` (F6, unchanged), and the
new `payments` row (key `p`) names the peer and the count. Two histories, two
rows, no ambiguity.
- Widths are measured in cells (`Span::width`); trailing columns are dropped
before they can wrap, so the body fits 80x24 (20 inner rows of 21) as well as
120x40 and 200x60.
Tests: new `tests/tui_payments.rs` (11 tests) dumps and asserts the screen at
80x24, 120x40 and 200x60 including the empty history, asserts a memo carrying
ESC/BEL/C1/bidi/newline bytes never reaches the frame buffer, and asserts the
window/column invariants for every width from 20 to 200.
Also relaxes one width assertion in `tests/tui_spec.rs`: `fit_cells` was
asserted to start with `"abcdef"`, which only holds when another test's
in-flight `ONIONWIRE_ASCII` mutation is not visible — the suite mutates env vars
without a global lock, so that test flaked (it also fails on an unmodified tree,
1 run in 2). It now accepts either chrome's cut point, which is what the comment
already claimed.
Docs: `docs/TUI.md` gains the screen's section, the retitled/replaced rows and
the updated row count; the "peer payment history" gap entry is closed.
2026-09-18 23:53:10 -04:00
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 ,
2026-09-19 01:18:47 -04:00
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 ,
2026-09-12 00:15:19 -04:00
} ;
use ratatui ::Frame ;
use ratatui ::Terminal ;
use ratatui ::backend ::TestBackend ;
use ratatui ::layout ::{ Constraint , Layout } ;
use ratatui ::widgets ::{ Block , Borders , List , ListItem , Paragraph , Wrap } ;
2026-09-12 00:54:16 -04:00
use std ::sync ::Mutex ;
2026-09-12 00:15:19 -04:00
const FP : & str = " abcdef0123456789deadbeefcafebabe " ;
2026-09-12 00:54:16 -04:00
static ASCII_ENV : Mutex < ( ) > = Mutex ::new ( ( ) ) ;
2026-09-12 00:15:19 -04:00
const ONION : & str = " abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvwx.onion " ;
fn screen_from ( buf : & ratatui ::buffer ::Buffer , w : u16 , h : u16 ) -> String {
let mut screen = String ::new ( ) ;
for y in 0 .. h {
for x in 0 .. w {
screen . push_str ( buf [ ( x , y ) ] . symbol ( ) ) ;
}
screen . push ( '\n' ) ;
}
screen
}
#[ test ]
fn status_footer_keeps_send_failed_and_chrome ( ) {
let note = " send failed: peer onion down " ;
for w in [ 80 u16 , 120 , 200 ] {
let line = status_footer ( w , FP , ONION , Some ( note ) , main_footer_hints ( ) ) ;
assert! (
line . chars ( ) . count ( ) < = w as usize ,
" footer wider than {w}: {} {line:?} " ,
line . chars ( ) . count ( )
) ;
assert! (
line . contains ( " send failed " ) ,
" {w} dropped fail-closed note: {line:?} "
) ;
assert! ( line . contains ( " TOR " ) , " {w} missing TOR: {line:?} " ) ;
assert! ( line . contains ( " me: " ) , " {w} missing me:: {line:?} " ) ;
assert! ( line . contains ( " ? help " ) , " {w} missing ? help: {line:?} " ) ;
}
}
#[ test ]
fn main_header_is_one_line_at_80 ( ) {
let line = main_header_line ( 80 , FP , ONION ) ;
assert! ( ! line . contains ( '\n' ) , " header must be one line: {line:?} " ) ;
assert! (
line . chars ( ) . count ( ) < = 80 ,
" header wider than 80: {} {line:?} " ,
line . chars ( ) . count ( )
) ;
assert! ( line . to_ascii_lowercase ( ) . contains ( " onionwire " ) , " {line:?} " ) ;
assert! ( line . contains ( " me: " ) , " {line:?} " ) ;
}
#[ test ]
fn roster_is_fixed_cells_not_percent ( ) {
assert_eq! ( roster_col_width ( 80 ) , 22 ) ;
assert_eq! ( roster_col_width ( 119 ) , 22 ) ;
assert_eq! ( roster_col_width ( 120 ) , 28 ) ;
assert_eq! ( roster_col_width ( 200 ) , 28 ) ;
}
#[ test ]
fn help_overlay_at_80x24_is_fullscreen_last_line_visible ( ) {
let backend = TestBackend ::new ( 80 , 24 ) ;
let mut terminal = Terminal ::new ( backend ) . expect ( " terminal " ) ;
terminal
. draw ( | f | {
f . render_widget (
Paragraph ::new ( " .-~~-. ONIONWIRE \n ┌roster junk \n ┌composer " ) ,
f . area ( ) ,
) ;
draw_text_overlay ( f , " ? help " , help_overlay_text ( ) ) ;
} )
. expect ( " draw " ) ;
let buf = terminal . backend ( ) . buffer ( ) ;
let screen = screen_from ( buf , 80 , 24 ) ;
assert! (
screen . contains ( " Esc closes this overlay " ) ,
" last help line clipped: \n {screen} "
) ;
assert! (
! screen . contains ( " .-~~-. " ) ,
" help punched through banner: \n {screen} "
) ;
assert! (
! screen . contains ( " ┌roster " ) ,
" help punched through roster: \n {screen} "
) ;
assert! ( screen . contains ( " ? help " ) , " help title missing: \n {screen} " ) ;
}
fn draw_main_standin ( f : & mut Frame , empty_roster : bool , composer : & str , note : Option < & str > ) {
let area = f . area ( ) ;
let header = main_header_line ( area . width , FP , ONION ) ;
let cols = Layout ::vertical ( [
Constraint ::Length ( 1 ) ,
Constraint ::Min ( 3 ) ,
Constraint ::Length ( 3 ) ,
Constraint ::Length ( 1 ) ,
] )
. split ( area ) ;
f . render_widget ( Paragraph ::new ( header ) , cols [ 0 ] ) ;
let roster_w = roster_col_width ( area . width ) . min ( cols [ 1 ] . width . saturating_sub ( 10 ) ) ;
let panes =
Layout ::horizontal ( [ Constraint ::Length ( roster_w ) , Constraint ::Min ( 10 ) ] ) . split ( cols [ 1 ] ) ;
let items = if empty_roster {
vec! [ ListItem ::new ( " no friends " ) ]
} else {
vec! [ ListItem ::new ( " alice aaaaaaaa… " ) ]
} ;
f . render_stateful_widget (
List ::new ( items )
. highlight_symbol ( " > " )
. block ( Block ::default ( ) . borders ( Borders ::ALL ) . title ( " roster 0 " ) ) ,
panes [ 0 ] ,
& mut ratatui ::widgets ::ListState ::default ( ) ,
) ;
f . render_widget (
Paragraph ::new ( " no friends yet " )
. wrap ( Wrap { trim : false } )
. block ( Block ::default ( ) . borders ( Borders ::ALL ) . title ( " chat " ) ) ,
panes [ 1 ] ,
) ;
f . render_widget (
Paragraph ::new ( format! ( " > {composer} " ) ) . wrap ( Wrap { trim : false } ) ,
cols [ 2 ] ,
) ;
let footer = status_footer ( area . width , FP , ONION , note , main_footer_hints ( ) ) ;
f . render_widget ( Paragraph ::new ( footer ) , cols [ 3 ] ) ;
}
#[ test ]
fn reconstructed_main_empty_roster_and_composer ( ) {
let backend = TestBackend ::new ( 80 , 24 ) ;
let mut terminal = Terminal ::new ( backend ) . expect ( " terminal " ) ;
terminal
. draw ( | f | draw_main_standin ( f , true , " message " , None ) )
. expect ( " draw " ) ;
let screen = screen_from ( terminal . backend ( ) . buffer ( ) , 80 , 24 ) ;
let row0 : String = screen . lines ( ) . next ( ) . unwrap_or ( " " ) . to_string ( ) ;
assert! (
! row0 . contains ( " .-~~-. " ) ,
" 80x24 main still uses 3-line wordmark: \n {screen} "
) ;
assert! (
screen . contains ( " no friends " ) ,
" empty roster blank: \n {screen} "
) ;
assert! (
screen . contains ( " message " ) ,
" composer missing placeholder: \n {screen} "
) ;
assert! (
! screen . contains ( " /wipe " ) ,
" composer still dumps slash list: \n {screen} "
) ;
}
#[ test ]
fn reconstructed_main_keeps_send_failed_on_footer ( ) {
let backend = TestBackend ::new ( 80 , 24 ) ;
let mut terminal = Terminal ::new ( backend ) . expect ( " terminal " ) ;
terminal
. draw ( | f | draw_main_standin ( f , false , " hello " , Some ( " send failed: peer onion down " ) ) )
. expect ( " draw " ) ;
let screen = screen_from ( terminal . backend ( ) . buffer ( ) , 80 , 24 ) ;
assert! (
screen . contains ( " send failed " ) ,
" fail-closed missing from frame: \n {screen} "
) ;
}
#[ test ]
fn dump_spec_frames ( ) {
2026-09-12 00:54:16 -04:00
let _guard = ASCII_ENV . lock ( ) . expect ( " ascii env lock " ) ;
unsafe { std ::env ::remove_var ( " ONIONWIRE_ASCII " ) } ;
2026-09-12 00:15:19 -04:00
for ( w , h ) in [ ( 80 u16 , 24 u16 ) , ( 120 , 40 ) ] {
let backend = TestBackend ::new ( w , h ) ;
let mut terminal = Terminal ::new ( backend ) . expect ( " terminal " ) ;
terminal
. draw ( | f | {
draw_main_standin (
f ,
false ,
" hello from composer " ,
Some ( " send failed: peer onion down " ) ,
)
} )
. expect ( " draw " ) ;
println! ( " ===== AFTER main {w} x {h} ===== " ) ;
print! ( " {} " , screen_from ( terminal . backend ( ) . buffer ( ) , w , h ) ) ;
let backend = TestBackend ::new ( w , h ) ;
let mut terminal = Terminal ::new ( backend ) . expect ( " terminal " ) ;
terminal
. draw ( | f | {
draw_main_standin ( f , true , " message " , None ) ;
draw_text_overlay ( f , " ? help " , help_overlay_text ( ) ) ;
} )
. expect ( " draw " ) ;
println! ( " ===== AFTER help {w} x {h} ===== " ) ;
print! ( " {} " , screen_from ( terminal . backend ( ) . buffer ( ) , w , h ) ) ;
2026-09-12 00:54:16 -04:00
let invite = sample_invite ( ) ;
let backend = TestBackend ::new ( w , h ) ;
let mut terminal = Terminal ::new ( backend ) . expect ( " terminal " ) ;
terminal . draw ( | f | draw_share ( f , & invite ) ) . expect ( " draw " ) ;
println! ( " ===== AFTER share {w} x {h} ===== " ) ;
print! ( " {} " , screen_from ( terminal . backend ( ) . buffer ( ) , w , h ) ) ;
}
}
fn sample_invite ( ) -> String {
let sk = [ 7 u8 ; 32 ] ;
qr ::encode ( & sk , ONION , & [ 1 u8 ; 32 ] ) . expect ( " encode " )
}
fn invite_line_ok ( line : & str ) -> bool {
let t = line . trim ( ) ;
t . is_empty ( )
| | t . starts_with ( " onionwire: " )
| | t . starts_with ( " k= " )
| | t . starts_with ( " o= " )
| | t . starts_with ( " spk= " )
| | t . starts_with ( " sig= " )
| | t . chars ( ) . all ( | c | c . is_ascii_hexdigit ( ) )
}
#[ test ]
fn alert_line_truncates_to_frame_width ( ) {
let long = " passphrases do not match and then a lot more context that would collide with the roster on the next row if left unwrapped " ;
let line = alert_line ( long , 80 ) ;
assert! (
line . chars ( ) . count ( ) < = 80 ,
" alert wider than 80: {} {line:?} " ,
line . chars ( ) . count ( )
) ;
assert! (
line . contains ( '…' ) | | line . contains ( " ... " ) ,
" long alert was not truncated: {line:?} "
) ;
assert! (
! line . contains ( " roster on the next row " ) ,
" alert still has overflow tail: {line:?} "
) ;
tui: clean-look chrome redesign (one accent, honest tor phase, real frames)
Applies the bitchat-tui clean-look principles to the OnionWire main screen.
- Hierarchy: header, roster + one primary chat pane, one status line, one
footer hint line. The header gives up the accent (the accent is reserved
for focus), so it stops competing with the panes.
- Tor phase is a first-class state: Node::tor_state() -> TorPhase (glyph +
word, header and footer) so connecting / ready / degraded / off are never
colour-only and never implied. No new data field.
- Footer changes with the focused pane (pane_footer_hints) and the phase; the
main footer drops the redundant onion (the header already prints it) and
uses those cells for hints. status_footer keeps its signature and strings.
- Empty roster / empty chat / connecting / degraded / off are designed states
with their own copy, not blank panes.
- draw_main_chrome + MainView: the real main render path is public and
Node-free, so tests/tui_frames.rs dumps the actual chrome at 80x24, 120x40
and 200x60 (12 tests, 5 states, real Message/OutboxEntry rows) instead of a
reconstructed stand-in.
- Widths in cells everywhere touched: status_footer*, alert_line,
main_header_line*, draw_text_overlay, roster_row_text. The roster spends its
budget name-first, so a 22-cell pane reads `bob-the-sta… stale` instead of
`… bbbbbbbb… stale`.
- draw_text_overlay is centered with a one-cell side margin and clears
underneath; never full-bleed.
Also fixes a pre-existing race in tests/tui_spec.rs (the ellipsis-form
assertion did not tolerate ONIONWIRE_ASCII being set by a parallel test).
Co-Authored-By: Hermes <[email protected] >
2026-09-18 23:13:12 -04:00
// Cells, not chars: a double-width peer error must not overflow the row.
let cjk = alert_line ( " 接続がタイムアウトしました 接続がタイムアウトしました " , 32 ) ;
assert! (
onionwire ::tui ::cell_width ( & cjk ) < = 32 ,
" alert wider than 32 cells: {} {cjk:?} " ,
onionwire ::tui ::cell_width ( & cjk )
) ;
2026-09-12 00:54:16 -04:00
}
#[ test ]
fn wrap_invite_breaks_on_field_boundaries ( ) {
let invite = sample_invite ( ) ;
assert! ( invite . len ( ) > 78 , " fixture too short to wrap: {invite} " ) ;
let wrapped = wrap_invite ( & invite , 78 ) ;
for line in wrapped . lines ( ) {
assert! (
line . chars ( ) . count ( ) < = 78 ,
" invite line wider than 78: {} {line:?} " ,
line . chars ( ) . count ( )
) ;
assert! (
invite_line_ok ( line ) ,
" invite wrapped mid-token: {line:?} \n {wrapped} "
) ;
}
assert! (
wrapped . contains ( " onionwire:v1: " ) ,
" lost invite prefix: \n {wrapped} "
) ;
assert! ( wrapped . contains ( " k= " ) , " lost k= field: \n {wrapped} " ) ;
assert! ( wrapped . contains ( " spk= " ) , " lost spk= field: \n {wrapped} " ) ;
let joined : String = wrapped . lines ( ) . map ( str ::trim ) . collect ( ) ;
assert_eq! (
joined , invite ,
" wrap must be newline-joinable back to payload "
) ;
}
#[ test ]
fn draw_share_invite_does_not_wrap_mid_token ( ) {
let invite = sample_invite ( ) ;
let backend = TestBackend ::new ( 80 , 24 ) ;
let mut terminal = Terminal ::new ( backend ) . expect ( " terminal " ) ;
terminal . draw ( | f | draw_share ( f , & invite ) ) . expect ( " draw " ) ;
let screen = screen_from ( terminal . backend ( ) . buffer ( ) , 80 , 24 ) ;
assert! (
screen . contains ( " onionwire:v1: " ) ,
" missing prefix: \n {screen} "
) ;
for raw in screen . lines ( ) {
let inner = raw . trim_start_matches ( [ '│' , '|' , ' ' ] ) ;
let inner = inner . trim_end_matches ( [ '│' , '|' , ' ' ] ) ;
if inner . starts_with ( " onionwire: " )
| | inner . starts_with ( " k= " )
| | inner . starts_with ( " o= " )
| | inner . starts_with ( " spk= " )
| | inner . starts_with ( " sig= " )
| | inner . chars ( ) . all ( | c | c . is_ascii_hexdigit ( ) )
{
assert! (
invite_line_ok ( inner ) ,
" share pane mid-token wrap: {inner:?} \n {screen} "
) ;
}
if inner . starts_with ( 'c' ) & & inner . contains ( " :o= " ) {
panic! ( " share still wraps mid-hex into :o=: {inner:?} \n {screen} " ) ;
}
2026-09-12 00:15:19 -04:00
}
}
2026-09-12 00:54:16 -04:00
#[ test ]
fn empty_friend_chat_has_send_hint ( ) {
let text = empty_friend_chat_text ( ) ;
assert! ( text . contains ( " no messages " ) , " {text:?} " ) ;
assert! ( text . contains ( " type below, Enter sends " ) , " {text:?} " ) ;
}
#[ test ]
fn paste_error_keeps_resubmit_hint ( ) {
let body = paste_screen_text ( " " , Some ( " bad invite " ) ) ;
assert! ( body . contains ( " bad invite " ) , " {body:?} " ) ;
assert! ( body . contains ( " Enter resubmits " ) , " {body:?} " ) ;
assert! ( body . contains ( " Esc back " ) , " {body:?} " ) ;
let ok = paste_screen_text ( " onionwire:v1:k=x " , None ) ;
assert! (
ok . contains ( " paste onionwire:v1 payload " ) ,
" happy-path hint lost: {ok:?} "
) ;
}
#[ test ]
fn ascii_switch_80x24_frame_is_pure_ascii ( ) {
let _guard = ASCII_ENV . lock ( ) . expect ( " ascii env lock " ) ;
unsafe { std ::env ::set_var ( " ONIONWIRE_ASCII " , " 1 " ) } ;
assert! (
ascii_chrome ( ) ,
" ONIONWIRE_ASCII set but ascii_chrome() is false "
) ;
let footer = status_footer ( 80 , FP , ONION , None , main_footer_hints ( ) ) ;
assert! (
footer . contains ( " ... " ) ,
" ASCII truncation marker missing: {footer:?} "
) ;
assert! (
! footer . contains ( '…' ) ,
" unicode ellipsis still in footer: {footer:?} "
) ;
let invite = sample_invite ( ) ;
let backend = TestBackend ::new ( 80 , 24 ) ;
let mut terminal = Terminal ::new ( backend ) . expect ( " terminal " ) ;
terminal . draw ( | f | draw_share ( f , & invite ) ) . expect ( " draw " ) ;
let screen = screen_from ( terminal . backend ( ) . buffer ( ) , 80 , 24 ) ;
let non_ascii : Vec < char > = screen . chars ( ) . filter ( | c | ! c . is_ascii ( ) ) . collect ( ) ;
assert! (
non_ascii . is_empty ( ) ,
" ASCII switch ignored, non-ASCII in 80x24 frame: {non_ascii:?} \n {screen} "
) ;
assert! (
screen . contains ( " ... " ) ,
" truncation marker missing from ASCII frame: \n {screen} "
) ;
assert! (
screen . contains ( '+' ) & & screen . contains ( '|' ) & & screen . contains ( '-' ) ,
" ASCII borders missing: \n {screen} "
) ;
println! ( " ===== AFTER ascii share 80x24 ===== \n {screen} " ) ;
unsafe { std ::env ::remove_var ( " ONIONWIRE_ASCII " ) } ;
}
2026-09-12 14:22:38 -04:00
// ---------------------------------------------------------------------------
// Outbox delivery state (card t_d9a5b065)
//
// States come from the outbox API (`Outbox::pending` → `Queued` / `Sending` /
// `Failed`; delivered rows are deleted, so absence means `Sent`). No new wire
// prefix, no parallel state model.
// ---------------------------------------------------------------------------
2026-09-12 14:34:37 -04:00
fn out_msg ( id : i64 , body : & str ) -> Message {
2026-09-12 14:22:38 -04:00
Message {
2026-09-12 14:34:37 -04:00
id ,
2026-09-12 14:22:38 -04:00
dir : " out " . into ( ) ,
plaintext : body . as_bytes ( ) . to_vec ( ) ,
}
}
2026-09-12 14:34:37 -04:00
fn in_msg ( id : i64 , body : & str ) -> Message {
2026-09-12 14:22:38 -04:00
Message {
2026-09-12 14:34:37 -04:00
id ,
2026-09-12 14:22:38 -04:00
dir : " in " . into ( ) ,
plaintext : body . as_bytes ( ) . to_vec ( ) ,
}
}
fn pending_row (
2026-09-12 14:34:37 -04:00
message_id : i64 ,
2026-09-12 14:22:38 -04:00
body : & str ,
status : OutboxStatus ,
attempts : u32 ,
next_in : i64 ,
now : i64 ,
) -> OutboxEntry {
OutboxEntry {
id : 1 ,
friend_pk : vec ! [ 9 u8 ; 32 ] ,
2026-09-12 14:34:37 -04:00
message_id ,
2026-09-12 14:22:38 -04:00
body : body . as_bytes ( ) . to_vec ( ) ,
chat: send and receive as ratchet frames through the outbox payload
Chat plaintext is ratchet-encrypted once, before the first delivery attempt,
and the frame is what the outbox stores and retries, so a retried message
re-sends identical bytes instead of advancing the sending chain twice.
- dispatch: Kind::Ratchet for the `rat ` prefix, matched before the unknown
[a-z]{3} prefix rule
- node: encode_chat_frame / ingest_chat_frame (the wire halves of Node::send
and handle_incoming), bootstrap derived from the peers' static prekey DH
because the Noise handshake is frozen and carries no ratchet key
- outbox: nullable outbox.payload + Outbox::send_payload; NULL payload keeps
the previous row-for-row behaviour
- store: additive outbox.payload migration, enqueue_outbox_payload,
OutboxEntry::payload
- add_friend_payload: a changed prekey clears the (prekey-bound) ratchet state
tests/ratchet_wire.rs (5) covers one frame per send, byte-identical retries,
out-of-order delivery, replay, tampering and fresh-friend both directions.
tests/tui_spec.rs and crates/onionwire-sdk/src/lib.rs only gained a
`payload: None` field in their OutboxEntry test fixtures: the card's required
field on a pub struct cannot be added without it.
2026-09-16 19:02:52 -04:00
payload : None ,
2026-09-12 14:22:38 -04:00
attempts ,
next_attempt_at : now + next_in ,
created_at : now ,
status ,
last_error : None ,
}
}
2026-09-12 14:34:37 -04:00
fn queued_row ( message_id : i64 , body : & str , attempts : u32 , next_in : i64 , now : i64 ) -> OutboxEntry {
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.
2026-09-19 00:31:42 -04:00
pending_row ( message_id , body , OutboxStatus ::Queued , attempts , next_in , now )
2026-09-12 14:22:38 -04:00
}
2026-09-12 14:34:37 -04:00
fn sending_row ( message_id : i64 , body : & str , now : i64 ) -> OutboxEntry {
pending_row ( message_id , body , OutboxStatus ::Sending , 1 , 0 , now )
2026-09-12 14:22:38 -04:00
}
2026-09-12 14:34:37 -04:00
fn failed_row ( message_id : i64 , body : & str , why : & str , now : i64 ) -> OutboxEntry {
pending_row (
message_id ,
body ,
OutboxStatus ::Failed ( why . into ( ) ) ,
8 ,
0 ,
now ,
)
2026-09-12 14:22:38 -04:00
}
/// Marker is everything after the two-space separator the render helper uses.
fn marker_of ( line : & str ) -> & str {
line . rsplit ( " " ) . next ( ) . unwrap_or ( " " )
}
/// Force the non-ASCII (unicode glyph) path. Caller holds `ASCII_ENV`.
fn force_unicode_mode ( ) {
unsafe {
std ::env ::remove_var ( " ONIONWIRE_ASCII " ) ;
std ::env ::remove_var ( " NO_COLOR " ) ;
}
}
#[ test ]
fn queued_and_delivered_messages_render_different_markers ( ) {
let guard = ASCII_ENV . lock ( ) . expect ( " ascii env lock " ) ;
force_unicode_mode ( ) ;
let _guard = guard ;
let now = 1_700_000_000 ;
2026-09-12 14:34:37 -04:00
let msgs = vec! [ out_msg ( 1 , " ping " ) , out_msg ( 2 , " pong " ) ] ;
let pending = vec! [ queued_row ( 2 , " pong " , 2 , 45 , now ) ] ;
2026-09-12 14:22:38 -04:00
let ( lines , summary ) = chat_with_delivery ( & msgs , & pending , now ) ;
assert! (
lines [ 0 ] . contains ( '✓' ) ,
" delivered row lost its mark: {:?} " ,
lines [ 0 ]
) ;
assert! ( ! lines [ 0 ] . contains ( " queued " ) , " {:?} " , lines [ 0 ] ) ;
assert! (
lines [ 1 ] . contains ( '◷' ) ,
" queued row lost its glyph: {:?} " ,
lines [ 1 ]
) ;
assert! ( lines [ 1 ] . contains ( " queued " ) , " {:?} " , lines [ 1 ] ) ;
assert! (
lines [ 1 ] . contains ( " try 2/8 " ) ,
" attempt count missing: {:?} " ,
lines [ 1 ]
) ;
assert! (
lines [ 1 ] . contains ( " retry 45s " ) ,
" retry age missing: {:?} " ,
lines [ 1 ]
) ;
assert_ne! (
marker_of ( & lines [ 0 ] ) ,
marker_of ( & lines [ 1 ] ) ,
" queued and delivered must not share a marker "
) ;
assert_eq! ( summary . queued , 1 ) ;
assert_eq! ( summary . failed , 0 ) ;
}
2026-09-12 14:34:37 -04:00
/// The case the body match got wrong: the same text sent twice, only the
/// *older* send still queued. Joined by body, the (single) pending row lands on
/// the newest send and the actually-queued row shows `✓` — which is exactly
/// false delivery. The join is on `Message::id` / `OutboxEntry::message_id`.
#[ test ]
fn identical_bodies_join_by_message_id_not_body ( ) {
let guard = ASCII_ENV . lock ( ) . expect ( " ascii env lock " ) ;
force_unicode_mode ( ) ;
let _guard = guard ;
let now = 1_700_000_000 ;
let msgs = vec! [ out_msg ( 7 , " same text " ) , out_msg ( 8 , " same text " ) ] ;
let pending = vec! [ queued_row ( 7 , " same text " , 1 , 30 , now ) ] ;
let ( lines , summary ) = chat_with_delivery ( & msgs , & pending , now ) ;
assert! (
lines [ 0 ] . contains ( '◷' ) & & lines [ 0 ] . contains ( " queued " ) ,
" queued marker must land on the queued row (id 7): {:?} " ,
lines [ 0 ]
) ;
assert! (
! lines [ 0 ] . contains ( '✓' ) ,
" queued row must not claim delivery: {:?} " ,
lines [ 0 ]
) ;
assert_eq! (
marker_of ( & lines [ 1 ] ) ,
" ✓ " ,
" delivered row (id 8) must keep its mark: {:?} " ,
lines [ 1 ]
) ;
2026-09-17 20:44:28 -04:00
assert_eq! (
summary . note ( ) . as_deref ( ) ,
Some ( " peer unreachable, queued (1/8, retry 30s) " )
) ;
2026-09-12 14:34:37 -04:00
}
2026-09-12 14:22:38 -04:00
#[ test ]
fn delivery_markers_have_exercised_ascii_fallbacks ( ) {
let _guard = ASCII_ENV . lock ( ) . expect ( " ascii env lock " ) ;
unsafe {
std ::env ::set_var ( " ONIONWIRE_ASCII " , " 1 " ) ;
std ::env ::remove_var ( " NO_COLOR " ) ;
}
let now = 500 ;
let msgs = vec! [
2026-09-12 14:34:37 -04:00
out_msg ( 1 , " alpha " ) ,
out_msg ( 2 , " beta " ) ,
out_msg ( 3 , " gamma " ) ,
out_msg ( 4 , " delta " ) ,
in_msg ( 5 , " epsilon " ) ,
2026-09-12 14:22:38 -04:00
] ;
let pending = vec! [
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.
2026-09-19 00:31:42 -04:00
failed_row ( 1 , " alpha " , " connect peer.onion:80: connection timed out " , now ) ,
2026-09-12 14:34:37 -04:00
queued_row ( 2 , " beta " , 1 , 30 , now ) ,
sending_row ( 3 , " gamma " , now ) ,
2026-09-12 14:22:38 -04:00
] ;
let ( lines , summary ) = chat_with_delivery ( & msgs , & pending , now ) ;
for line in & lines {
assert! (
line . is_ascii ( ) ,
" ASCII fallback missing, non-ASCII in {line:?} "
) ;
}
assert_eq! ( marker_of ( & lines [ 0 ] ) , " failed: connection timed out " ) ;
assert_eq! ( marker_of ( & lines [ 1 ] ) , " queued (try 1/8, retry 30s) " ) ;
assert_eq! ( marker_of ( & lines [ 2 ] ) , " sending " ) ;
assert_eq! ( marker_of ( & lines [ 3 ] ) , " ok " , " delivered fallback is `ok` " ) ;
assert_eq! ( lines [ 4 ] , " them: epsilon " , " inbound rows carry no state " ) ;
assert_eq! ( summary . queued , 2 , " queued + sending are both outstanding " ) ;
assert_eq! ( summary . failed , 1 ) ;
unsafe { std ::env ::remove_var ( " ONIONWIRE_ASCII " ) } ;
}
#[ test ]
fn retry_age_and_failure_reason_are_short_forms ( ) {
assert_eq! ( retry_in_text ( 45 ) , " retry 45s " ) ;
assert_eq! ( retry_in_text ( 59 ) , " retry 59s " ) ;
assert_eq! ( retry_in_text ( 60 ) , " retry 1m " ) ;
assert_eq! ( retry_in_text ( 720 ) , " retry 12m " ) ;
assert_eq! ( retry_in_text ( 0 ) , " retry now " ) ;
assert_eq! ( retry_in_text ( - 30 ) , " retry now " ) ;
assert_eq! (
short_send_reason ( " connect abcdef.onion:80: connection timed out " , 24 ) ,
" connection timed out "
) ;
let long = short_send_reason ( " a-really-long-failure-description-here " , 12 ) ;
assert! ( long . chars ( ) . count ( ) < = 12 , " {long:?} " ) ;
assert! (
long . contains ( '…' ) | | long . contains ( " ... " ) ,
" truncation marker missing: {long:?} "
) ;
assert_eq! ( short_send_reason ( " nope " , 24 ) , " nope " ) ;
}
#[ test ]
fn delivery_tag_reads_the_outbox_status_enum ( ) {
let guard = ASCII_ENV . lock ( ) . expect ( " ascii env lock " ) ;
force_unicode_mode ( ) ;
let _guard = guard ;
assert_eq! ( delivery_tag ( & OutboxStatus ::Sent , 0 , 0 ) , " ✓ " ) ;
assert_eq! (
delivery_tag ( & OutboxStatus ::Queued , 3 , 120 ) ,
" ◷ queued (try 3/8, retry 2m) "
) ;
assert_eq! ( delivery_tag ( & OutboxStatus ::Sending , 1 , 0 ) , " » sending " ) ;
assert_eq! (
delivery_tag ( & OutboxStatus ::Failed ( " connect x:80: nope " . into ( ) ) , 8 , 0 ) ,
" ✗ failed: nope "
) ;
}
#[ test ]
fn footer_summary_counts_queued_and_keeps_fail_closed ( ) {
let none = OutboxSummary ::default ( ) ;
assert_eq! ( none . note ( ) , None ) ;
let queued = OutboxSummary {
queued : 2 ,
failed : 0 ,
first_error : None ,
2026-09-17 20:44:28 -04:00
attempts : 3 ,
next_in_secs : Some ( 45 ) ,
2026-09-12 14:22:38 -04:00
} ;
2026-09-17 20:44:28 -04:00
assert_eq! (
queued . note ( ) . as_deref ( ) ,
Some ( " peer unreachable, queued (3/8, retry 45s) " )
) ;
2026-09-12 14:22:38 -04:00
let failed = OutboxSummary {
queued : 0 ,
failed : 1 ,
first_error : Some ( " connect peer.onion:80: connection timed out " . into ( ) ) ,
2026-09-17 20:44:28 -04:00
.. OutboxSummary ::default ( )
2026-09-12 14:22:38 -04:00
} ;
let note = failed . note ( ) . expect ( " failed rows must produce a note " ) ;
assert! ( note . starts_with ( " send failed: " ) , " {note:?} " ) ;
assert! ( note . contains ( " connection timed out " ) , " {note:?} " ) ;
let mixed = OutboxSummary {
queued : 3 ,
failed : 1 ,
first_error : Some ( " connect peer.onion:80: connection timed out " . into ( ) ) ,
2026-09-17 20:44:28 -04:00
attempts : 2 ,
next_in_secs : Some ( 60 ) ,
2026-09-12 14:22:38 -04:00
} ;
let mixed_note = mixed . note ( ) . expect ( " mixed rows must produce a note " ) ;
2026-09-17 20:44:28 -04:00
assert! (
mixed_note . contains ( " queued (2/8, retry 1m) " ) ,
" {mixed_note:?} "
) ;
assert! ( mixed_note . starts_with ( " peer unreachable " ) , " {mixed_note:?} " ) ;
2026-09-12 14:22:38 -04:00
assert! ( mixed_note . contains ( " send failed " ) , " {mixed_note:?} " ) ;
// Fail-closed copy stays visible in the real footer at the 80-col floor.
let line = status_footer ( 80 , FP , ONION , Some ( & note ) , main_footer_hints ( ) ) ;
assert! (
line . chars ( ) . count ( ) < = 80 ,
" {} {line:?} " ,
line . chars ( ) . count ( )
) ;
assert! ( line . contains ( " send failed " ) , " footer dropped it: {line:?} " ) ;
assert! ( line . contains ( " TOR " ) & & line . contains ( " ? help " ) , " {line:?} " ) ;
let queued_line = status_footer ( 80 , FP , ONION , queued . note ( ) . as_deref ( ) , main_footer_hints ( ) ) ;
2026-09-17 20:44:28 -04:00
assert! (
queued_line . contains ( " queued (3/8, retry 45s) " ) ,
" {queued_line:?} "
) ;
2026-09-12 14:22:38 -04:00
assert! ( queued_line . chars ( ) . count ( ) < = 80 ) ;
// `! ` ornament (colour off) still lands on the derived failing note.
let _guard = ASCII_ENV . lock ( ) . expect ( " ascii env lock " ) ;
unsafe { std ::env ::set_var ( " NO_COLOR " , " 1 " ) } ;
let no_color = status_footer ( 80 , FP , ONION , Some ( & note ) , main_footer_hints ( ) ) ;
assert! ( no_color . contains ( " ! send failed " ) , " {no_color:?} " ) ;
unsafe { std ::env ::remove_var ( " NO_COLOR " ) } ;
}
/// The card's width criterion: draw the real helpers at the documented floor
/// (80x24) and prove nothing in the chat/footer region exceeds the width, and
/// that an over-long row wraps in the pane instead of being clipped.
#[ test ]
fn chat_and_footer_rows_fit_80x24_and_wrap_instead_of_clipping ( ) {
let guard = ASCII_ENV . lock ( ) . expect ( " ascii env lock " ) ;
force_unicode_mode ( ) ;
let _guard = guard ;
let now = 1_700_000_000 ;
let long = " this is a very long chat line that should wrap inside the chat pane instead of running off the right edge of an 80-column terminal and colliding with the roster border " ;
2026-09-12 14:34:37 -04:00
let msgs = vec! [ out_msg ( 1 , " ok " ) , in_msg ( 2 , " pong " ) , out_msg ( 3 , long ) ] ;
let pending = vec! [ queued_row ( 3 , long , 3 , 45 , now ) ] ;
2026-09-12 14:22:38 -04:00
let ( lines , summary ) = chat_with_delivery ( & msgs , & pending , now ) ;
for line in lines . iter ( ) . take ( 2 ) {
assert! (
line . chars ( ) . count ( ) < = 80 ,
" short row wider than 80: {} {line:?} " ,
line . chars ( ) . count ( )
) ;
}
let footer = status_footer (
80 ,
FP ,
ONION ,
summary . note ( ) . as_deref ( ) ,
main_footer_hints ( ) ,
) ;
assert! ( footer . chars ( ) . count ( ) < = 80 , " {footer:?} " ) ;
let backend = TestBackend ::new ( 80 , 24 ) ;
let mut terminal = Terminal ::new ( backend ) . expect ( " terminal " ) ;
terminal
. draw ( | f | {
let area = f . area ( ) ;
let cols = Layout ::vertical ( [ Constraint ::Min ( 3 ) , Constraint ::Length ( 1 ) ] ) . split ( area ) ;
draw_chat ( f , cols [ 0 ] , & lines , Some ( " alice " ) , true , 0 ) ;
f . render_widget ( Paragraph ::new ( footer . clone ( ) ) , cols [ 1 ] ) ;
} )
. expect ( " draw " ) ;
let buf = terminal . backend ( ) . buffer ( ) ;
let mut screen = String ::new ( ) ;
for y in 0 .. 24 u16 {
for x in 0 .. 80 u16 {
screen . push_str ( buf [ ( x , y ) ] . symbol ( ) ) ;
}
screen . push ( '\n' ) ;
}
for ( y , row ) in screen . lines ( ) . enumerate ( ) {
assert! (
row . chars ( ) . count ( ) < = 80 ,
" 80x24 chat/footer row {y} wider than the terminal: {} {row:?} " ,
row . chars ( ) . count ( )
) ;
}
assert! (
screen . contains ( '◷' ) ,
" queued glyph missing from frame: \n {screen} "
) ;
assert! ( screen . contains ( " queued " ) , " queued word missing: \n {screen} " ) ;
assert! ( screen . contains ( '✓' ) , " delivered glyph missing: \n {screen} " ) ;
assert! (
screen . contains ( " with the roster border " ) ,
" long row was clipped, not wrapped: \n {screen} "
) ;
assert! (
2026-09-17 20:44:28 -04:00
screen . contains ( " peer unreachable, queued (3/8, retry 45s) " ) ,
2026-09-12 14:22:38 -04:00
" footer summary missing: \n {screen} "
) ;
println! ( " ===== AFTER outbox 80x24 (real draw_chat + status_footer) ===== \n {screen} " ) ;
}
/// The renderer consumes the real outbox API, not a hand-written fixture: a
/// genuine unreachable-onion send leaves a `Queued` row, and that row is what
/// the chat line and the footer note are built from.
#[ tokio::test ]
async fn renders_a_queued_row_from_a_real_outbox_send ( ) {
use onionwire ::Store ;
use onionwire ::outbox ::{ BoxFut , Deliverer , Outbox } ;
use std ::sync ::Arc ;
struct Dead ;
impl Deliverer for Dead {
fn deliver < ' a > (
& ' a self ,
_onion : & ' a str ,
_pinned_id : & ' a [ u8 ] ,
_prekey : & ' a [ u8 ] ,
_plaintext : & ' a [ u8 ] ,
) -> BoxFut < ' a , Result < ( ) , String > > {
Box ::pin ( async { Err ( " connect dead.onion:80: timed out " . to_string ( ) ) } )
}
}
let dir = tempfile ::tempdir ( ) . expect ( " tempdir " ) ;
let store = Store ::open_at_with_passphrase ( dir . path ( ) , " tui-spec-pass " ) . expect ( " open store " ) ;
let pk = [ 1 u8 ; 32 ] ;
store
. upsert_friend ( & pk , " dead.onion " , None )
. expect ( " friend " ) ;
store . set_friend_prekey ( & pk , & [ 7 u8 ; 32 ] ) . expect ( " prekey " ) ;
let store = Arc ::new ( std ::sync ::Mutex ::new ( store ) ) ;
let outbox = Outbox ::new ( Arc ::clone ( & store ) , Arc ::new ( Dead ) ) ;
assert_eq! (
outbox . send ( & pk , b " queued for a dead peer " ) . await ,
Ok ( OutboxStatus ::Queued )
) ;
let pending = outbox . pending ( & pk ) . expect ( " pending rows " ) ;
assert_eq! ( pending . len ( ) , 1 , " one queued row " ) ;
let msgs = store
. lock ( )
. expect ( " store lock " )
. list_messages ( & pk )
. expect ( " messages " ) ;
let now = pending [ 0 ] . next_attempt_at - 45 ;
let ( lines , summary ) = chat_with_delivery ( & msgs , & pending , now ) ;
assert_eq! ( lines . len ( ) , 1 ) ;
assert! (
lines [ 0 ] . contains ( " queued (try 1/8, retry 45s) " ) ,
" real outbox row did not render: {:?} " ,
lines [ 0 ]
) ;
2026-09-17 20:44:28 -04:00
assert_eq! (
summary . note ( ) . as_deref ( ) ,
Some ( " peer unreachable, queued (1/8, retry 45s) " )
) ;
2026-09-12 14:22:38 -04:00
// And once a send crosses the circuit the row is gone, so the same message
// renders as delivered.
let ( delivered , summary ) = chat_with_delivery ( & msgs , & [ ] , now ) ;
assert! ( delivered [ 0 ] . contains ( '✓' ) , " {:?} " , delivered [ 0 ] ) ;
assert_eq! ( summary . note ( ) , None ) ;
}
2026-09-15 17:29:26 -04:00
// ---------------------------------------------------------------------------
// Colour token set (card t_49b7c2b1)
// ---------------------------------------------------------------------------
tests/tui_spec: remove the NO_COLOR env race behind the flaky suite
`alert_line_prefixes_when_no_color` flipped the process-global `NO_COLOR`
without the `ASCII_ENV` mutex the other env-touching tests in this binary
hold, so a concurrent `remove_var("NO_COLOR")` could win and make
`alert_line()` resolve to Rgb/Ansi16 — the `! ` assertion then failed on an
otherwise green run (measured 1/12 runs at cc1201d).
Inject the colour mode instead of reading the environment in the test:
* `tui::alert_line_for_mode(mode, msg, width)` — `alert_line()` is now a
one-line delegate passing `color_mode()`, so production behaviour is
unchanged and the no-colour path is asserted without touching the env.
* The test now pins all three shapes of that path: `None` prefixes `! `,
Rgb leaves the message verbatim, and an already-prefixed alert is not
double-prefixed.
Also fix the second, same-class race the 20x repeat surfaced:
`wallets_settings_menu_frame_shows_the_shipped_footer` compares a rendered
frame against `status_footer_phased` computed moments earlier, and both read
`ascii_chrome()`/`color_mode()` live — a concurrent `ONIONWIRE_ASCII=1` made
the two sides disagree (✓/… vs ok/...). It now takes the same `ASCII_ENV`
lock and forces the unicode mode.
Evidence (TMPDIR=/home/lancelot/.hermes/tmp/onionwire-tui):
* cargo test --locked -> exit 0, 35 suites, 472 passed, 0 failed, 4 ignored
* cargo clippy --locked --all-targets -- -D warnings -> exit 0
* cargo test --locked --test tui_spec x60 -> 60 ok, 0 failures
* teeth: with the `! ` prefix removed from the None path, the test fails
("expected '! ' prefix in None mode: \"peer down\"") — reverted.
* ONIONWIRE_ASCII=1 cargo test --locked --test tui_spec -> 37 passed (no
unlocked test's outcome depends on the ambient value)
* rustfmt --edition 2024 --check on both files: only the inherited hunks
(src/tui.rs 16 == HEAD 16; tests/tui_spec.rs 3 vs HEAD 4, one inherited
hunk reformatted away by this edit)
2026-09-26 22:46:43 -04:00
use onionwire ::tui ::{ ColorMode , alert_line_for_mode , tokens_for } ;
2026-09-15 17:29:26 -04:00
use ratatui ::style ::{ Color , Modifier } ;
#[ test ]
fn rgb_tokens_resolve_to_palette_fg ( ) {
let t = tokens_for ( ColorMode ::Rgb ) ;
assert_eq! ( t . text . fg , Some ( Color ::Rgb ( 196 , 214 , 176 ) ) ) ;
assert_eq! ( t . dim . fg , Some ( Color ::Rgb ( 98 , 110 , 92 ) ) ) ;
assert_eq! ( t . accent . fg , Some ( Color ::Rgb ( 232 , 165 , 75 ) ) ) ;
assert_eq! ( t . alert . fg , Some ( Color ::Rgb ( 220 , 80 , 70 ) ) ) ;
assert_eq! ( t . stale . fg , Some ( Color ::Rgb ( 210 , 180 , 80 ) ) ) ;
assert_eq! ( t . border . fg , Some ( Color ::Rgb ( 72 , 84 , 64 ) ) ) ;
// highlight uses bg + fg + bold in RGB mode
assert_eq! ( t . highlight . fg , Some ( Color ::Rgb ( 232 , 165 , 75 ) ) ) ;
assert_eq! ( t . highlight . bg , Some ( Color ::Rgb ( 48 , 42 , 28 ) ) ) ;
assert! (
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.
2026-09-19 00:31:42 -04:00
t . highlight
. add_modifier
. contains ( Modifier ::BOLD ) ,
2026-09-15 17:29:26 -04:00
" RGB highlight must be bold "
) ;
}
#[ test ]
fn none_tokens_strip_colour_fg_and_alert_keeps_bold ( ) {
let t = tokens_for ( ColorMode ::None ) ;
assert_eq! ( t . text . fg , None , " None mode must strip all colour " ) ;
assert_eq! ( t . dim . fg , None ) ;
assert_eq! ( t . alert . fg , None ) ;
assert_eq! ( t . border . fg , None ) ;
assert_eq! ( t . stale . fg , None ) ;
// accent falls back to bold (no colour) in None mode
assert_eq! (
t . accent . add_modifier ,
Modifier ::BOLD ,
" None accent must be bold-only "
) ;
// highlight falls back to bold + reversed
assert_eq! (
t . highlight . add_modifier ,
Modifier ::BOLD | Modifier ::REVERSED ,
" None highlight must be bold+reversed "
) ;
assert_eq! ( t . highlight . fg , None ) ;
assert_eq! ( t . highlight . bg , None ) ;
}
#[ test ]
fn ansi16_tokens_use_ansi_colours ( ) {
let t = tokens_for ( ColorMode ::Ansi16 ) ;
assert_eq! ( t . text . fg , Some ( Color ::White ) ) ;
assert_eq! ( t . dim . fg , Some ( Color ::DarkGray ) ) ;
assert_eq! ( t . alert . fg , Some ( Color ::Red ) ) ;
assert_eq! ( t . border . fg , Some ( Color ::DarkGray ) ) ;
assert_eq! ( t . stale . fg , Some ( Color ::Yellow ) ) ;
assert_eq! ( t . accent . fg , Some ( Color ::Yellow ) ) ;
// highlight in Ansi16 has no colour, just modifiers
assert_eq! ( t . highlight . fg , None ) ;
assert_eq! ( t . highlight . bg , None ) ;
assert! (
t . highlight
. add_modifier
. contains ( Modifier ::REVERSED | Modifier ::BOLD )
) ;
}
#[ test ]
fn tokens_for_is_deterministic_across_calls ( ) {
let a = tokens_for ( ColorMode ::Rgb ) ;
let b = tokens_for ( ColorMode ::Rgb ) ;
assert_eq! ( a . text . fg , b . text . fg ) ;
assert_eq! ( a . accent . fg , b . accent . fg ) ;
assert_eq! ( a . highlight . fg , b . highlight . fg ) ;
}
#[ test ]
fn alert_line_prefixes_when_no_color ( ) {
tests/tui_spec: remove the NO_COLOR env race behind the flaky suite
`alert_line_prefixes_when_no_color` flipped the process-global `NO_COLOR`
without the `ASCII_ENV` mutex the other env-touching tests in this binary
hold, so a concurrent `remove_var("NO_COLOR")` could win and make
`alert_line()` resolve to Rgb/Ansi16 — the `! ` assertion then failed on an
otherwise green run (measured 1/12 runs at cc1201d).
Inject the colour mode instead of reading the environment in the test:
* `tui::alert_line_for_mode(mode, msg, width)` — `alert_line()` is now a
one-line delegate passing `color_mode()`, so production behaviour is
unchanged and the no-colour path is asserted without touching the env.
* The test now pins all three shapes of that path: `None` prefixes `! `,
Rgb leaves the message verbatim, and an already-prefixed alert is not
double-prefixed.
Also fix the second, same-class race the 20x repeat surfaced:
`wallets_settings_menu_frame_shows_the_shipped_footer` compares a rendered
frame against `status_footer_phased` computed moments earlier, and both read
`ascii_chrome()`/`color_mode()` live — a concurrent `ONIONWIRE_ASCII=1` made
the two sides disagree (✓/… vs ok/...). It now takes the same `ASCII_ENV`
lock and forces the unicode mode.
Evidence (TMPDIR=/home/lancelot/.hermes/tmp/onionwire-tui):
* cargo test --locked -> exit 0, 35 suites, 472 passed, 0 failed, 4 ignored
* cargo clippy --locked --all-targets -- -D warnings -> exit 0
* cargo test --locked --test tui_spec x60 -> 60 ok, 0 failures
* teeth: with the `! ` prefix removed from the None path, the test fails
("expected '! ' prefix in None mode: \"peer down\"") — reverted.
* ONIONWIRE_ASCII=1 cargo test --locked --test tui_spec -> 37 passed (no
unlocked test's outcome depends on the ambient value)
* rustfmt --edition 2024 --check on both files: only the inherited hunks
(src/tui.rs 16 == HEAD 16; tests/tui_spec.rs 3 vs HEAD 4, one inherited
hunk reformatted away by this edit)
2026-09-26 22:46:43 -04:00
// ColorMode::None (NO_COLOR) → alert_line prepends "! ". The mode is
// injected rather than read from the process env: other tests in this
// binary flip NO_COLOR concurrently, which made the env version flaky.
let plain = alert_line_for_mode ( ColorMode ::None , " peer down " , 80 ) ;
assert! (
plain . starts_with ( " ! " ) ,
" expected '! ' prefix in None mode: {plain:?} "
) ;
// The ornament belongs to the None path only; RGB keeps the message verbatim.
assert_eq! (
alert_line_for_mode ( ColorMode ::Rgb , " peer down " , 80 ) ,
" peer down "
) ;
// An alert that already carries the ornament is not double-prefixed.
assert_eq! (
alert_line_for_mode ( ColorMode ::None , " ! peer down " , 80 ) ,
" ! peer down "
) ;
2026-09-15 17:29:26 -04:00
}
tui: WALLETS and SETTINGS menu (F9 / /settings) over the landed wallet + node features
The Monero wallet and the cuprate node shipped behind function keys only, so a
user who did not already know F6 opened the wallet could not find wallet setup,
the child wallet, the chain source or the settings.
F9 (also /settings) now opens one discoverable screen with the two groups the
card fixes: WALLET (endpoint, child, sync, receive, balance, payments, create,
import) then SETTINGS (nickname, profile, identity, colour, backup, restore,
wipe, wipe-all). Every actionable row prints the key or command that fires it,
including the F6 wallet screen's own keys, and those keys stay live on the
screen so no row can name a dead key.
- Screen, not popup: 19 rows at 80x24 against 21 inner rows; 120x40 and 200x60
hold. The footer is the shared status_footer, so TOR / identity / ? help stay
put.
- No credentials: WalletMenuState carries booleans, labels and display-ready
error strings only. rpc_login, secret(), seeds and passphrases have no field
to travel in.
- Untrusted values are display data: sanitize + newline/tab strip, then
truncated in cells.
- Cells, not chars: cell_width() measures through ratatui's own Span::width, so
no unicode-width dependency was added and chars().count() is never a width.
- Copy without a clipboard crate: c writes the receive address as an OSC 52
sequence; the terminal owns the clipboard and it survives SSH.
- Colour is never the only signal: every state also spells itself out.
- F7 stays free for the endpoint config screen that names it (db208be,
docs/WALLET.md).
F2/F3/F4/F5/F6/F8 keep working: the function keys are now handled once, for Main
and this screen, instead of inside the Main arm.
2026-09-18 22:26:57 -04:00
// ---------------------------------------------------------------------------
// WALLETS & SETTINGS menu (F9 / `/settings`)
// ---------------------------------------------------------------------------
/// A 94-character base58 receive address (a real one is 95; the exact length is
/// not load-bearing, only that it is far wider than the value column).
const SAMPLE_ADDR : & str = " 4AdUndXHHZ6cfufTMvppY6JwXNouMBzSkbLYfpAV5Usx3skxNgYeYJKUGVktfzxayGbMWaC8iqPUE9XUBFGrLyDz4DpEBM " ;
fn menu_state ( ) -> WalletMenuState {
WalletMenuState {
configured : true ,
connected : true ,
wallet_error : None ,
receive_addr : SAMPLE_ADDR . into ( ) ,
balance : " 0.250000000000 " . into ( ) ,
transfers : 3 ,
child_state : " ready " . into ( ) ,
child_source : " local node " . into ( ) ,
child_error : None ,
nickname : Some ( " lance " . into ( ) ) ,
bio_set : true ,
xmr_set : true ,
me_fp : FP . into ( ) ,
tui: peer payment history behind the F9 `payments` row (key p)
The F9 / `/settings` menu's only payment row showed the wallet's own transfer
list (`Node::wallet_recent_transfers`, F6). The signed `/pay` invoices and
`/tip` receipts a peer sent live in the `payments` table and had no path from
the TUI, so they were invisible. `Node::list_payments` (PR #119) closes that
gap; this wires it into a screen.
- `Screen::PeerPayments { state }` + `PeerPaymentsState` /
`PeerPaymentRow`, built by `PeerPaymentsState::from_payments` from
`Node::list_payments`' rows (newest first: the store returns `payments.id`
ascending, the screen windows the vector).
- Key handler: `p` on the F9 screen opens it (`open_peer_payments`); `up`/`down`
(or `k`/`j`) move the selection, `Esc` goes back, `F9` reopens the menu.
- Rows carry direction, kind, amount (`pay::atomic_to_xmr_str`, the same
piconero formatter the chat lines use), memo (sanitized at draw time) and the
receipt's `verified` / `unverified` word; the focused row is marked with `>`
and bold. The selected row's txid and address sit under the rows — the
address wrapped over two lines rather than clipped.
- States: populated, `no payments with {peer}`, `could not read payments`, and
a menu row that refuses when no friend is selected. An empty history is a
state, never an error.
- Menu: the wallet's own list is retitled `transfers` (F6, unchanged), and the
new `payments` row (key `p`) names the peer and the count. Two histories, two
rows, no ambiguity.
- Widths are measured in cells (`Span::width`); trailing columns are dropped
before they can wrap, so the body fits 80x24 (20 inner rows of 21) as well as
120x40 and 200x60.
Tests: new `tests/tui_payments.rs` (11 tests) dumps and asserts the screen at
80x24, 120x40 and 200x60 including the empty history, asserts a memo carrying
ESC/BEL/C1/bidi/newline bytes never reaches the frame buffer, and asserts the
window/column invariants for every width from 20 to 200.
Also relaxes one width assertion in `tests/tui_spec.rs`: `fit_cells` was
asserted to start with `"abcdef"`, which only holds when another test's
in-flight `ONIONWIRE_ASCII` mutation is not visible — the suite mutates env vars
without a global lock, so that test flaked (it also fails on an unmodified tree,
1 run in 2). It now accepts either chrome's cut point, which is what the comment
already claimed.
Docs: `docs/TUI.md` gains the screen's section, the retitled/replaced rows and
the updated row count; the "peer payment history" gap entry is closed.
2026-09-18 23:53:10 -04:00
peer : " lance " . into ( ) ,
peer_payments : Some ( 3 ) ,
tui: WALLETS and SETTINGS menu (F9 / /settings) over the landed wallet + node features
The Monero wallet and the cuprate node shipped behind function keys only, so a
user who did not already know F6 opened the wallet could not find wallet setup,
the child wallet, the chain source or the settings.
F9 (also /settings) now opens one discoverable screen with the two groups the
card fixes: WALLET (endpoint, child, sync, receive, balance, payments, create,
import) then SETTINGS (nickname, profile, identity, colour, backup, restore,
wipe, wipe-all). Every actionable row prints the key or command that fires it,
including the F6 wallet screen's own keys, and those keys stay live on the
screen so no row can name a dead key.
- Screen, not popup: 19 rows at 80x24 against 21 inner rows; 120x40 and 200x60
hold. The footer is the shared status_footer, so TOR / identity / ? help stay
put.
- No credentials: WalletMenuState carries booleans, labels and display-ready
error strings only. rpc_login, secret(), seeds and passphrases have no field
to travel in.
- Untrusted values are display data: sanitize + newline/tab strip, then
truncated in cells.
- Cells, not chars: cell_width() measures through ratatui's own Span::width, so
no unicode-width dependency was added and chars().count() is never a width.
- Copy without a clipboard crate: c writes the receive address as an OSC 52
sequence; the terminal owns the clipboard and it survives SSH.
- Colour is never the only signal: every state also spells itself out.
- F7 stays free for the endpoint config screen that names it (db208be,
docs/WALLET.md).
F2/F3/F4/F5/F6/F8 keep working: the function keys are now handled once, for Main
and this screen, instead of inside the Main arm.
2026-09-18 22:26:57 -04:00
}
}
/// 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 " ) ;
2026-09-19 01:18:47 -04:00
// 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 ( ) ,
) ;
tui: WALLETS and SETTINGS menu (F9 / /settings) over the landed wallet + node features
The Monero wallet and the cuprate node shipped behind function keys only, so a
user who did not already know F6 opened the wallet could not find wallet setup,
the child wallet, the chain source or the settings.
F9 (also /settings) now opens one discoverable screen with the two groups the
card fixes: WALLET (endpoint, child, sync, receive, balance, payments, create,
import) then SETTINGS (nickname, profile, identity, colour, backup, restore,
wipe, wipe-all). Every actionable row prints the key or command that fires it,
including the F6 wallet screen's own keys, and those keys stay live on the
screen so no row can name a dead key.
- Screen, not popup: 19 rows at 80x24 against 21 inner rows; 120x40 and 200x60
hold. The footer is the shared status_footer, so TOR / identity / ? help stay
put.
- No credentials: WalletMenuState carries booleans, labels and display-ready
error strings only. rpc_login, secret(), seeds and passphrases have no field
to travel in.
- Untrusted values are display data: sanitize + newline/tab strip, then
truncated in cells.
- Cells, not chars: cell_width() measures through ratatui's own Span::width, so
no unicode-width dependency was added and chars().count() is never a width.
- Copy without a clipboard crate: c writes the receive address as an OSC 52
sequence; the terminal owns the clipboard and it survives SSH.
- Colour is never the only signal: every state also spells itself out.
- F7 stays free for the endpoint config screen that names it (db208be,
docs/WALLET.md).
F2/F3/F4/F5/F6/F8 keep working: the function keys are now handled once, for Main
and this screen, instead of inside the Main arm.
2026-09-18 22:26:57 -04:00
terminal
. draw ( | f | draw_wallets_settings ( f , st , & footer ) )
. expect ( " draw " ) ;
screen_from ( terminal . backend ( ) . buffer ( ) , w , h )
}
2026-09-19 01:18:47 -04:00
#[ test ]
fn wallets_settings_menu_frame_shows_the_shipped_footer ( ) {
tests/tui_spec: remove the NO_COLOR env race behind the flaky suite
`alert_line_prefixes_when_no_color` flipped the process-global `NO_COLOR`
without the `ASCII_ENV` mutex the other env-touching tests in this binary
hold, so a concurrent `remove_var("NO_COLOR")` could win and make
`alert_line()` resolve to Rgb/Ansi16 — the `! ` assertion then failed on an
otherwise green run (measured 1/12 runs at cc1201d).
Inject the colour mode instead of reading the environment in the test:
* `tui::alert_line_for_mode(mode, msg, width)` — `alert_line()` is now a
one-line delegate passing `color_mode()`, so production behaviour is
unchanged and the no-colour path is asserted without touching the env.
* The test now pins all three shapes of that path: `None` prefixes `! `,
Rgb leaves the message verbatim, and an already-prefixed alert is not
double-prefixed.
Also fix the second, same-class race the 20x repeat surfaced:
`wallets_settings_menu_frame_shows_the_shipped_footer` compares a rendered
frame against `status_footer_phased` computed moments earlier, and both read
`ascii_chrome()`/`color_mode()` live — a concurrent `ONIONWIRE_ASCII=1` made
the two sides disagree (✓/… vs ok/...). It now takes the same `ASCII_ENV`
lock and forces the unicode mode.
Evidence (TMPDIR=/home/lancelot/.hermes/tmp/onionwire-tui):
* cargo test --locked -> exit 0, 35 suites, 472 passed, 0 failed, 4 ignored
* cargo clippy --locked --all-targets -- -D warnings -> exit 0
* cargo test --locked --test tui_spec x60 -> 60 ok, 0 failures
* teeth: with the `! ` prefix removed from the None path, the test fails
("expected '! ' prefix in None mode: \"peer down\"") — reverted.
* ONIONWIRE_ASCII=1 cargo test --locked --test tui_spec -> 37 passed (no
unlocked test's outcome depends on the ambient value)
* rustfmt --edition 2024 --check on both files: only the inherited hunks
(src/tui.rs 16 == HEAD 16; tests/tui_spec.rs 3 vs HEAD 4, one inherited
hunk reformatted away by this edit)
2026-09-26 22:46:43 -04:00
// 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 ( ) ;
2026-09-19 01:18:47 -04:00
// 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 "
) ;
}
tui: WALLETS and SETTINGS menu (F9 / /settings) over the landed wallet + node features
The Monero wallet and the cuprate node shipped behind function keys only, so a
user who did not already know F6 opened the wallet could not find wallet setup,
the child wallet, the chain source or the settings.
F9 (also /settings) now opens one discoverable screen with the two groups the
card fixes: WALLET (endpoint, child, sync, receive, balance, payments, create,
import) then SETTINGS (nickname, profile, identity, colour, backup, restore,
wipe, wipe-all). Every actionable row prints the key or command that fires it,
including the F6 wallet screen's own keys, and those keys stay live on the
screen so no row can name a dead key.
- Screen, not popup: 19 rows at 80x24 against 21 inner rows; 120x40 and 200x60
hold. The footer is the shared status_footer, so TOR / identity / ? help stay
put.
- No credentials: WalletMenuState carries booleans, labels and display-ready
error strings only. rpc_login, secret(), seeds and passphrases have no field
to travel in.
- Untrusted values are display data: sanitize + newline/tab strip, then
truncated in cells.
- Cells, not chars: cell_width() measures through ratatui's own Span::width, so
no unicode-width dependency was added and chars().count() is never a width.
- Copy without a clipboard crate: c writes the receive address as an OSC 52
sequence; the terminal owns the clipboard and it survives SSH.
- Colour is never the only signal: every state also spells itself out.
- F7 stays free for the endpoint config screen that names it (db208be,
docs/WALLET.md).
F2/F3/F4/F5/F6/F8 keep working: the function keys are now handled once, for Main
and this screen, instead of inside the Main arm.
2026-09-18 22:26:57 -04:00
#[ test ]
fn wallets_settings_menu_lists_both_groups_and_every_key ( ) {
let body = wallets_settings_menu_text ( 78 , & menu_state ( ) ) ;
let wallet_at = body . find ( " WALLET " ) . expect ( " wallet header " ) ;
let settings_at = body . find ( " SETTINGS " ) . expect ( " settings header " ) ;
assert! ( wallet_at < settings_at , " WALLET must come first: \n {body} " ) ;
for needle in [
" endpoint " , " child " , " sync " , " receive " , " balance " , " payments " , " create " , " import " ,
] {
assert! (
body . contains ( needle ) ,
" WALLET row {needle:?} missing: \n {body} "
) ;
}
for needle in [
" nickname " , " profile " , " identity " , " colour " , " backup " , " restore " , " wipe " ,
] {
assert! (
body . contains ( needle ) ,
" SETTINGS row {needle:?} missing: \n {body} "
) ;
}
// Every actionable row names the key or command that fires it, including the
tui: F7 becomes the node-setup screen, and F6 goes back to being the wallet
The chain source was reachable from three places and configured from none of
them properly: `F6`'s inline `1`/`2`/`3` picker wrote only the in-process
choice, the `F9` menu showed the state and named keys that edited it, and
`Node::set_local_monerod` / `set_remote_daemon` / `set_receive_only` — the only
way to point the app at a Monero node — had **no TUI caller at all** (Kotlin
only). `wallet::NOT_CONFIGURED_MSG` told users to "open F7" and there was no F7.
F7 (`WalletSetupConfig`) is now the one screen that sets up the node:
- The `datadir` row is new and editable. `Node::set_local_monerod_at` takes the
path; `set_local_monerod` delegates with the derived default, so an existing
install keeps the store it already has. An empty datadir is refused rather
than silently replaced — a store that moved unasked looks like a vanished
chain and resyncs somewhere the user did not choose.
- The `network` row is new: it carries the Cuprate mainnet/testnet choice that
`F6`'s `1`/`2`/`3` used to own, so deleting those keys loses nothing. Mainnet
reads `unvalidated` before it is picked.
- A `NODE` section shows the live `Node::wallet_child_status` line (state, chain
source, `sync h/t`, last error) and the last save/test answer. It is the
node's answer, never the draft above it, and `Ctrl-R` re-reads it.
- `Ctrl-S` saves and starts the child (the daemon, and `monerod` for a local
source); `Ctrl-X` stops it. Both go through the same `Node::start_wallet_child`
/ `stop_wallet_child` the app's own lifecycle uses, so a start that lands on a
wallet with no stored passphrase still reaches the unlock prompt.
F6 loses the chain picker and the `s`/`x`/`p` child keys — it is the wallet
again (receive, balance, transfers, create/import) — and its footer points at
`F7 node`. The `F9` menu's `child`/`sync` rows now name `F7 ctrl-s/x` and
`F7 ctrl-r` instead of keys that no longer exist on F6. `set_cuprate_chain` and
the `p` probe handler are deleted rather than left dead.
The node's own keys are named in the body, on the section they act on: at 80
columns the footer has room for one group and the status line already spends
half the width, which is the same reason the login row names `Ctrl-U`.
Tests: six new cases in `src/tui.rs`'s `wallet_setup_config_tests` drive the real
key path and the real node — the typed datadir reaching `ChainSource::Local`, an
empty one being refused with nothing written, the live row on open, `Ctrl-S`
saving then reporting the node's own refusal, the in-process network pick
reaching the store, and F6 no longer owning keys it does not handle.
`tests/tui_spec.rs`'s menu-key check now asserts the F7 keys; the F6 keys it
asserted before no longer work.
2026-09-27 20:06:51 -04:00
// 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.
tui: WALLETS and SETTINGS menu (F9 / /settings) over the landed wallet + node features
The Monero wallet and the cuprate node shipped behind function keys only, so a
user who did not already know F6 opened the wallet could not find wallet setup,
the child wallet, the chain source or the settings.
F9 (also /settings) now opens one discoverable screen with the two groups the
card fixes: WALLET (endpoint, child, sync, receive, balance, payments, create,
import) then SETTINGS (nickname, profile, identity, colour, backup, restore,
wipe, wipe-all). Every actionable row prints the key or command that fires it,
including the F6 wallet screen's own keys, and those keys stay live on the
screen so no row can name a dead key.
- Screen, not popup: 19 rows at 80x24 against 21 inner rows; 120x40 and 200x60
hold. The footer is the shared status_footer, so TOR / identity / ? help stay
put.
- No credentials: WalletMenuState carries booleans, labels and display-ready
error strings only. rpc_login, secret(), seeds and passphrases have no field
to travel in.
- Untrusted values are display data: sanitize + newline/tab strip, then
truncated in cells.
- Cells, not chars: cell_width() measures through ratatui's own Span::width, so
no unicode-width dependency was added and chars().count() is never a width.
- Copy without a clipboard crate: c writes the receive address as an OSC 52
sequence; the terminal owns the clipboard and it survives SSH.
- Colour is never the only signal: every state also spells itself out.
- F7 stays free for the endpoint config screen that names it (db208be,
docs/WALLET.md).
F2/F3/F4/F5/F6/F8 keep working: the function keys are now handled once, for Main
and this screen, instead of inside the Main arm.
2026-09-18 22:26:57 -04:00
for key in [
tui: F7 becomes the node-setup screen, and F6 goes back to being the wallet
The chain source was reachable from three places and configured from none of
them properly: `F6`'s inline `1`/`2`/`3` picker wrote only the in-process
choice, the `F9` menu showed the state and named keys that edited it, and
`Node::set_local_monerod` / `set_remote_daemon` / `set_receive_only` — the only
way to point the app at a Monero node — had **no TUI caller at all** (Kotlin
only). `wallet::NOT_CONFIGURED_MSG` told users to "open F7" and there was no F7.
F7 (`WalletSetupConfig`) is now the one screen that sets up the node:
- The `datadir` row is new and editable. `Node::set_local_monerod_at` takes the
path; `set_local_monerod` delegates with the derived default, so an existing
install keeps the store it already has. An empty datadir is refused rather
than silently replaced — a store that moved unasked looks like a vanished
chain and resyncs somewhere the user did not choose.
- The `network` row is new: it carries the Cuprate mainnet/testnet choice that
`F6`'s `1`/`2`/`3` used to own, so deleting those keys loses nothing. Mainnet
reads `unvalidated` before it is picked.
- A `NODE` section shows the live `Node::wallet_child_status` line (state, chain
source, `sync h/t`, last error) and the last save/test answer. It is the
node's answer, never the draft above it, and `Ctrl-R` re-reads it.
- `Ctrl-S` saves and starts the child (the daemon, and `monerod` for a local
source); `Ctrl-X` stops it. Both go through the same `Node::start_wallet_child`
/ `stop_wallet_child` the app's own lifecycle uses, so a start that lands on a
wallet with no stored passphrase still reaches the unlock prompt.
F6 loses the chain picker and the `s`/`x`/`p` child keys — it is the wallet
again (receive, balance, transfers, create/import) — and its footer points at
`F7 node`. The `F9` menu's `child`/`sync` rows now name `F7 ctrl-s/x` and
`F7 ctrl-r` instead of keys that no longer exist on F6. `set_cuprate_chain` and
the `p` probe handler are deleted rather than left dead.
The node's own keys are named in the body, on the section they act on: at 80
columns the footer has room for one group and the status line already spends
half the width, which is the same reason the login row names `Ctrl-U`.
Tests: six new cases in `src/tui.rs`'s `wallet_setup_config_tests` drive the real
key path and the real node — the typed datadir reaching `ChainSource::Local`, an
empty one being refused with nothing written, the live row on open, `Ctrl-S`
saving then reporting the node's own refusal, the in-process network pick
reaching the store, and F6 no longer owning keys it does not handle.
`tests/tui_spec.rs`'s menu-key check now asserts the F7 keys; the F6 keys it
asserted before no longer work.
2026-09-27 20:06:51 -04:00
" F7 ctrl-s/x " ,
" F7 ctrl-r " ,
tui: peer payment history behind the F9 `payments` row (key p)
The F9 / `/settings` menu's only payment row showed the wallet's own transfer
list (`Node::wallet_recent_transfers`, F6). The signed `/pay` invoices and
`/tip` receipts a peer sent live in the `payments` table and had no path from
the TUI, so they were invisible. `Node::list_payments` (PR #119) closes that
gap; this wires it into a screen.
- `Screen::PeerPayments { state }` + `PeerPaymentsState` /
`PeerPaymentRow`, built by `PeerPaymentsState::from_payments` from
`Node::list_payments`' rows (newest first: the store returns `payments.id`
ascending, the screen windows the vector).
- Key handler: `p` on the F9 screen opens it (`open_peer_payments`); `up`/`down`
(or `k`/`j`) move the selection, `Esc` goes back, `F9` reopens the menu.
- Rows carry direction, kind, amount (`pay::atomic_to_xmr_str`, the same
piconero formatter the chat lines use), memo (sanitized at draw time) and the
receipt's `verified` / `unverified` word; the focused row is marked with `>`
and bold. The selected row's txid and address sit under the rows — the
address wrapped over two lines rather than clipped.
- States: populated, `no payments with {peer}`, `could not read payments`, and
a menu row that refuses when no friend is selected. An empty history is a
state, never an error.
- Menu: the wallet's own list is retitled `transfers` (F6, unchanged), and the
new `payments` row (key `p`) names the peer and the count. Two histories, two
rows, no ambiguity.
- Widths are measured in cells (`Span::width`); trailing columns are dropped
before they can wrap, so the body fits 80x24 (20 inner rows of 21) as well as
120x40 and 200x60.
Tests: new `tests/tui_payments.rs` (11 tests) dumps and asserts the screen at
80x24, 120x40 and 200x60 including the empty history, asserts a memo carrying
ESC/BEL/C1/bidi/newline bytes never reaches the frame buffer, and asserts the
window/column invariants for every width from 20 to 200.
Also relaxes one width assertion in `tests/tui_spec.rs`: `fit_cells` was
asserted to start with `"abcdef"`, which only holds when another test's
in-flight `ONIONWIRE_ASCII` mutation is not visible — the suite mutates env vars
without a global lock, so that test flaked (it also fails on an unmodified tree,
1 run in 2). It now accepts either chrome's cut point, which is what the comment
already claimed.
Docs: `docs/TUI.md` gains the screen's section, the retitled/replaced rows and
the updated row count; the "peer payment history" gap entry is closed.
2026-09-18 23:53:10 -04:00
" c copy F6 r " ,
" F6 c " ,
" F6 i " ,
" F6 r " ,
" F2 " ,
" /profile " ,
" /backup " ,
" /restore " ,
" /wipe " ,
" /wipe-all " ,
tui: WALLETS and SETTINGS menu (F9 / /settings) over the landed wallet + node features
The Monero wallet and the cuprate node shipped behind function keys only, so a
user who did not already know F6 opened the wallet could not find wallet setup,
the child wallet, the chain source or the settings.
F9 (also /settings) now opens one discoverable screen with the two groups the
card fixes: WALLET (endpoint, child, sync, receive, balance, payments, create,
import) then SETTINGS (nickname, profile, identity, colour, backup, restore,
wipe, wipe-all). Every actionable row prints the key or command that fires it,
including the F6 wallet screen's own keys, and those keys stay live on the
screen so no row can name a dead key.
- Screen, not popup: 19 rows at 80x24 against 21 inner rows; 120x40 and 200x60
hold. The footer is the shared status_footer, so TOR / identity / ? help stay
put.
- No credentials: WalletMenuState carries booleans, labels and display-ready
error strings only. rpc_login, secret(), seeds and passphrases have no field
to travel in.
- Untrusted values are display data: sanitize + newline/tab strip, then
truncated in cells.
- Cells, not chars: cell_width() measures through ratatui's own Span::width, so
no unicode-width dependency was added and chars().count() is never a width.
- Copy without a clipboard crate: c writes the receive address as an OSC 52
sequence; the terminal owns the clipboard and it survives SSH.
- Colour is never the only signal: every state also spells itself out.
- F7 stays free for the endpoint config screen that names it (db208be,
docs/WALLET.md).
F2/F3/F4/F5/F6/F8 keep working: the function keys are now handled once, for Main
and this screen, instead of inside the Main arm.
2026-09-18 22:26:57 -04:00
] {
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 \n line two \n line three " . into ( ) ) ,
nickname : Some ( " tab \t here " . 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} " ) ;
tui: peer payment history behind the F9 `payments` row (key p)
The F9 / `/settings` menu's only payment row showed the wallet's own transfer
list (`Node::wallet_recent_transfers`, F6). The signed `/pay` invoices and
`/tip` receipts a peer sent live in the `payments` table and had no path from
the TUI, so they were invisible. `Node::list_payments` (PR #119) closes that
gap; this wires it into a screen.
- `Screen::PeerPayments { state }` + `PeerPaymentsState` /
`PeerPaymentRow`, built by `PeerPaymentsState::from_payments` from
`Node::list_payments`' rows (newest first: the store returns `payments.id`
ascending, the screen windows the vector).
- Key handler: `p` on the F9 screen opens it (`open_peer_payments`); `up`/`down`
(or `k`/`j`) move the selection, `Esc` goes back, `F9` reopens the menu.
- Rows carry direction, kind, amount (`pay::atomic_to_xmr_str`, the same
piconero formatter the chat lines use), memo (sanitized at draw time) and the
receipt's `verified` / `unverified` word; the focused row is marked with `>`
and bold. The selected row's txid and address sit under the rows — the
address wrapped over two lines rather than clipped.
- States: populated, `no payments with {peer}`, `could not read payments`, and
a menu row that refuses when no friend is selected. An empty history is a
state, never an error.
- Menu: the wallet's own list is retitled `transfers` (F6, unchanged), and the
new `payments` row (key `p`) names the peer and the count. Two histories, two
rows, no ambiguity.
- Widths are measured in cells (`Span::width`); trailing columns are dropped
before they can wrap, so the body fits 80x24 (20 inner rows of 21) as well as
120x40 and 200x60.
Tests: new `tests/tui_payments.rs` (11 tests) dumps and asserts the screen at
80x24, 120x40 and 200x60 including the empty history, asserts a memo carrying
ESC/BEL/C1/bidi/newline bytes never reaches the frame buffer, and asserts the
window/column invariants for every width from 20 to 200.
Also relaxes one width assertion in `tests/tui_spec.rs`: `fit_cells` was
asserted to start with `"abcdef"`, which only holds when another test's
in-flight `ONIONWIRE_ASCII` mutation is not visible — the suite mutates env vars
without a global lock, so that test flaked (it also fails on an unmodified tree,
1 run in 2). It now accepts either chrome's cut point, which is what the comment
already claimed.
Docs: `docs/TUI.md` gains the screen's section, the retitled/replaced rows and
the updated row count; the "peer payment history" gap entry is closed.
2026-09-18 23:53:10 -04:00
assert! (
body . contains ( " wallet answering · chain not at tip " ) ,
" \n {body} "
) ;
tui: WALLETS and SETTINGS menu (F9 / /settings) over the landed wallet + node features
The Monero wallet and the cuprate node shipped behind function keys only, so a
user who did not already know F6 opened the wallet could not find wallet setup,
the child wallet, the chain source or the settings.
F9 (also /settings) now opens one discoverable screen with the two groups the
card fixes: WALLET (endpoint, child, sync, receive, balance, payments, create,
import) then SETTINGS (nickname, profile, identity, colour, backup, restore,
wipe, wipe-all). Every actionable row prints the key or command that fires it,
including the F6 wallet screen's own keys, and those keys stay live on the
screen so no row can name a dead key.
- Screen, not popup: 19 rows at 80x24 against 21 inner rows; 120x40 and 200x60
hold. The footer is the shared status_footer, so TOR / identity / ? help stay
put.
- No credentials: WalletMenuState carries booleans, labels and display-ready
error strings only. rpc_login, secret(), seeds and passphrases have no field
to travel in.
- Untrusted values are display data: sanitize + newline/tab strip, then
truncated in cells.
- Cells, not chars: cell_width() measures through ratatui's own Span::width, so
no unicode-width dependency was added and chars().count() is never a width.
- Copy without a clipboard crate: c writes the receive address as an OSC 52
sequence; the terminal owns the clipboard and it survives SSH.
- Colour is never the only signal: every state also spells itself out.
- F7 stays free for the endpoint config screen that names it (db208be,
docs/WALLET.md).
F2/F3/F4/F5/F6/F8 keep working: the function keys are now handled once, for Main
and this screen, instead of inside the Main arm.
2026-09-18 22:26:57 -04:00
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 [ 78 u16 , 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
tui: clean-look chrome redesign (one accent, honest tor phase, real frames)
Applies the bitchat-tui clean-look principles to the OnionWire main screen.
- Hierarchy: header, roster + one primary chat pane, one status line, one
footer hint line. The header gives up the accent (the accent is reserved
for focus), so it stops competing with the panes.
- Tor phase is a first-class state: Node::tor_state() -> TorPhase (glyph +
word, header and footer) so connecting / ready / degraded / off are never
colour-only and never implied. No new data field.
- Footer changes with the focused pane (pane_footer_hints) and the phase; the
main footer drops the redundant onion (the header already prints it) and
uses those cells for hints. status_footer keeps its signature and strings.
- Empty roster / empty chat / connecting / degraded / off are designed states
with their own copy, not blank panes.
- draw_main_chrome + MainView: the real main render path is public and
Node-free, so tests/tui_frames.rs dumps the actual chrome at 80x24, 120x40
and 200x60 (12 tests, 5 states, real Message/OutboxEntry rows) instead of a
reconstructed stand-in.
- Widths in cells everywhere touched: status_footer*, alert_line,
main_header_line*, draw_text_overlay, roster_row_text. The roster spends its
budget name-first, so a 22-cell pane reads `bob-the-sta… stale` instead of
`… bbbbbbbb… stale`.
- draw_text_overlay is centered with a one-cell side margin and clears
underneath; never full-bleed.
Also fixes a pre-existing race in tests/tui_spec.rs (the ellipsis-form
assertion did not tolerate ONIONWIRE_ASCII being set by a parallel test).
Co-Authored-By: Hermes <[email protected] >
2026-09-18 23:13:12 -04:00
// 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.
tui: WALLETS and SETTINGS menu (F9 / /settings) over the landed wallet + node features
The Monero wallet and the cuprate node shipped behind function keys only, so a
user who did not already know F6 opened the wallet could not find wallet setup,
the child wallet, the chain source or the settings.
F9 (also /settings) now opens one discoverable screen with the two groups the
card fixes: WALLET (endpoint, child, sync, receive, balance, payments, create,
import) then SETTINGS (nickname, profile, identity, colour, backup, restore,
wipe, wipe-all). Every actionable row prints the key or command that fires it,
including the F6 wallet screen's own keys, and those keys stay live on the
screen so no row can name a dead key.
- Screen, not popup: 19 rows at 80x24 against 21 inner rows; 120x40 and 200x60
hold. The footer is the shared status_footer, so TOR / identity / ? help stay
put.
- No credentials: WalletMenuState carries booleans, labels and display-ready
error strings only. rpc_login, secret(), seeds and passphrases have no field
to travel in.
- Untrusted values are display data: sanitize + newline/tab strip, then
truncated in cells.
- Cells, not chars: cell_width() measures through ratatui's own Span::width, so
no unicode-width dependency was added and chars().count() is never a width.
- Copy without a clipboard crate: c writes the receive address as an OSC 52
sequence; the terminal owns the clipboard and it survives SSH.
- Colour is never the only signal: every state also spells itself out.
- F7 stays free for the endpoint config screen that names it (db208be,
docs/WALLET.md).
F2/F3/F4/F5/F6/F8 keep working: the function keys are now handled once, for Main
and this screen, instead of inside the Main arm.
2026-09-18 22:26:57 -04:00
let ascii = fit_cells ( " abcdefghij " , 8 ) ;
assert! ( cell_width ( & ascii ) < = 8 , " {ascii:?} " ) ;
tui: clean-look chrome redesign (one accent, honest tor phase, real frames)
Applies the bitchat-tui clean-look principles to the OnionWire main screen.
- Hierarchy: header, roster + one primary chat pane, one status line, one
footer hint line. The header gives up the accent (the accent is reserved
for focus), so it stops competing with the panes.
- Tor phase is a first-class state: Node::tor_state() -> TorPhase (glyph +
word, header and footer) so connecting / ready / degraded / off are never
colour-only and never implied. No new data field.
- Footer changes with the focused pane (pane_footer_hints) and the phase; the
main footer drops the redundant onion (the header already prints it) and
uses those cells for hints. status_footer keeps its signature and strings.
- Empty roster / empty chat / connecting / degraded / off are designed states
with their own copy, not blank panes.
- draw_main_chrome + MainView: the real main render path is public and
Node-free, so tests/tui_frames.rs dumps the actual chrome at 80x24, 120x40
and 200x60 (12 tests, 5 states, real Message/OutboxEntry rows) instead of a
reconstructed stand-in.
- Widths in cells everywhere touched: status_footer*, alert_line,
main_header_line*, draw_text_overlay, roster_row_text. The roster spends its
budget name-first, so a 22-cell pane reads `bob-the-sta… stale` instead of
`… bbbbbbbb… stale`.
- draw_text_overlay is centered with a one-cell side margin and clears
underneath; never full-bleed.
Also fixes a pre-existing race in tests/tui_spec.rs (the ellipsis-form
assertion did not tolerate ONIONWIRE_ASCII being set by a parallel test).
Co-Authored-By: Hermes <[email protected] >
2026-09-18 23:13:12 -04:00
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:?} "
) ;
tui: WALLETS and SETTINGS menu (F9 / /settings) over the landed wallet + node features
The Monero wallet and the cuprate node shipped behind function keys only, so a
user who did not already know F6 opened the wallet could not find wallet setup,
the child wallet, the chain source or the settings.
F9 (also /settings) now opens one discoverable screen with the two groups the
card fixes: WALLET (endpoint, child, sync, receive, balance, payments, create,
import) then SETTINGS (nickname, profile, identity, colour, backup, restore,
wipe, wipe-all). Every actionable row prints the key or command that fires it,
including the F6 wallet screen's own keys, and those keys stay live on the
screen so no row can name a dead key.
- Screen, not popup: 19 rows at 80x24 against 21 inner rows; 120x40 and 200x60
hold. The footer is the shared status_footer, so TOR / identity / ? help stay
put.
- No credentials: WalletMenuState carries booleans, labels and display-ready
error strings only. rpc_login, secret(), seeds and passphrases have no field
to travel in.
- Untrusted values are display data: sanitize + newline/tab strip, then
truncated in cells.
- Cells, not chars: cell_width() measures through ratatui's own Span::width, so
no unicode-width dependency was added and chars().count() is never a width.
- Copy without a clipboard crate: c writes the receive address as an OSC 52
sequence; the terminal owns the clipboard and it survives SSH.
- Colour is never the only signal: every state also spells itself out.
- F7 stays free for the endpoint config screen that names it (db208be,
docs/WALLET.md).
F2/F3/F4/F5/F6/F8 keep working: the function keys are now handled once, for Main
and this screen, instead of inside the Main arm.
2026-09-18 22:26:57 -04:00
assert_eq! ( cell_width ( " 名 " ) , 2 ) ;
assert_eq! ( cell_width ( " abc " ) , 3 ) ;
}
#[ test ]
fn wallets_settings_menu_fits_80x24_and_120x40 ( ) {
for ( w , h ) in [ ( 80 u16 , 24 u16 ) , ( 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 [ ( 80 u16 , 24 u16 ) , ( 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 [ ( 80 u16 , 24 u16 ) , ( 120 , 40 ) , ( 200 , 60 ) ] {
println! ( " ===== WALLETS & SETTINGS {w} x {h} ===== " ) ;
print! ( " {} " , render_menu ( w , h , & menu_state ( ) ) ) ;
println! ( " ===== WALLETS & SETTINGS (unconfigured) {w} x {h} ===== " ) ;
print! ( " {} " , render_menu ( w , h , & unconfigured ) ) ;
}
}
#[ test ]
fn osc52_copy_sequence_is_a_base64_clipboard_write ( ) {
// OSC 52: ESC ] 52 ; c ; <base64> BEL — the terminal owns the clipboard, so
// the address never touches a file and no crate is needed.
assert_eq! ( osc52_copy_sequence ( " 4Ada " ) , " \u{1b} ]52;c;NEFkYQ== \u{7} " ) ;
let seq = osc52_copy_sequence ( SAMPLE_ADDR ) ;
let payload = seq
. strip_prefix ( " \u{1b} ]52;c; " )
. and_then ( | s | s . strip_suffix ( '\u{7}' ) )
. expect ( " osc52 envelope " ) ;
assert_eq! ( payload . len ( ) , 128 , " 94 bytes base64 to 128 characters " ) ;
assert! ( payload . ends_with ( " == " ) , " {payload:?} " ) ;
assert! (
payload
. chars ( )
. all ( | c | c . is_ascii_alphanumeric ( ) | | c = = '+' | | c = = '/' | | c = = '=' ) ,
" {payload:?} "
) ;
// Junk cannot escape the sequence: bidi/control characters, a newline and a
// stray BEL are stripped before encoding, and surrounding space is trimmed.
let seq = osc52_copy_sequence ( " 4Ada \u{202e} \n \u{7} " ) ;
assert_eq! ( seq , " \u{1b} ]52;c;NEFkYQ== \u{7} " ) ;
assert_eq! ( osc52_copy_sequence ( " 4Ada " ) , " \u{1b} ]52;c;NEFkYQ== \u{7} " ) ;
}
#[ test ]
fn slash_settings_is_the_menu ( ) {
assert! ( matches! ( parse_cmd ( " /settings " ) , Some ( SlashCmd ::Settings ) ) ) ;
tui: peer payment history behind the F9 `payments` row (key p)
The F9 / `/settings` menu's only payment row showed the wallet's own transfer
list (`Node::wallet_recent_transfers`, F6). The signed `/pay` invoices and
`/tip` receipts a peer sent live in the `payments` table and had no path from
the TUI, so they were invisible. `Node::list_payments` (PR #119) closes that
gap; this wires it into a screen.
- `Screen::PeerPayments { state }` + `PeerPaymentsState` /
`PeerPaymentRow`, built by `PeerPaymentsState::from_payments` from
`Node::list_payments`' rows (newest first: the store returns `payments.id`
ascending, the screen windows the vector).
- Key handler: `p` on the F9 screen opens it (`open_peer_payments`); `up`/`down`
(or `k`/`j`) move the selection, `Esc` goes back, `F9` reopens the menu.
- Rows carry direction, kind, amount (`pay::atomic_to_xmr_str`, the same
piconero formatter the chat lines use), memo (sanitized at draw time) and the
receipt's `verified` / `unverified` word; the focused row is marked with `>`
and bold. The selected row's txid and address sit under the rows — the
address wrapped over two lines rather than clipped.
- States: populated, `no payments with {peer}`, `could not read payments`, and
a menu row that refuses when no friend is selected. An empty history is a
state, never an error.
- Menu: the wallet's own list is retitled `transfers` (F6, unchanged), and the
new `payments` row (key `p`) names the peer and the count. Two histories, two
rows, no ambiguity.
- Widths are measured in cells (`Span::width`); trailing columns are dropped
before they can wrap, so the body fits 80x24 (20 inner rows of 21) as well as
120x40 and 200x60.
Tests: new `tests/tui_payments.rs` (11 tests) dumps and asserts the screen at
80x24, 120x40 and 200x60 including the empty history, asserts a memo carrying
ESC/BEL/C1/bidi/newline bytes never reaches the frame buffer, and asserts the
window/column invariants for every width from 20 to 200.
Also relaxes one width assertion in `tests/tui_spec.rs`: `fit_cells` was
asserted to start with `"abcdef"`, which only holds when another test's
in-flight `ONIONWIRE_ASCII` mutation is not visible — the suite mutates env vars
without a global lock, so that test flaked (it also fails on an unmodified tree,
1 run in 2). It now accepts either chrome's cut point, which is what the comment
already claimed.
Docs: `docs/TUI.md` gains the screen's section, the retitled/replaced rows and
the updated row count; the "peer payment history" gap entry is closed.
2026-09-18 23:53:10 -04:00
assert! ( matches! (
parse_cmd ( " /settings " ) ,
Some ( SlashCmd ::Settings )
) ) ;
tui: WALLETS and SETTINGS menu (F9 / /settings) over the landed wallet + node features
The Monero wallet and the cuprate node shipped behind function keys only, so a
user who did not already know F6 opened the wallet could not find wallet setup,
the child wallet, the chain source or the settings.
F9 (also /settings) now opens one discoverable screen with the two groups the
card fixes: WALLET (endpoint, child, sync, receive, balance, payments, create,
import) then SETTINGS (nickname, profile, identity, colour, backup, restore,
wipe, wipe-all). Every actionable row prints the key or command that fires it,
including the F6 wallet screen's own keys, and those keys stay live on the
screen so no row can name a dead key.
- Screen, not popup: 19 rows at 80x24 against 21 inner rows; 120x40 and 200x60
hold. The footer is the shared status_footer, so TOR / identity / ? help stay
put.
- No credentials: WalletMenuState carries booleans, labels and display-ready
error strings only. rpc_login, secret(), seeds and passphrases have no field
to travel in.
- Untrusted values are display data: sanitize + newline/tab strip, then
truncated in cells.
- Cells, not chars: cell_width() measures through ratatui's own Span::width, so
no unicode-width dependency was added and chars().count() is never a width.
- Copy without a clipboard crate: c writes the receive address as an OSC 52
sequence; the terminal owns the clipboard and it survives SSH.
- Colour is never the only signal: every state also spells itself out.
- F7 stays free for the endpoint config screen that names it (db208be,
docs/WALLET.md).
F2/F3/F4/F5/F6/F8 keep working: the function keys are now handled once, for Main
and this screen, instead of inside the Main arm.
2026-09-18 22:26:57 -04:00
assert! ( parse_cmd ( " /settings now " ) . is_none ( ) ) ;
}