#clipboard #ext #x11 #exit #content #extension #copypasta

copypasta-ext

A clipboard library providing useful extensions for copypasta

10 releases

0.4.4 Feb 23, 2023
0.4.3 Feb 20, 2023
0.4.1 Jan 19, 2023
0.3.9 Jun 18, 2022
0.3.0 May 28, 2020

#114 in Unix APIs

Download history 2715/week @ 2024-07-19 2828/week @ 2024-07-26 2234/week @ 2024-08-02 2072/week @ 2024-08-09 1646/week @ 2024-08-16 1527/week @ 2024-08-23 2505/week @ 2024-08-30 2650/week @ 2024-09-06 2934/week @ 2024-09-13 2620/week @ 2024-09-20 2294/week @ 2024-09-27 2359/week @ 2024-10-04 2910/week @ 2024-10-11 3249/week @ 2024-10-18 2250/week @ 2024-10-25 1777/week @ 2024-11-01

10,528 downloads per month
Used in 25 crates (20 directly)

MIT/Apache

52KB
723 lines

Build status on GitLab CI Newest release on crates.io Documentation Number of downloads on crates.io Project license

copypasta-ext

A clipboard library providing useful extensions for the copypasta library.

I had a growing annoyance with copypasta, because the clipboard is cleared on the Linux/X11 platform when your application exits as per X11 design. The crate maintainer didn't want to implement workarounds (for valid reasons). This copypasta-ext crate provides additional clipboard contexts that solve this, along with a few other additions.

Here are some of these additions:

To guess at runtime what clipboard provider is best used see the DisplayServer class. Enable all desired compiler feature flags for clipboard systems to support, and use DisplayServer::select().try_context() to obtain a clipboard context.

This crate should work with the latest copypasta. Feel free to open an issue or pull request otherwise. The copypasta crate is exposed as copypasta_ext::copypasta.

Example

Get and set clipboard contents. Keeps contents in X11 clipboard after exit by forking the process. Falls back to standard clipboard provider on non X11 platforms. See x11_fork module for details.

use copypasta_ext::prelude::*;
use copypasta_ext::x11_fork::ClipboardContext;

fn main() {
    let mut ctx = ClipboardContext::new().unwrap();
    println!("{:?}", ctx.get_contents());
    ctx.set_contents("some string".into()).unwrap();
}

Get and set clipboard contents. Keeps contents in X11 clipboard after exit by invoking xclip/xsel. Falls back to standard clipboard provider on non X11 platforms. See x11_bin module for details.

use copypasta_ext::prelude::*;
use copypasta_ext::x11_bin::ClipboardContext;

fn main() {
    let mut ctx = ClipboardContext::new().unwrap();
    println!("{:?}", ctx.get_contents());
    ctx.set_contents("some string".into()).unwrap();
}

Requirements

  • Rust 1.60 or above (MSRV)
  • Same requirements as copypasta
  • Requirements noted in specific clipboard context modules

Special thanks

  • to the maintainers/contributors of rust-clipboard and copypasta
  • to everyone involved in all crate dependencies used

License

This project is dual-licensed under the MIT and Apache2 license.

Dependencies

~0–9.5MB
~107K SLoC