clipboard
stableSystem clipboard plugin providing a Clipboard class to read and write text and images, check clipboard contents, and clear the clipboard across Windows, macOS, and Linux.
use plugin clipboard::{Clipboard.new, get_text, set_text, …} Functions (8)
- Clipboard.new Open a handle to the system clipboard
- get_text Read the current clipboard text
- set_text Write a string to the clipboard
- get_image Read the current clipboard image as RGBA pixels
- set_image Write an RGBA image to the clipboard
- has_text Check whether the clipboard holds non-empty text
- has_image Check whether the clipboard holds an image
- clear Clear all clipboard contents
Open a handle to the system clipboard
Opens a connection to the system clipboard and returns a Clipboard handle. Errors if the clipboard cannot be accessed (for example, on a headless Linux session without a display server).
use plugin clipboard::{Clipboard}
let cb = Clipboard.new()
cb.set_text("hello from Zolo")
print(cb.get_text())
Read the current clipboard text
Returns the text currently stored on the clipboard. Errors if the clipboard is empty or holds non-text content.
use plugin clipboard::{Clipboard}
let cb = Clipboard.new()
if cb.has_text() {
let text = cb.get_text()
print("clipboard says: {text}")
}
Write a string to the clipboard
Replaces the clipboard contents with the given string.
use plugin clipboard::{Clipboard}
let cb = Clipboard.new()
cb.set_text("copied at runtime")
print(cb.get_text()) // "copied at runtime"
Read the current clipboard image as RGBA pixels
Returns the image currently stored on the clipboard as a table with width and height integers and bytes containing the raw RGBA pixel data (width * height * 4 bytes). Errors if the clipboard does not hold an image.
use plugin clipboard::{Clipboard}
let cb = Clipboard.new()
if cb.has_image() {
let img = cb.get_image()
print("image is {img["width"]}x{img["height"]}")
}
Write an RGBA image to the clipboard
Places an image on the clipboard. bytes must be raw RGBA pixel data with exactly width * height * 4 bytes.
use plugin clipboard::{Clipboard}
let cb = Clipboard.new()
// a 1x1 opaque red pixel (RGBA)
cb.set_image(1, 1, [255, 0, 0, 255])
print(cb.has_image()) // true
Check whether the clipboard holds non-empty text
Returns true if the clipboard currently holds non-empty text, false otherwise. Never errors, making it a safe guard before calling get_text.
use plugin clipboard::{Clipboard}
let cb = Clipboard.new()
if cb.has_text() {
print(cb.get_text())
} else {
print("clipboard has no text")
}
Check whether the clipboard holds an image
Returns true if the clipboard currently holds an image, false otherwise. Never errors, making it a safe guard before calling get_image.
use plugin clipboard::{Clipboard}
let cb = Clipboard.new()
print(cb.has_image())
Clear all clipboard contents
Removes all contents from the clipboard.
use plugin clipboard::{Clipboard}
let cb = Clipboard.new()
cb.set_text("temporary secret")
cb.clear()
print(cb.has_text()) // false