use cosh_tools::computer::mouse::{DEFAULT_DRAG_MS, MIN_DRAG_MS, validate};
use cosh_tools::computer::types::{ComputerControl, PointerAction, PointerAnchor};
fn main() {
const TOOL: &str = "computer_control";
let click_ok = ComputerControl {
app: Some("Reports".into()),
selector: Some("button[name='OK']".into()),
..Default::default()
};
assert!(validate(&click_ok, TOOL).is_ok());
println!("element click: valid");
let click_overflow = ComputerControl {
app: Some("Files".into()),
selector: Some("list_item[name='report.csv']".into()),
anchor: Some(PointerAnchor::TopRight), ..Default::default()
};
assert!(validate(&click_overflow, TOOL).is_ok());
let drag_card = ComputerControl {
app: Some("Board".into()),
selector: Some("list_item[name='todo']".into()),
action: Some(PointerAction::Drag),
to_selector: Some("list_item[name='done']".into()),
duration_ms: Some(DEFAULT_DRAG_MS), ..Default::default()
};
assert!(validate(&drag_card, TOOL).is_ok());
println!(
"element→element drag: valid (duration {} ms, min {})",
DEFAULT_DRAG_MS, MIN_DRAG_MS
);
let cases: Vec<(&str, ComputerControl)> = vec![
(
"drag without an end point",
ComputerControl {
action: Some(PointerAction::Drag),
x: Some(100),
y: Some(100),
..Default::default()
},
),
(
"scroll without dx/dy",
ComputerControl {
action: Some(PointerAction::Scroll),
x: Some(100),
y: Some(100),
..Default::default()
},
),
(
"selector without app/pid/surface",
ComputerControl {
selector: Some("button[name='OK']".into()),
..Default::default()
},
),
];
for (label, step) in cases {
if let Err(e) = validate(&step, TOOL) {
println!("{label} rejected: {e}");
}
}
let _press = ComputerControl {
action: Some(PointerAction::Down),
x: Some(100),
y: Some(100),
..Default::default()
};
let _release = ComputerControl {
action: Some(PointerAction::Up),
..Default::default()
};
}