Skip to content

fix(tui): flush OSC 52 clipboard write, propagate errors on fallback#35289

Open
maorizenberg wants to merge 1 commit into
anomalyco:devfrom
maorizenberg:fix/clipboard-osc52-flush-wayland
Open

fix(tui): flush OSC 52 clipboard write, propagate errors on fallback#35289
maorizenberg wants to merge 1 commit into
anomalyco:devfrom
maorizenberg:fix/clipboard-osc52-flush-wayland

Conversation

@maorizenberg

@maorizenberg maorizenberg commented Jul 4, 2026

Copy link
Copy Markdown

Issue for this PR

Fixes #4283

Type of change

  • Bug fix

What does this PR do?

Copy-to-clipboard on Linux Wayland (e.g., Ubuntu 24.04) showed "Copied to clipboard" toast but paste returned old content. Two bugs:

  1. OSC 52 escape sequence used process.stdout.write() which buffers/interleaves with TUI rendering — terminal never processes sequence. Changed to fs.writeSync(process.stdout.fd, ...) for immediate flush to TTY fd.

  2. All clipboard write paths silently caught errors with .catch(() => undefined), swallowing failures when no clipboard tool (wl-copy, xclip) available. Removed catch — errors now propagate to caller which shows error toast.

Also added -i flag to xclip command for explicit stdin read.

How did you verify your code works?

Tested on Ubuntu 24.04 Wayland without wl-clipboard installed. Copy now works via OSC 52. All 192 existing tests pass. Typecheck clean across all 36 packages.

Screenshots / recordings

N/A (terminal fix, no UI change)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

- Replace process.stdout.write with fs.writeSync for OSC 52 escape
  sequence to ensure immediate flush to TTY fd
- Add -i flag to xclip command for explicit stdin read
- Remove .catch(() => undefined) from clipboard write paths so
  errors propagate to caller and show error toast instead of
  false 'Copied to clipboard'
- Update test to include -i flag in xclip expected args
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jul 4, 2026
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Related PRs Found:

  1. PR fix(tui): prevent false clipboard copy success on Linux #31252 - fix(tui): prevent false clipboard copy success on Linux

  2. PR fix(clipboard): write OSC52 to /dev/tty instead of stdout #12129 - fix(clipboard): write OSC52 to /dev/tty instead of stdout

    • Related: Directly addresses the same OSC 52 buffering issue with an alternative approach (writing to /dev/tty)
  3. PR fix(cli): Linux clipboard selection #32370 - fix(cli): Linux clipboard selection

    • Related: Linux clipboard functionality improvements
  4. PR fix: enable primary clipboard copy for Wayland/X11 to fix Linux middle-click paste #6370 - fix: enable primary clipboard copy for Wayland/X11 to fix Linux middle-click paste

    • Related: Addresses Wayland clipboard issues

Most relevant: PR #12129 appears to be the closest match—it also fixes the OSC 52 stdout buffering issue on Linux, though it uses /dev/tty instead of the fs.writeSync(process.stdout.fd, ...) approach in PR #35289.

@github-actions github-actions Bot removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Jul 4, 2026
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy To Clipboard is not working

1 participant