1pub fn copy_plain_text_to_clipboard(text: &str) -> Result<(), String> {
18 let payload = text.as_bytes();
19 if std::env::var("WAYLAND_DISPLAY").is_ok()
20 && let Ok(mut child) = std::process::Command::new("wl-copy")
21 .stdin(std::process::Stdio::piped())
22 .stdout(std::process::Stdio::null())
23 .stderr(std::process::Stdio::null())
24 .spawn()
25 {
26 if let Some(mut sin) = child.stdin.take() {
27 let _ = std::io::Write::write_all(&mut sin, payload);
28 }
29 let _ = child.wait();
30 return Ok(());
31 }
32
33 if let Ok(mut child) = std::process::Command::new("xclip")
34 .args(["-selection", "clipboard"])
35 .stdin(std::process::Stdio::piped())
36 .stdout(std::process::Stdio::null())
37 .stderr(std::process::Stdio::null())
38 .spawn()
39 {
40 if let Some(mut sin) = child.stdin.take() {
41 let _ = std::io::Write::write_all(&mut sin, payload);
42 }
43 let _ = child.wait();
44 return Ok(());
45 }
46
47 if std::env::var("WAYLAND_DISPLAY").is_ok() {
48 Err("Clipboard tool not found. Install 'wl-clipboard' (wl-copy) or 'xclip'.".to_string())
49 } else {
50 Err("Clipboard tool not found. Install 'xclip' or 'wl-clipboard' (wl-copy).".to_string())
51 }
52}