From 02e170114cfed51762b5c52f0b8fce17ba9ce0cf Mon Sep 17 00:00:00 2001 From: agent Date: Sat, 26 Sep 2026 22:43:56 -0400 Subject: [PATCH] tui: size the modal popup from the body's wrapped rows draw_text_overlay sized its height from the body's logical line count, so the 184-char SPEND_AUTHORITY_WARNING (one logical line, three wrapped rows at 80 columns) got a 4-row body box and the scroll-to-tail put only "trust. / Type SPEND to confirm" on screen. Height now comes from the wrapped row count, capped by the frame; a body that still cannot fit scrolls to its tail as before. the_create_flow_is_still_reachable_and_still_warns now asserts the whole warning on the standard 80x24 frame instead of 200x60, via a helper that blanks the popup's border cells (a wrapped sentence has a border glyph between its rows). --- src/tui.rs | 73 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/src/tui.rs b/src/tui.rs index d015a8f..365d672 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -3778,10 +3778,13 @@ fn draw_passphrase(f: &mut Frame, kind: BackupKind, second: bool, buf: &str) { /// tail. Every modal goes through this one, so a popup can never punch through /// the chrome underneath it and can never be wider than the frame. /// -/// Width always keeps a one-cell margin on each side. Height keeps the margin -/// only when the frame can afford it: a 22-line body on a 24-row terminal needs -/// the rows more than it needs symmetry, and the scroll below still lands the -/// last line on screen. +/// Width always keeps a one-cell margin on each side. Height is the body's +/// **wrapped** row count plus the border rows, not its logical line count: one +/// long sentence is three rows on an 80-column terminal, and sizing from the +/// line count used to leave the popup 4 rows tall and scroll the head of that +/// sentence away (`SPEND_AUTHORITY_WARNING`, 184 chars on one line). The frame +/// still caps the height, and only a body that cannot fit the frame at all +/// scrolls — to its tail, so the closing instruction is what stays on screen. pub fn draw_text_overlay(f: &mut Frame, title: &str, text: &str) { let area = f.area(); let wanted_w = text @@ -3790,9 +3793,21 @@ pub fn draw_text_overlay(f: &mut Frame, title: &str, text: &str) { .max() .unwrap_or(40) .saturating_add(4); - let wanted_h = text.lines().count() as u16 + 2; let max_w = area.width.saturating_sub(2).max(10); let width = (wanted_w as u16).clamp(10, max_w.max(10)).min(area.width); + let inner_w = width.saturating_sub(2).max(1); + let wrapped: u16 = text + .lines() + .map(|l| { + let n = cell_width(l) as u16; + if n == 0 { + 1 + } else { + n.div_ceil(inner_w) + } + }) + .sum(); + let wanted_h = wrapped.saturating_add(2); let height = if wanted_h >= area.height.saturating_sub(1) { area.height } else { @@ -3806,19 +3821,7 @@ pub fn draw_text_overlay(f: &mut Frame, title: &str, text: &str) { }; f.render_widget(Clear, area); f.render_widget(Clear, popup); - let inner_w = popup.width.saturating_sub(2).max(1); let inner_h = popup.height.saturating_sub(2); - let wrapped: u16 = text - .lines() - .map(|l| { - let n = cell_width(l) as u16; - if n == 0 { - 1 - } else { - n.div_ceil(inner_w) - } - }) - .sum(); let scroll = wrapped.saturating_sub(inner_h); f.render_widget( Paragraph::new(text) @@ -5697,6 +5700,19 @@ mod wallet_store_tests { text.split_whitespace().collect::>().join(" ") } + /// The drawn frame with the popup's box-drawing cells blanked out: the side + /// borders sit between a wrapped sentence's two rows and are chrome, not + /// copy. Without this, a warning split over two rows reads as + /// `…do not trust.` and no whole-sentence assertion can pass. + fn unframed(text: &str) -> String { + text.chars() + .map(|c| match c { + '\u{2502}' | '\u{250c}' | '\u{2510}' | '\u{2514}' | '\u{2518}' | '\u{2500}' => ' ', + other => other, + }) + .collect() + } + /// Nothing remembered means nothing to warn about: a first run opens on the /// main view, not on the create flow's spend-authority warning. Asserting /// the screen alone would pass with the warning merely drawn behind Main, so @@ -5718,8 +5734,11 @@ mod wallet_store_tests { } /// Moving the entry point did not weaken the warning: `/wallet create` on a - /// fresh install still lands on `CreateWarn`, and the frame really carries - /// the spend-authority copy. + /// fresh install still lands on `CreateWarn`, and the standard 80x24 frame + /// carries the *whole* spend-authority sentence — the popup grows to the + /// body's wrapped rows instead of scrolling the head of it off screen. The + /// whole-sentence assertion used to need a 200x60 frame because of that + /// scroll; it belongs on the standard terminal. #[test] fn the_create_flow_is_still_reachable_and_still_warns() { let dir = tempfile::tempdir().unwrap(); @@ -5738,13 +5757,19 @@ mod wallet_store_tests { ), "the create command must still warn before anything is created" ); - // The overlay is taller than its body and scrolls to its tail, so the - // 80x24 frame carries only the warning's closing words; the whole - // sentence needs a frame wide enough to hold it on one row. let narrow = first_frame(&app); + // Dumped for `cargo test --lib tui:: -- --nocapture`; this frame is the + // evidence that the whole warning, not just its tail, is on screen. + println!("{narrow}"); + let copy = flattened(&unframed(&narrow)); assert!( - flattened(&narrow).contains("trust."), - "the create flow must warn on the standard frame:\n{narrow}" + copy.contains(&flattened(wallet::SPEND_AUTHORITY_WARNING)), + "the spend-authority warning must be readable on the standard 80x24 \ + frame, not just its tail:\n{narrow}" + ); + assert!( + copy.contains("Type SPEND to confirm"), + "the confirmation prompt must be on screen with the warning:\n{narrow}" ); let wide = frame_on(&app, 200, 60); assert!( -- 2.52.0