pub trait ClipboardProvider: Send + Sync {
fn read_text(&self) -> Option<String>;
fn write_text(&self, text: &str);
}
#[cfg(all(not(target_arch = "wasm32"), target_os = "macos"))]
pub struct SystemClipboard;
#[cfg(all(not(target_arch = "wasm32"), target_os = "macos"))]
impl ClipboardProvider for SystemClipboard {
fn read_text(&self) -> Option<String> {
use std::process::Command;
Command::new("pbpaste")
.output()
.ok()
.and_then(|o| String::from_utf8(o.stdout).ok())
}
fn write_text(&self, text: &str) {
use std::process::Command;
if let Ok(mut child) = Command::new("pbcopy")
.stdin(std::process::Stdio::piped())
.spawn()
{
if let Some(stdin) = child.stdin.as_mut() {
use std::io::Write;
let _ = stdin.write_all(text.as_bytes());
}
let _ = child.wait();
}
}
}