BREP_stream_client 0.1.0

Embed the next.BREP.io CAD application in a Rust program: launch `brep-app --stream` headless (or connect to one), receive its whole window as RGBA frames and drive it with pointer, keyboard and touch input. No browser and no GUI toolkit required.
Documentation
//! Launch the CAD application headless from Rust, wait for its first picture,
//! click its File menu, and save what it shows as a PNG. No window, no browser.
//!
//!     cargo run --example snapshot -- [path/to/brep-app]
use brep_stream_client::{Input, Launcher, Mods, PointerButton};
use std::time::{Duration, Instant};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let program = std::env::args().nth(1).unwrap_or_else(|| "brep-app".into());
    let started = Instant::now();
    // 1280 x 800 logical pixels at density 1. The app ends with the session.
    let session = Launcher::new(&program).size(1280.0, 800.0, 1.0).launch()?;
    session.wait_still(Duration::from_millis(1500), Duration::from_secs(120))?;
    let (width, height) = {
        let frame = session.frame();
        (frame.width, frame.height)
    };
    println!("ready in {:.1} s: {width} x {height} pixels", started.elapsed().as_secs_f32());

    // The File menu sits at (148, 19) in the default layout.
    let (x, y) = (148.0, 19.0);
    let clicked = Instant::now();
    session.send(Input::PointerMove { x, y });
    session.send(Input::Button { x, y, button: PointerButton::Primary, down: true, mods: Mods::NONE });
    session.send(Input::Button { x, y, button: PointerButton::Primary, down: false, mods: Mods::NONE });
    session.wait_frame(Duration::from_secs(10))?;
    println!("the click came back as a new frame in {} ms", clicked.elapsed().as_millis());
    session.wait_still(Duration::from_millis(500), Duration::from_secs(30))?;

    {
        let frame = session.frame();
        image::save_buffer("brep-cad.png", &frame.rgba, frame.width, frame.height, image::ColorType::Rgba8)?;
        println!("saved brep-cad.png after {} frames", frame.frames);
    }
    let status = session.shutdown(Duration::from_secs(15))?;
    println!("the app exited: {status}");
    Ok(())
}