setClipboard static method

Cmd setClipboard(
  1. String text, {
  2. String selection = 'c',
})

Set the terminal clipboard via OSC 52.

Most terminals expect base64-encoded UTF-8.

This requires ANSI escape support and may be blocked by terminal security settings. It is safe to call even if unsupported.

Implementation

static Cmd setClipboard(String text, {String selection = 'c'}) {
  final sel = selection.isEmpty ? 'c' : selection[0];
  final payload = base64.encode(utf8.encode(text));
  return writeRaw('\x1b]52;$sel;$payload\x07');
}