Repository navigation
Conversation
There was a problem hiding this comment.
Thanks for this. The interop writer itself looks solid, but I'm not convinced it fixes the reported case, and it can make copies fail that may work today.
How I checked: I have no WSL here. I ran the default writer against a fake powershell.exe on PATH, using the "host timed out, terminal attempted" result. The UTF-8 text arrived exactly, and a non-zero exit, a hang (killed at about 3 s) and a missing powershell.exe all rejected with clear errors. Outside WSL it behaves as before. bun test test/clipboard.test.ts passes and tsc -b is clean.
Public API: the only addition is the optional options.windowsClipboard argument on createClipboardAdapter, which is internal to packages/tui. Nothing outside depends on it, and it is backwards compatible.
Concerns:
- The reported failure may not be what this fixes. Your manual check (host
unsupported, terminalnot-attempted) already throws on the base, so it shows an error rather than the false "Copied to clipboard" toast from #65913. The reporter has WSLg withDISPLAYandWAYLAND_DISPLAYset. If the host write reportswrittenthere (taken by WSLg but not synced to Windows), this change returns early and does nothing. The regression also lines up with the OpenTUI 0.8 → 0.9 bump (#63989), sinceclipboard.tshasn't changed since #61094, so the root cause may be in OpenTUI. Could you show whatresult.hostandresult.terminalactually are in the reporter's setup (WSLg + Windows Terminal, default env)? - Copies that may work today now fail. Windows Terminal does support OSC 52 copy. On WSL with no usable interop (
appendWindowsPath=false, interop off) and terminal capabilityunknown, a copy that may well have worked on the base now shows an error (see the inline comment). - Latency. Every WSL copy whose host write fails now waits for
powershell.exeto start (often around a second) before the toast appears, even when OSC 52 already worked.
| if (result.host.status === "written") return | ||
| // The native host clipboard can time out or fail on WSL, and Windows Terminal ignores | ||
| // OSC 52, so write through Windows interop before trusting an "attempted" terminal write. | ||
| if (isWSL()) { |
There was a problem hiding this comment.
When the interop write fails, this only keeps the terminal result if capability === "supported". With "unknown", which may be what Windows Terminal often reports, it now throws. Windows Terminal does handle OSC 52 writes, so on WSL without a usable powershell.exe (appendWindowsPath=false, interop disabled, PATH stripped) a copy that may well have worked on the base becomes an error toast. Could the interop failure fall back to the old attempted handling unless the capability is "unsupported"? That keeps this a pure improvement, not a new way to fail. It also deserves a test with capability "unknown", since that is the common case.
There was a problem hiding this comment.
Thanks, both points were right. I measured the reporter's setup (WSLg + Windows Terminal, default DISPLAY=:0, WAYLAND_DISPLAY=wayland-0): the host write returns {"status":"written"} in 4-5 ms and wl-paste shows the text on the Wayland selection, but the Windows clipboard keeps its previous content. So the early return was skipping the fix for the reported case.
The WSL path now mirrors every copy through powershell.exe in parallel with the normal write, and interop succeeding is what makes it a success; if interop is unavailable or fails it falls back to the old result, with unknown treated as before and covered by a test. The cost is one interop process per WSL copy (~310 ms here); I could not find a cheaper way to tell whether a host written actually reached Windows. The measured statuses are in the PR description.
WSLg can report a successful host clipboard write that never reaches the Windows clipboard, and Windows Terminal may ignore OSC 52, so the TUI reported a copy that did not happen. Mirror WSL copies through powershell.exe interop in parallel, and only report a failure when no route can have copied the text.
ad9ad90 to
831ad10
Compare
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
There was a problem hiding this comment.
The new commits address my earlier point. When interop fails, copies fall back to the earlier result: the host reported written, or the terminal attempted OSC 52 and does not report it as unsupported. Copies that might have worked no longer turn into errors, and the unknown case now has a test. Running interop in parallel on every WSL copy also covers the case you measured, where WSLg reports written but the Windows clipboard doesn't change.
I can't run WSL here. With a fake powershell.exe, the mirror ran and received the exact text even when the host reported written. Without interop, the copy only failed when OSC 52 was reported as unsupported. Outside WSL nothing changes. bun test test/clipboard.test.ts passes (11) and tsc -b is clean.
Public API unchanged: the only addition is the internal optional windowsClipboard option on createClipboardAdapter.
No further concerns.
Issue for this PR
Closes #65913
Type of change
What does this PR do?
On WSL the TUI can report a successful copy while the Windows clipboard keeps its previous content. Measured here (WSLg + Windows Terminal, default
DISPLAY/WAYLAND_DISPLAY): OpenTUI's host write returns{"status":"written"}in about 5 ms and the text appears on the Wayland selection (wl-pasteshows it), but the Windows clipboard is unchanged; the OSC 52 write alone did not reach it either.This mirrors every copy made under WSL through
powershell.exeinterop (Set-Clipboardover UTF-8 stdin, 3 s timeout) in parallel with the normal write, and treats the copy as successful when interop succeeds. If interop is unavailable or fails, it falls back to the previous behaviour: the host reportedwritten, or an attempted OSC 52 write unless the terminal reports it as unsupported. Tests inject the Windows writer, so they never touch the real clipboard.How did you verify your code works?
write()resolved in ~310 ms and the Windows clipboard held the exact text; on the base commit it resolved without changing the clipboard.DISPLAY/WAYLAND_DISPLAYunset: before,Clipboard write failed (host: unsupported, terminal: not-attempted); after, resolved and the clipboard held the text.cd packages/tui && bun test test/clipboard.test.ts(11 pass),bun run typecheck, Prettier.Screenshots / recordings
N/A (no UI change)
Checklist
Added by the opencode bot (AI-generated).
Related: #59664, #49895