From 7e0174fda1bd69204eec76b16579e71a9c269aeb Mon Sep 17 00:00:00 2001 From: Noah <2+noah@noreply.gitea.bluefla.re> Date: Fri, 13 Nov 2026 11:01:23 -0600 Subject: [PATCH] feat(gui): progress bar in the Health cell during install/restore (#42) While a board installs or restores, its Health cell shows a phase-based ASCII progress bar ("installing [#######---] 70%") instead of a static "installing". Phases map to indicative, monotonic percents (acquire < verify < write). Adds unit tests for the bar and the phase->percent mapping. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01B1W6qKwKxq3oUPDKWicM6i --- crates/alkane-gui/src/ui.rs | 67 ++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/crates/alkane-gui/src/ui.rs b/crates/alkane-gui/src/ui.rs index a083ea60..937692ae 100644 --- a/crates/alkane-gui/src/ui.rs +++ b/crates/alkane-gui/src/ui.rs @@ -514,6 +514,29 @@ fn encode_status_icon(pal: &Palette, status: &str) -> String { encode_segments(&[(Some(status_kind_color(pal, status)), shape.to_string())]) } +/// An indicative percent for an install/restore phase line, so the Health cell +/// can show a progress bar instead of a static "installing...". Phase-based (the +/// engine streams named phases, not a true byte count), monotonic within a run. +fn stock_progress_pct(msg: &str) -> u8 { + let m = msg.to_ascii_lowercase(); + if m.contains("acquir") || m.contains("using local") { + 15 + } else if m.contains("verify") { + 35 + } else if m.contains("install") || m.contains("restor") || m.contains("writ") { + 70 + } else { + 50 + } +} + +/// A fixed-width ASCII progress bar, e.g. "[######----]", for a 0..=100 percent. +fn ascii_bar(pct: u8) -> String { + let width = 10usize; + let filled = (pct as usize * width / 100).min(width); + format!("[{}{}]", "#".repeat(filled), "-".repeat(width - filled)) +} + /// A read-only flash-plan summary for a local `.afw`: its tier and which regions /// it overwrites (U-Boot / Kernel / Userspace), from the bundle's own manifest. /// Shown in the install dialog when a file is picked so the operator sees exactly @@ -3194,12 +3217,34 @@ impl App { } if let Some(p) = progress { wx_rs::set_status_text(&p); + // Show a progress bar in the Health cell of each in-flight board + // (issue #42: "installing" alone was not enough feedback). + let pct = stock_progress_pct(&p); + let bar = ascii_bar(pct); + let updates: Vec<(String, String)> = self + .op_status + .iter() + .filter(|(_, v)| v.starts_with("installing") || v.starts_with("restoring")) + .map(|(ip, v)| { + let verb = if v.starts_with("restoring") { + "restoring" + } else { + "installing" + }; + (ip.clone(), format!("{verb} {bar} {pct}%")) + }) + .collect(); + for (ip, s) in updates { + self.op_status.insert(ip, s); + } } if done { self.stock_op = None; self.install_targets.clear(); + // Clear any in-progress "installing/restoring [bar] NN%" statuses, but + // keep "installed; verifying alkane..." (starts with "installed"). self.op_status - .retain(|_, v| v != "installing..." && v != "restoring..."); + .retain(|_, v| !v.starts_with("installing") && !v.starts_with("restoring")); } if !op_clear.is_empty() || !verify_ips.is_empty() || done { self.fill_rows(); @@ -6467,6 +6512,26 @@ mod tests { //! cell comparison deliberately strips out, so they need their own coverage. use super::*; + #[test] + fn progress_bar_fills_proportionally() { + assert_eq!(ascii_bar(0), "[----------]"); + assert_eq!(ascii_bar(50), "[#####-----]"); + assert_eq!(ascii_bar(100), "[##########]"); + assert_eq!(ascii_bar(70), "[#######---]"); + // Over-100 is clamped, never panics. + assert_eq!(ascii_bar(200), "[##########]"); + } + + #[test] + fn stock_phase_percents_are_monotonic() { + let acq = stock_progress_pct("acquiring .afw..."); + let ver = stock_progress_pct("verifying .afw..."); + let inst = stock_progress_pct("installing zynq-7010 onto 10.0.0.5 (from stock)..."); + assert!(acq < ver && ver < inst, "{acq} < {ver} < {inst}"); + assert_eq!(stock_progress_pct("using local t.afw..."), acq); + assert_eq!(stock_progress_pct("restoring 10.0.0.5 to stock..."), inst); + } + /// A palette with unambiguous sentinel colours so equality checks are exact. fn test_pal() -> Palette { Palette {