virtuoso_cli/client/
window_ops.rs1use crate::client::bridge::escape_skill_string;
2
3pub struct WindowOps;
4
5impl WindowOps {
6 pub fn list_windows(&self) -> String {
9 r#"let((out sep) out = "[" sep = "" foreach(w hiGetWindowList() out = strcat(out sep sprintf(nil "{\"name\":\"%s\"}" hiGetWindowName(w))) sep = ",") strcat(out "]"))"#.into()
10 }
11
12 pub fn dismiss_dialog(&self, action: &str) -> String {
15 if action == "ok" {
16 r#"let((d) d = hiGetCurrentDialog() if(d hiSendOK(d) "no-dialog"))"#.into()
17 } else {
18 r#"let((d) d = hiGetCurrentDialog() if(d hiCancelDialog(d) "no-dialog"))"#.into()
19 }
20 }
21
22 pub fn get_dialog_info(&self) -> String {
25 r#"let((d) d = hiGetCurrentDialog() if(d hiGetWindowName(d) "no-dialog"))"#.into()
26 }
27
28 pub fn screenshot(&self, path: &str) -> String {
34 let path = escape_skill_string(path);
35 Self::skill_capture(&path)
36 }
37
38 pub fn screenshot_by_pattern(&self, path: &str, pattern: &str) -> String {
42 let path = escape_skill_string(path);
43 let pattern = escape_skill_string(pattern);
44 let capture = Self::skill_capture(&path);
45 format!(
46 r#"let((matched) matched = nil foreach(w hiGetWindowList() when(rexMatchp("{pattern}" hiGetWindowName(w)) matched = t)) if(matched {capture} "no-match"))"#
47 )
48 }
49
50 fn skill_capture(escaped_path: &str) -> String {
52 format!(
53 r#"let((cmd) cmd = sprintf(nil "import -window root -display %s {escaped_path}" getShellEnvVar("DISPLAY")) system(cmd) if(isFile("{escaped_path}") "{escaped_path}" nil))"#
54 )
55 }
56}