1 unstable release

0.1.2 Sep 18, 2022
0.1.1 Sep 11, 2022
0.1.0 Sep 11, 2022

#1099 in Text processing

Download history 7/week @ 2024-06-09 13/week @ 2024-06-16 23/week @ 2024-06-23 22/week @ 2024-06-30 9/week @ 2024-07-07 12/week @ 2024-07-14 25/week @ 2024-07-21 101/week @ 2024-07-28 29/week @ 2024-08-04 68/week @ 2024-08-11 38/week @ 2024-08-18 18/week @ 2024-08-25 29/week @ 2024-09-01 25/week @ 2024-09-08 25/week @ 2024-09-15 69/week @ 2024-09-22

151 downloads per month

MIT license

105KB
3K SLoC

C++ 2K SLoC // 0.1% comments Rust 524 SLoC Objective-C++ 267 SLoC // 0.1% comments

crates.io docs.rs license Workflow Status

Cross-platform clipboard management library powered by clip.

Features

  • Read and write UTF-8 text to/from the clipboard
  • Read and write RGBA images to/from the clipboard
  • Clipboard clearing

Platform support

Platform Clear Text (R) Text (W) Images (R) Images (W)
Windows
macOS
Linux (X11)

Linux

Requires the libx11-dev/libX11-devel and libpng-dev/libpng-devel packages to be installed.

Thread Safety

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.

Examples

Reading data

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");
    }
}

Writing text

let mut clipboard = clippers::Clipboard::get();
clipboard.write_text("Hello, world!").unwrap();
assert_eq!(clipboard.read().unwrap().into_text().unwrap(), "Hello, world!");

Writing an image

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());

Dependencies

~1.9–7.5MB
~60K SLoC