use cosh_tools::computer::types::{ComputerScreenshot, LegendEntryOutput, ScreenshotOutput};
fn main() {
let annotated = ComputerScreenshot {
app: Some("Reports".into()),
selector: Some("button".into()),
annotate: true,
..Default::default()
};
println!("annotated capture input: {annotated:?}");
let annotated_wire = r#"{"app": "Reports", "selector": "button", "annotate": true}"#;
let parsed: ComputerScreenshot =
serde_json::from_str(annotated_wire).expect("valid wire shape");
println!("wire {annotated_wire} → {parsed:?}");
let out = sample_output();
println!(
"delivered image: {}x{} ({} bytes)",
out.width, out.height, out.bytes
);
let image_coord = (410.0_f64, 252.0_f64);
let desktop = (
out.desktop_origin.0 as f64 + image_coord.0 * out.desktop_scale.0,
out.desktop_origin.1 as f64 + image_coord.1 * out.desktop_scale.1,
);
println!(
"image {image_coord:?} → desktop ({:.0}, {:.0})",
desktop.0, desktop.1
);
for entry in &out.legend {
println!(
"tag {} → {} ({} {})",
entry.tag,
entry.selector,
entry.role,
entry.name.as_deref().unwrap_or("")
);
}
}
fn sample_output() -> ScreenshotOutput {
ScreenshotOutput {
width: 800,
height: 600,
desktop_origin: (0, 0),
desktop_scale: (1.0, 1.0),
bytes: 42,
legend: vec![LegendEntryOutput {
tag: "B7".into(),
selector: "button[name='Export']:nth(7)".into(),
role: "button".into(),
name: Some("Export".into()),
color: [255, 0, 0],
}],
omitted: Vec::new(),
truncated: 0,
images: Vec::new(),
}
}