Skip to content

Add OSC 52 clipboard support - #53

Open
kynrek wants to merge 1 commit into
Swordfish90:masterfrom
kynrek:osc52-pr
Open

Add OSC 52 clipboard support#53
kynrek wants to merge 1 commit into
Swordfish90:masterfrom
kynrek:osc52-pr

Conversation

@kynrek

@kynrek kynrek commented Jul 31, 2026

Copy link
Copy Markdown

Summary

Handle the OSC 52 escape sequence (ESC ] 52 ; Pc ; Pd ST) so remote applications can set the local clipboard — for example tmux with set-clipboard on copying over SSH.

Details

  • Vt102Emulation decodes the base64 payload and writes it to the system clipboard via QApplication::clipboard().
  • Clipboard read requests (Pd == '?') are intentionally ignored so a remote host cannot exfiltrate local clipboard contents.
  • MAX_TOKEN_LENGTH is raised from 256 to 100000 so large clipboard payloads are not truncated (matches xterm's default OSC 52 limit).
  • The feature is gated behind a static flag (default on), exposed as the clipboardWriteAllowed property on TerminalDisplay, so an embedding application can offer an on/off setting. When disabled, OSC 52 sequences are ignored and behaviour is unchanged.

Testing

Built on macOS (Qt 6) and verified end-to-end: with set -g set-clipboard on in tmux over SSH, selecting text in copy-mode now populates the local macOS clipboard. Toggling the flag off restores the previous behaviour.

A companion PR to cool-retro-term adds a UI checkbox that binds to clipboardWriteAllowed.

Handle the OSC 52 escape sequence (ESC ] 52 ; Pc ; Pd ST) so that remote
applications can set the local clipboard — e.g. tmux with 'set-clipboard on'
copying over SSH.

Vt102Emulation decodes the base64 payload and writes it to the system
clipboard via QApplication::clipboard(). Clipboard read requests (Pd == '?')
are intentionally ignored so a remote host cannot exfiltrate clipboard
contents. MAX_TOKEN_LENGTH is raised from 256 to 100000 so large payloads
are not truncated.

The feature is gated behind a static flag (default on) exposed as the
'clipboardWriteAllowed' property on TerminalDisplay, allowing the embedding
application to expose an on/off setting. When disabled, OSC 52 sequences are
ignored and the terminal keeps its previous behaviour.

@kynrek kynrek left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was necessary to be able to copy while using tmux sessions and I though others would benefit from it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant