Add OSC 52 clipboard support - #53
Open
kynrek wants to merge 1 commit into
Open
Conversation
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
commented
Jul 31, 2026
kynrek
left a comment
Author
There was a problem hiding this comment.
This was necessary to be able to copy while using tmux sessions and I though others would benefit from it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Handle the OSC 52 escape sequence (
ESC ] 52 ; Pc ; Pd ST) so remote applications can set the local clipboard — for exampletmuxwithset-clipboard oncopying over SSH.Details
Vt102Emulationdecodes the base64 payload and writes it to the system clipboard viaQApplication::clipboard().Pd == '?') are intentionally ignored so a remote host cannot exfiltrate local clipboard contents.MAX_TOKEN_LENGTHis raised from 256 to 100000 so large clipboard payloads are not truncated (matches xterm's default OSC 52 limit).clipboardWriteAllowedproperty onTerminalDisplay, 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 onin 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.