feat(tui/clipboard): multi-backend copy with OSC 52 fallback (#65)#188
Open
quangdang46 wants to merge 1 commit into
Open
feat(tui/clipboard): multi-backend copy with OSC 52 fallback (#65)#188quangdang46 wants to merge 1 commit into
quangdang46 wants to merge 1 commit into
Conversation
The previous copy_to_clipboard tried wl-copy first, then arboard,
and dropped silently on every other path. SSH sessions, machines
without wl-copy/arboard, and X11 systems with xclip/xsel were all
broken.
Replace with a layered resolver:
1. If SSH_CONNECTION or SSH_TTY is set, skip native helpers and emit
OSC 52 directly so the clipboard ends up on the user's local
machine instead of the remote host.
2. Otherwise try platform-native helpers in order:
- macOS: pbcopy
- Linux Wayland: wl-copy --type text/plain;charset=utf-8 (only if
WAYLAND_DISPLAY is set)
- Linux X11: xclip then xsel (only if DISPLAY is set)
- Windows: arboard
3. Final fallback: emit OSC 52 (BEL-terminated, base64-encoded) which
modern terminals (kitty, alacritty, foot, wezterm, iTerm2,
Ghostty, recent xterm) honor.
Helpers like native_clipboard_commands_for_env / write_osc52_clipboard_to /
should_prefer_osc52_for_env are pub(super) so the test module can
exercise them deterministically without touching real env / stdout.
Tests added in src/tui/app/helpers_tests.rs:
- native_clipboard_commands_prefer_wayland_before_x11
- native_clipboard_commands_are_empty_without_display_env
- osc52_clipboard_writer_emits_base64_bel_sequence
(asserts \x1b]52;c;<base64>\x07)
- ssh_sessions_prefer_osc52_clipboard
Ports upstream PR 1jehuang#68.
Closes #65
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
copy_to_clipboardpreviously tried onlywl-copythenarboard, dropping silently on every other path. SSH sessions, machines without those tools, and X11 systems withxclip/xselwere all broken.This addresses issue #65: #65
Changes
src/tui/app/helpers.rs — replace with a layered resolver:
SSH_CONNECTIONorSSH_TTYis set, skip native helpers and write OSC 52 directly so the clipboard lands on the user's local machine.pbcopywl-copy --type text/plain;charset=utf-8(only ifWAYLAND_DISPLAYis set)xclip -selection clipboard -inthenxsel --clipboard --input(only ifDISPLAYis set)arboardThe pure helpers (
native_clipboard_commands_for_env,write_osc52_clipboard_to,should_prefer_osc52_for_env) arepub(super)so the test module can exercise them without touching real env / stdout.src/tui/app/helpers_tests.rs — 4 new tests:
native_clipboard_commands_prefer_wayland_before_x11native_clipboard_commands_are_empty_without_display_envosc52_clipboard_writer_emits_base64_bel_sequence— pins the exact\x1b]52;c;<base64>\x07byte sequence.ssh_sessions_prefer_osc52_clipboardTests
All 4 new tests pass; all pre-existing helpers tests still pass.
Notes
Ports upstream PR 1jehuang#68.