8 releases

0.4.1 Oct 31, 2023
0.4.0 Mar 23, 2023
0.3.1 Nov 6, 2021
0.3.0 Oct 26, 2021
0.1.1 Sep 8, 2020

#251 in Text processing

Download history 232/week @ 2024-07-21 276/week @ 2024-07-28 360/week @ 2024-08-04 352/week @ 2024-08-11 434/week @ 2024-08-18 374/week @ 2024-08-25 443/week @ 2024-09-01 407/week @ 2024-09-08 289/week @ 2024-09-15 295/week @ 2024-09-22 263/week @ 2024-09-29 224/week @ 2024-10-06 256/week @ 2024-10-13 278/week @ 2024-10-20 226/week @ 2024-10-27 220/week @ 2024-11-03

1,002 downloads per month
Used in 11 crates (9 directly)

MIT license

17KB
311 lines

terminal-clipboard

CI MIT Latest Version Chat on Miaou

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 libxcb to compile.

On Debian and Ubuntu you can install them with

sudo apt install libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev -y

Fedora, Centos, Red Hat

sudo dnf install libxcb -y

openSUSE

sudo zypper --non-interactive install xorg-x11-util-devel libxcb-composite0 libxcb-render0 libxcb-shape0 libxcb-xfixes0

Arch Linux

sudo pacman -Syu --noconfirm libxcb

Alpine is not supported. For alpine you have to use musl instead of gnu and have to provide alternative behaviour.

#[cfg(not(target_env = "musl"))]
{
  terminal_clipboard::set_string(answer_text).unwrap();
  assert_eq!(*answer_text, terminal_clipboard::get_string().unwrap());
  println!("Text '{answer_text}' was copied to your clipboard")
}
#[cfg(target_env = "musl")]
{
  println!("{}", answer_text);
}

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.

Dependencies

~0–2.4MB
~48K SLoC