setClipboardBestEffort static method
Set clipboard using external helpers when possible, with OSC 52 fallback.
Preferred external tools by platform:
- Linux:
wl-copy, thenxclip, thenxsel - macOS:
pbcopy - Windows:
clip
If an external helper is unavailable or fails, falls back to setClipboard (OSC 52) to preserve compatibility with terminals that support it.
Implementation
static Cmd setClipboardBestEffort(String text, {String selection = 'c'}) {
return Cmd(() async {
final copied = await _trySetClipboardExternal(text);
if (copied) {
return ClipboardSetMsg(
method: ClipboardSetMethod.external,
textLength: text.length,
);
}
return await Cmd.sequence([
setClipboard(text, selection: selection),
Cmd.message(
ClipboardSetMsg(
method: ClipboardSetMethod.osc52,
textLength: text.length,
),
),
]).execute();
});
}