terminal emulator
git clone https://git.lucas.co/cce-terminal.git
src/clip.rs (987B)
1 //! PRIMARY-selection clipboard, via the same wl-copy/wl-paste convention as
2 //! the toolkit's regular clipboard (`cce_ui::widget::clipboard`): select →
3 //! primary, middle-click → paste primary. No X fallback — this DE is
4 //! Wayland-only and the toolkit's xclip arm is vestigial.
5
6 use std::io::Write;
7 use std::process::{Command, Stdio};
8
9 pub fn copy_primary(text: &str) {
10 let text = text.to_string();
11 std::thread::spawn(move || {
12 if let Ok(mut child) =
13 Command::new("wl-copy").arg("--primary").stdin(Stdio::piped()).spawn()
14 {
15 if let Some(mut stdin) = child.stdin.take() {
16 let _ = stdin.write_all(text.as_bytes());
17 }
18 let _ = child.wait();
19 }
20 });
21 }
22
23 pub fn paste_primary() -> Option<String> {
24 let output = Command::new("wl-paste").args(["--primary", "-n"]).output().ok()?;
25 if !output.status.success() {
26 return None;
27 }
28 String::from_utf8(output.stdout).ok()
29 }