Crates.io | terminal-clipboard |
lib.rs | terminal-clipboard |
version | 0.4.1 |
source | src |
created_at | 2020-09-08 13:42:31.923193 |
updated_at | 2023-10-31 09:33:26.916261 |
description | a minimal cross-platform clipboard |
homepage | |
repository | https://github.com/Canop/terminal-clipboard |
max_upload_size | |
id | 286142 |
size | 26,729 |
terminal-clipboard is a cross-platform clipboard library focused on strings copying and pasting for terminal applications:
terminal_clipboard::set_string("test").unwrap();
assert_eq!("test", terminal_clipboard::get_string().unwrap());
The implementation is currently chosen from the "target_os" part of the compilation target.
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.
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);
}
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.