Skip to main content

Module clipboard

Module clipboard 

Source
Expand description

The clipboard’s pure parts (ADR 0015): formats, items, slots, the boundaries content crosses, and the negotiation between what a copy offers and what a paste target accepts. No egui: the contract, its default owner and the commands are egui_pop_api::clipboard’s.

Experimental: may change in any release (docs/stability.md).
  • A format (FormatId) is a MIME-like id: an application’s private types are application/x-<app>.<type>+json (egui-pop’s own application/x-egui-pop.<type>+json), the standard ones text/plain, text/html, image/png, text/uri-list.
  • An item (ClipItem) is what one copy made: its private type, its version, a structured payload, a title (“3 nodes”), readable fallbacks for the system clipboard, where it came from and what sanitisers left out.
  • A target declares the formats it accepts, richest first; negotiate takes the first the item offers, or one a declared transform makes from what it offers (one transform, never a chain). Nothing fits: a Refusal saying why (ADR 0003).
use egui_pop_model::clipboard::{self, ClipItem, FormatId, TransformSpec, TEXT};

const COLOR: FormatId = FormatId::from_static("application/x-demo.color+json");
const GRAY: FormatId = FormatId::from_static("application/x-demo.gray+json");

let item = ClipItem::new(COLOR, 1, serde_json::json!({ "hex": "#d9a441" }), "a colour")
    .fallback(TEXT, serde_json::json!("#d9a441"));
assert_eq!(item.offers(), [COLOR, TEXT]);

let to_gray = TransformSpec::new("demo.color-to-gray", COLOR, GRAY).lossy();
// A target taking colours takes the item as it is.
let plan = clipboard::negotiate(&item.offers(), &[COLOR, TEXT], &[to_gray.clone()]).unwrap();
assert_eq!((plan.format, plan.transform), (COLOR, None));
// A target taking greys only gets it through the transform.
let plan = clipboard::negotiate(&item.offers(), &[GRAY], &[to_gray]).unwrap();
assert_eq!(plan.transform.as_deref(), Some("demo.color-to-gray"));
assert!(plan.lossy);
// A target taking images refuses it, saying why.
assert!(clipboard::negotiate(&item.offers(), &[clipboard::PNG], &[]).is_err());

Structs§

ClipItem
What one copy made: a typed item with its readable fallbacks.
ClipOrigin
Where an item came from.
FormatId
A format: a MIME-like type, type/subtype with optional parameters.
Plan
How a paste goes: the representation taken from the offer, what the target receives, and the transform between them, if any.
Refusal
Why nothing on the clipboard fits a target.
Repr
One representation of an item: a format and its data (a JSON string for a text format).
Stripped
What a sanitiser removed, and why.
TitleKey
A title as a catalogue message: its key and its arguments.
TransformSpec
A transform a plugin declares: it makes to from from.

Enums§

Boundary
The boundary a representation crosses, which sanitisers run on.
Slot
Where an item is kept in the owner: the user’s slot, or a session’s own (an agent’s, a script’s), so that an agent neither reads nor overwrites what the user copied unless the owner allows it.

Constants§

HTML
HTML, with a text alternative.
PNG
An image.
TEXT
Plain text: every item renders one, and external text arrives as it.
URI_LIST
A list of files or links.

Functions§

candidates
Every way an offer fits a target, the best first: per accepted format (richest first), the offer’s own representation, or else each transform making it from what is offered (from the richest offered).
choose
negotiate, held to the format the target should receive (format) and the transform to use (transform), when given: what paste special and an agent’s paste ask for.
html_to_text
HTML reduced to its text: tags removed (with the content of script and style), block ends as line breaks, the common entities decoded.
marker
The marker of a text written to the system clipboard: 64-bit FNV-1a. A paste whose text has the marker of the owner’s last write is the owner’s own item, not external content.
negotiate
The plan of a paste: the first accepted format the offer has, or one a transform makes from it; nothing: why not.
strip_controls
Text without control characters: escape sequences (ESC [ … final, ESC ] … BEL) and every C0 and C1 control but tab, line feed and carriage return. The text and how many characters went.