Repository navigation
feat(tui): OSC 52 clipboard for SSH/headless terminals - #87
Merged
Merged
Conversation
`y`-copy used `arboard`, which only speaks X11/Wayland on Unix — over SSH with no display forwarding it waits out the X11 connection timeout, then fails with a cryptic error and nothing reaches a clipboard. - On non-macOS Unix with no `$DISPLAY`/`$WAYLAND_DISPLAY`, skip `arboard` (and its X11 timeout) and emit an OSC 52 escape (`ESC ]52;c;<base64>BEL`) so the *local* terminal writes the *local* clipboard over the SSH stream. macOS and Windows keep their native desktop backends first (DISPLAY-agnostic; Terminal.app's OSC 52 is unreliable), with OSC 52 as a fallback if the native call errors. - OSC 52 bytes are written on the event-loop thread, never from a spawned task: the headless path writes synchronously in `dispatch`, and the native-error path round-trips through a new internal `AppEvent::CopyViaTerminal` intercepted in the loop before `handle_event`. This serializes the escape with `terminal.draw` so the two never interleave on stdout. - The lean `--no-default-features` build now copies via OSC 52 too, instead of reporting "clipboard not built in". - Status stays honest: "copied: <v>" for the native path, "copied via terminal: <v>" for OSC 52. Platform-conditional logic is unit-tested cross-platform via a `cfg(any(feature, test))` gate (display detection, the skip decision, the OSC 52 encoding/write). Docs: README feature/keymap, CHANGELOG, ROADMAP (☑), and a TROUBLESHOOTING entry covering the tmux `set-clipboard on` caveat. `base64` moves dev → runtime dep.
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.
What
y-copy usedarboard, which on Unix only speaks X11/Wayland. Over SSH with no display forwarding it waits out the X11 connection timeout and then fails with a cryptic error — nothing reaches a clipboard. This adds an OSC 52 path so copy works over SSH and on headless terminals.Behavior by platform
$DISPLAY/$WAYLAND_DISPLAYarboard(native)arboard(native pasteboard; DISPLAY-agnostic)--no-default-features(noclipboard)OSC 52 (
ESC ]52;c;<base64>BEL) is written to the terminal stream, so the local terminal — not a remote X server — writes the local clipboard.Correctness: no stdout race
OSC 52 bytes are written only on the event-loop thread, never from a spawned task:
dispatch(loop thread);AppEvent::CopyViaTerminal, intercepted in the loop beforehandle_event.So the escape is serialized with
terminal.drawand the two can't interleave on stdout (crossterm flushes the frame;write_osc52flushes after). OSC 52 doesn't move the cursor or draw cells, so ratatui's next diff is unaffected.Notes
copied: <v>(native) vscopied via terminal: <v>(OSC 52).DISPLAY/WAYLAND_DISPLAY(an X11/Wayland concept), so SSH-into-a-Mac can't be distinguished — arboard succeeds to the remote Mac's pasteboard rather than falling back to OSC 52. Deliberate (Terminal.app's OSC 52 is unreliable; SSH-into-Mac-TUI is rare);SSH_CONNECTIONcould close it later if wanted.base64moves dev-dep → runtime dep (now used in non-test code).Verification
cfg(any(feature = "clipboard", test))gate: display detection, the skip decision, OSC 52 encoding, and the buffered write. 5 new tests, present in both feature modes.fmtclean;clippy --all-targetsclean on--all-featuresand--no-default-features; 1139 all-features / 1044 no-default tests pass, 0 failed.Docs
README (feature table + keymap), CHANGELOG (
Added), ROADMAP (item ☑), and adocs/TROUBLESHOOTING.mdentry covering the tmuxset -g set-clipboard oncaveat.