tui: the spend-authority warning is readable on a standard 80x24 terminal #163
1 changed files with 49 additions and 24 deletions
73
src/tui.rs
73
src/tui.rs
|
|
@ -3801,10 +3801,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
|
||||
|
|
@ -3813,9 +3816,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 {
|
||||
|
|
@ -3829,19 +3844,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)
|
||||
|
|
@ -5720,6 +5723,19 @@ mod wallet_store_tests {
|
|||
text.split_whitespace().collect::<Vec<_>>().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 <border> 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
|
||||
|
|
@ -5741,8 +5757,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();
|
||||
|
|
@ -5761,13 +5780,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!(
|
||||
|
|
|
|||
Loading…
Reference in a new issue