Clipboard
Category: Core
Source: clipboard.dart
Writes text to the system clipboard across platforms.
Tries a platform-specific list of commands in order (on Linux there are several clipboard tools; try each). Stdin is the only input path — no shell interpretation, so arbitrary binary-safe text works.
The runner is injectable; tests supply a fake to avoid spawning a real pbcopy / clip / wl-copy.
Classes
ClipboardProcess
Constructor
const ClipboardProcess({required this.stdin, required this.exitCode})Properties
| Property | Type | Description |
|---|---|---|
stdin | IOSink | |
exitCode | Future<int> |
Functions
String? encodeOsc52(String text, {Map<String, String>? env})
Encode [text] as an OSC52 set-clipboard escape sequence. When inside tmux (detected by the TMUX env var), wrap the sequence in tmux's passthrough DCS so it reaches the outer terminal. Returns null if the payload exceeds [osc52MaxBytes] — caller falls back.
`Future<bool> copyToClipboard(
String text, { ClipboardRunner? runner, Osc52Writer? osc52Writer, Map<String, String>? environmentOverride, })`
Copies [text] to the system clipboard.
Strategy:
- If running under tmux or SSH, try OSC52 first (host commands usually can't see the user's real clipboard from there) and fall back to host commands only if OSC52 is unavailable.
- Otherwise try host commands first (pbcopy/clip/wl-copy/xclip/xsel), then OSC52 as last resort.
Never throws — process-launch failures (ProcessException) and non-zero exits fall through to the next candidate. Returns false only if every candidate failed.
Constants
| Name | Type | Description |
|---|---|---|
osc52MaxBytes | int | Maximum OSC52 payload size before we refuse to emit. The DCS framing most terminals use to receive OSC52 has a length limit (~100KB is the upper bound; 74KB stays well under it after base64 expansion). |