Crate terminal_clipboard

Source
Expand description

terminal-clipboard is a cross-platform clipboard library focused on strings copying and pasting for terminal applications:

  • it’s tested on linux, windows and Android (Termux)
  • it doesn’t handle other types of objects than strings
  • it doesn’t handle non UTF8 strings

§Usage

terminal_clipboard::set_string("test").unwrap();
assert_eq!("test", terminal_clipboard::get_string().unwrap());

§Supported platforms

The implementation is currently chosen from the “target_os” part of the compilation target.

§Android (Termux)

The current implementation will defer to Termux API facilities to access the Android clipboard, and won’t work if the Termux API isn’t available at runtime.

If you know of solutions to access the Android clipboard without Termux, please open an issue.

§Linux

If a unix-like target is detected and the “termux” feature isn’t enabled, terminal-clipboard uses the x11-clipboard crate.

You’ll need to have xorg-dev and libxcb-composite0-dev to compile.

On Debian and Ubuntu you can install them with

sudo apt install xorg-dev libxcb-composite0-dev

§Windows

If the compilation target is “windows”, terminal-clipboard uses the clipboard-win crate. If you’re only interested in this platform, you should use this crate directly.

use terminal_clipboard;
terminal_clipboard::set_string("test").unwrap();
assert_eq!("test", terminal_clipboard::get_string().unwrap());

Structs§

ClipboardError
LocalClipboard
A clipboard with no access to outside the application.
X11Clipboard

Traits§

Clipboard

Functions§

get_string
Return the content of the clipboard
get_type
Return the type of the Clipboard, for example “X11”, “Windows”, “Local”, or “Termux”
new_clipboard
Build a new clipboard.
set_string
Fill the clipboard with the given string