Crates.io | clippers |
lib.rs | clippers |
version | 0.1.2 |
source | src |
created_at | 2022-09-11 13:12:49.78343 |
updated_at | 2022-09-18 23:51:52.721613 |
description | Cross-platform clipboard management library |
homepage | |
repository | https://github.com/WilliamVenner/clippers |
max_upload_size | |
id | 663035 |
size | 137,059 |
Cross-platform clipboard management library powered by clip
.
Platform | Clear | Text (R) | Text (W) | Images (R) | Images (W) |
---|---|---|---|---|---|
Windows | ✅ | ✅ | ✅ | ✅ | ✅ |
macOS | ✅ | ✅ | ✅ | ✅ | ✅ |
Linux (X11) | ✅ | ✅ | ✅ | ✅ | ✅ |
Requires the libx11-dev
/libX11-devel
and libpng-dev
/libpng-devel
packages to be installed.
Not all OS clipboard APIs are thread-safe, so whilst the functions in this crate do their best to be thread-safe by synchronising using an internal mutex, using other clipboard libraries or calling OS clipboard APIs directly may cause undefined behaviour.
let mut clipboard = clippers::Clipboard::get();
match clipboard.read() {
Some(clippers::ClipperData::Text(text)) => {
println!("Clipboard text: {:?}", text);
}
Some(clippers::ClipperData::Image(image)) => {
println!("Clipboard image: {}x{} RGBA", image.width(), image.height());
}
Some(data) => {
println!("Clipboard data is unknown: {data:?}");
}
None => {
println!("Clipboard is empty");
}
}
let mut clipboard = clippers::Clipboard::get();
clipboard.write_text("Hello, world!").unwrap();
assert_eq!(clipboard.read().unwrap().into_text().unwrap(), "Hello, world!");
let mut clipboard = clippers::Clipboard::get();
let image = image::ImageBuffer::from_fn(8, 8, |x, y| {
if (x * y) % 2 == 0 {
image::Rgba([255, 0, 0, 255])
} else {
image::Rgba([0, 255, 0, 255])
}
});
clipboard.write_image(image.width(), image.height(), image.as_raw()).unwrap();
let clipboard_image = clipboard.read().unwrap();
assert_eq!(clipboard_image.into_image().unwrap().as_raw(), image.as_ref());