2022-02-25 17:24:24 +00:00
|
|
|
#[cfg(all(
|
|
|
|
unix,
|
|
|
|
not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))
|
|
|
|
))]
|
|
|
|
pub fn set_clipboard(content: String) {
|
2022-02-26 21:51:41 +00:00
|
|
|
use std::{
|
|
|
|
io::Write,
|
|
|
|
process::{Command, Stdio},
|
|
|
|
};
|
2022-02-26 21:51:12 +00:00
|
|
|
|
|
|
|
let mut child = Command::new("xsel")
|
|
|
|
.arg("--input")
|
|
|
|
.arg("--clipboard")
|
|
|
|
.stdin(Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.expect("execute command xsel");
|
|
|
|
|
2022-02-26 21:51:41 +00:00
|
|
|
child
|
|
|
|
.stdin
|
|
|
|
.as_mut()
|
|
|
|
.unwrap()
|
|
|
|
.write_all(content.as_bytes())
|
|
|
|
.expect("execute command");
|
2022-02-26 21:51:12 +00:00
|
|
|
child.wait_with_output().unwrap();
|
2022-02-25 17:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(all(
|
|
|
|
unix,
|
|
|
|
not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))
|
|
|
|
)))]
|
|
|
|
use arboard::Clipboard;
|
|
|
|
|
|
|
|
#[cfg(not(all(
|
|
|
|
unix,
|
|
|
|
not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))
|
|
|
|
)))]
|
|
|
|
pub fn set_clipboard(content: String) {
|
|
|
|
let mut clipboard = Clipboard::new().unwrap();
|
|
|
|
clipboard.set_text(content).unwrap();
|
|
|
|
}
|