garage44.eu/jeroen/pinnacle

logclone: git clone https://garage44.eu/jeroen/pinnacle.git

cartopolis-agent · 2026-11-30T15:43:32Z

feat(xtask): files-demo opens a picture and a file nothing opens

After the notes, the demo fetches harbour.png (drawn here and written by
Wil's PNG encoder) and readings.bin from the host in the Terminal, then
opens both in Files: 9-picture.png shows the picture fitted to the pane,
10-nothing-opens-it.png the other saying nothing here opens it.
xtask/Cargo.toml  |  2 ++
 xtask/src/main.rs | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml
index 7b9b689..19ab171 100644
--- a/xtask/Cargo.toml
+++ b/xtask/Cargo.toml
@@ -26,3 +26,5 @@ pinnacle-modem = { path = "../modem" }
 pinnacle-wifi = { path = "../wifi" }
 # Kees's demo provider, served on this machine for `cargo xtask kees-demo`.
 kees_core = { git = "https://code.garage44.eu/jeroen/kees.git", rev = "17c56be", features = ["demo"] }
+# Wil's PNG writer, for the picture `cargo xtask files-demo` opens in Files.
+wil_core = { git = "https://code.garage44.eu/jeroen/wil.git", rev = "e3cc7d2" }
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 6b98191..e6742e8 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -3451,13 +3451,67 @@ fn contacts_demo() -> Result {
     Ok(())
 }
 
+/// A picture to open in Files, as a PNG: a harbour at dusk, a sun low over
+/// the water and a boat's sail, with a see-through border.
+fn harbour_png() -> Vec<u8> {
+    let (w, h) = (960u32, 640u32);
+    let mut image = wil_core::Image::new(w, h);
+    for (i, p) in image.pixels.chunks_exact_mut(4).enumerate() {
+        let (x, y) = ((i as u32 % w) as i32, (i as u32 / w) as i32);
+        let horizon = 400;
+        let (dx, dy) = (x - 620, y - 330);
+        let sail = (180..300).contains(&y) && x >= 300 && x - 300 < (y - 180) * 2 / 3;
+        let hull =
+            (300..330).contains(&y) && (260..420).contains(&x) && x - 260 > (y - 300) && 420 - x > (y - 300);
+        let rgb = if hull {
+            [60, 40, 35]
+        } else if sail {
+            [245, 240, 225]
+        } else if dx * dx + dy * dy < 60 * 60 && y < horizon {
+            [255, 214, 120]
+        } else if y < horizon {
+            // Sky: deep blue above, orange at the horizon.
+            let t = y * 255 / horizon;
+            [
+                (40 + t * 200 / 255) as u8,
+                (60 + t * 90 / 255) as u8,
+                (120 - t * 60 / 255) as u8,
+            ]
+        } else {
+            // Water, darker further down, the sun's path on it.
+            let t = (y - horizon) * 255 / (h as i32 - horizon);
+            let path = (x - 620).abs() < 40 - (y - horizon) / 8 && (y / 6) % 2 == 0;
+            match path {
+                true => [230, 170, 90],
+                false => [
+                    (30 - t * 20 / 255) as u8,
+                    (70 - t * 40 / 255) as u8,
+                    (110 - t * 50 / 255) as u8,
+                ],
+            }
+        };
+        let border = x < 16 || y < 16 || x >= w as i32 - 16 || y >= h as i32 - 16;
+        p.copy_from_slice(&[rgb[0], rgb[1], rgb[2], if border { 0 } else { 255 }]);
+    }
+    wil_core::png::encode(&image, wil_core::deflate::Level::DEFAULT)
+}
+
 /// Files, used by tapping, photographed into `target/demo-files/`: two
 /// notes written in Notes, found in its folder in Files, one opened and
 /// moved to the person's own files, the other deleted; Notes then has one.
+/// Then a picture and a file that is neither text nor a picture, fetched
+/// in the Terminal, opened in Files: the one shown, the other said so.
 fn files_demo() -> Result {
     const P: &str = "filer: button ";
     let dir = demo_dir("demo-files")?;
-    let mut s = Session::start()?;
+    let url = serve()?;
+    disks(&url)?;
+    std::fs::write(repository().join("harbour.png"), harbour_png()).map_err(|e| e.to_string())?;
+    let odd: Vec<u8> = (0..4096u32)
+        .map(|i| (i.wrapping_mul(2_654_435_761) >> 13) as u8)
+        .collect();
+    std::fs::write(repository().join("readings.bin"), odd).map_err(|e| e.to_string())?;
+    let mut s = Session::boot(&Guest::default(), "")?;
     let (w, _) = s.app();
     s.wait_for(&home_apps(0))?;
     s.tap_named("launcher: tile ", "Notes")?;
@@ -3522,6 +3576,37 @@ fn files_demo() -> Result {
     s.wait_for(&home_apps(0))?;
     s.tap_named("launcher: tile ", "Notes")?;
     s.wait_for("notes: 0 notes")?;
+    s.close()?;
+    s.wait_for("display: closed Notes")?;
+
+    // A picture and a file nothing opens, brought onto the device.
+    s.wait_for(&home_apps(0))?;
+    s.tap_named("launcher: tile ", "Terminal")?;
+    s.wait_for("display: Terminal connected")?;
+    for name in ["harbour.png", "readings.bin"] {
+        let line = format!("fetch {url}{name} {name}");
+        s.type_keys(&format!("{line}\n"))?;
+        s.wait_for(&format!("terminal: {line} ended"))?;
+    }
+    s.close()?;
+    s.wait_for("display: closed Terminal")?;
+    s.wait_for(&home_apps(0))?;
+    // Files is still open at Notes' folder: back to the person's own files.
+    s.tap_named("launcher: tile ", "Files")?;
+    s.find_named(&format!("{P}back"))?;
+    s.tap_named(P, "back")?;
+    s.find_named(&format!("{P}row harbour.png"))?;
+    s.tap_named(P, "row harbour.png")?;
+    s.wait_for("filer: showing data:/harbour.png 960x640")?;
+    std::thread::sleep(Duration::from_millis(600));
+    s.shot(&dir.join("9-picture.png"))?;
+    if !pinnacle_layout::notes::two_panes(w) {
+        s.tap_named(P, "close")?;
+    }
+    s.tap_named(P, "row readings.bin")?;
+    s.wait_for("filer: opened data:/readings.bin")?;
+    std::thread::sleep(Duration::from_millis(600));
+    s.shot(&dir.join("10-nothing-opens-it.png"))?;
     Ok(())
 }