Repository navigation
Conversation
9ae7907 to
91376b7
Compare
|
I opened MBanucu/opencode#1 against this branch. It shows the helper error instead of “Copied to clipboard” when the write fails and OSC 52 support is unconfirmed. I tested it in Apple Terminal with |
Preserve helper diagnostics when no other clipboard route can report success. Related to anomalyco#59664.
|
Thanks — I merged MBanucu#1 into this branch via rebase as Re-verified on Linux after the merge:
The PR description now covers the follow-up commit. |
|
Thanks for merging my follow-up. Could a maintainer weigh in on scope? Should this PR keep the Linux copy and paste fallbacks together, or would it make sense to restore v1’s text-copy fallback first and then review the paste fallback separately? |
|
Happy to split this if that is what maintainers prefer — here is the breakdown so the scope call is easier. v1's helper was text-copy only on the write side ( In this PR the two halves are already separable after
So "text copy first" would be a small, low-risk PR, but it would not close #66351 — that issue is entirely in the read/image path. My preference is to keep them together because the policy is one decision ("when the native backend reports Either way this stays draft until a maintainer signs off on the approach. |
Issue for this PR
Refs #66351
Type of change
What does this PR do?
On Linux, OpenTUI reads and writes the host clipboard through Wayland or X11
natively. When neither backend is usable it reports
unsupported, and the TUIshows
Clipboard read is not supported on this system. On Nix this happens onGNOME/Mutter: there is no Wayland data-control protocol, and OpenTUI's X11
fallback cannot
dlopenlibxcb.so.1because the wrapper does not expose it(#66351). The same
unsupportedstatus reaches users on hosts where the X11clipboard library is missing, even though
wl-paste/xclipcan still reach thedesktop clipboard.
This adds a last-resort backend to the TUI clipboard adapter. It only runs on
Linux and only after the native read reports
unsupported, or after a hostwrite reports
unsupported/failed:wl-pastewhenWAYLAND_DISPLAYis set andxclipwhenDISPLAYis set, in the caller's MIME preference order, with a 1.5 s timeout and an
8 MiB cap;
wl-copyandxclip, serialised so a burst of copies keeps itsorder;
of claiming success when OSC 52 support is unconfirmed (TUI: "Copied to clipboard" toast shown even when nothing was copied (OSC52 "attempted" treated as success) #59664);
behaviour, so nothing changes on systems where the native backend works.
The fallback is injected through
createClipboardAdapterand only enabled bycreateTuiClipboard, so other OpenTUI consumers and the existing adapter testskeep the native-only behaviour. It does not change OpenTUI itself, whose
documentation intentionally says it does not invoke
wl-copy,wl-paste,xclip, orxsel.The second commit (
cc15c65, authored by @SeifHediya inMBanucu#1) covers the failure case:
ClipboardTools.writereturnsfalsewhen no helper is installed and rejects with the helper's stderr whenone runs but fails. The adapter only swallows that failure when the terminal
reported OSC 52 support, so an unconfirmed OSC 52 attempt no longer hides a
broken
wl-copy.A packaging fix for the Nix case is proposed separately in
#67304 and
NixOS/nixpkgs#595482. This PR is the broader fallback for hosts where the
native library cannot be loaded at all.
I have opened this as a draft because #66351 is a feature request and the
CONTRIBUTING guide asks for design approval before new functionality.
How did you verify your code works?
clipboard, write fallback, failed tool write, no helper installed, and both
OSC 52 capability cases.
bun test packages/tui/test/clipboard.test.tspasses(12 tests).
tscagainst@opentui/core0.9.9.directly:
read(["image/png", "text/plain"])returned a PNG placed withwl-copybyte-for-byte,write()put text on the clipboard, and the sameheld with
WAYLAND_DISPLAYunset, which forces thexclipcandidates.opencode v2.4.3+cc15c65) and ran it in a PTY with aPNG on the clipboard. Its wrapper has no
libxcb, so the native backendreports
unsupported;Ctrl+Vstill inserted[Image 1]. WithWAYLAND_DISPLAYandDISPLAYunset, the same key inserted nothing andshowed no error, which is the intended empty fallback.
DISPLAYunset and failingwl-copy/xclipshims first on
PATH, the "Copy session ID" action showedFailed to copy session ID; with the real helpers it showedSession ID copied to clipboard!and emitted the OSC 52 sequence. A fakewl-copythat fails whilexclipsucceeds still completes the copy.Screenshots / recordings
Not a UI change.
Checklist