Crate cli_clipboard

source ·
Expand description

CLI Clipboard

cli-clipboard is a fork of rust-clipboard that adds wayland support for terminal and window-less applications via wl-clipboard-rs. For terminal applications it supports copy and paste for both wayland and X11 linux environments, macOS and windows.

Also adds convenience functions for get_contents and set_contents.

On Linux it will first attempt to setup a Wayland clipboard provider. If that fails it will then fallback to the X11 clipboard provider.

Examples

Using ClipboardContext to create a clipboard provider:

use cli_clipboard::{ClipboardContext, ClipboardProvider};

let mut ctx = ClipboardContext::new().unwrap();
let the_string = "Hello, world!";
ctx.set_contents(the_string.to_owned()).unwrap();
assert_eq!(ctx.get_contents().unwrap(), the_string);
ctx.clear();
// clearing the clipboard causes get_contents to return Err on macos and windows
if cfg!(any(windows, target_os = "macos")) {
   if ctx.get_contents().is_ok() {
       panic!("Should be Err");
   }
} else {
   assert_eq!(ctx.get_contents().unwrap(), "");
}

Using the helper functions:

use cli_clipboard;

let the_string = "Hello, world!";
cli_clipboard::set_contents(the_string.to_owned()).unwrap();
assert_eq!(cli_clipboard::get_contents().unwrap(), the_string);

Modules

Traits

Trait for clipboard access

Functions

Get the current clipboard contents
Write a string to the clipboard

Type Definitions