[PR #546] [MERGED] feat(clipboard): add OSC 52 clipboard support for SSH/remote sessions #610

Closed
opened 2026-03-02 23:47:20 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opentui/pull/546
Author: @Son0fSun
Created: 1/17/2026
Status: Merged
Merged: 1/31/2026
Merged by: @kommander

Base: mainHead: main


📝 Commits (10+)

📊 Changes

13 files changed (+727 additions, -68 deletions)

View changed files

📝 packages/core/src/examples/console-demo.ts (+8 -9)
packages/core/src/lib/clipboard.test.ts (+100 -0)
packages/core/src/lib/clipboard.ts (+43 -0)
📝 packages/core/src/renderer.ts (+25 -1)
📝 packages/core/src/testing/test-renderer.ts (+4 -1)
📝 packages/core/src/zig-structs.ts (+1 -0)
📝 packages/core/src/zig.ts (+16 -4)
📝 packages/core/src/zig/ansi.zig (+4 -0)
📝 packages/core/src/zig/lib.zig (+16 -2)
📝 packages/core/src/zig/renderer.zig (+19 -1)
📝 packages/core/src/zig/terminal.zig (+211 -50)
📝 packages/core/src/zig/tests/terminal_test.zig (+221 -0)
packages/core/src/zig/tests/test_utils.zig (+59 -0)

📄 Description

Summary

  • Add cross-platform clipboard support using OSC 52 escape sequences
  • Enable copy/paste operations to work over SSH connections
  • Replace macOS-only pbcopy in console-demo with portable OSC 52

Problem

Clipboard operations don't work when running OpenTUI applications over SSH because the app doesn't have access to the local clipboard. This breaks copy/paste workflows for remote development.

Fixes https://github.com/sst/opencode/issues/6111
Fixes https://github.com/anomalyco/opencode/issues/2773

Solution

OSC 52 is an ANSI escape sequence that allows terminal applications to interact with the system clipboard through the terminal emulator. The terminal handles the clipboard operation locally, so it works seamlessly over SSH.

New API

import { copyToClipboard, clearClipboard, isOsc52Supported } from "@opentui/core"

// Copy text to clipboard
copyToClipboard("Hello, world!")

// With options
copyToClipboard(text, { 
  target: "clipboard",  // or "primary", "secondary"
  silent: true          // suppress errors
})

// Check support
if (isOsc52Supported()) {
  // OSC 52 likely supported
}

Supported Environments

  • Direct terminals: iTerm2, Kitty, Alacritty, Windows Terminal, foot, WezTerm
  • tmux: Full passthrough support including nested sessions
  • GNU Screen: Proper DCS passthrough format

Technical Details

OSC 52 format: ESC ] 52 ; <target> ; <base64-content> ST

For terminal multiplexers, the sequence must be wrapped in DCS passthrough:

  • tmux: ESC P tmux; ESC ESC <seq> ESC \
  • screen: ESC P ESC ESC <seq> ESC \

Changes

File Description
packages/core/src/lib/clipboard.ts New OSC 52 clipboard module
packages/core/src/lib/clipboard.test.ts Comprehensive test suite (11 tests)
packages/core/src/lib/index.ts Export clipboard functions
packages/core/src/examples/console-demo.ts Use OSC 52 instead of pbcopy

Test plan

  • Unit tests pass (bun test packages/core/src/lib/clipboard.test.ts)
  • Tested copy operation over SSH session
  • Verified paste works on local machine (macOS)
  • Test on Windows Terminal
  • Test inside tmux
  • Test inside GNU Screen

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opentui/pull/546 **Author:** [@Son0fSun](https://github.com/Son0fSun) **Created:** 1/17/2026 **Status:** ✅ Merged **Merged:** 1/31/2026 **Merged by:** [@kommander](https://github.com/kommander) **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (10+) - [`8e9b138`](https://github.com/anomalyco/opentui/commit/8e9b138dece5b340a861c662258ea7a159cd2415) feat(clipboard): add OSC 52 clipboard support for SSH/remote sessions - [`115c632`](https://github.com/anomalyco/opentui/commit/115c632994c587cf1131881c9719f950cd444ebe) Merge branch 'main' into main - [`9f8d859`](https://github.com/anomalyco/opentui/commit/9f8d859a46ad2ab40c427017071312921564e9fb) wip - [`56a07ad`](https://github.com/anomalyco/opentui/commit/56a07ad9fa609f47b04526c725b61ecaf5c91000) refactor - [`2b21a8c`](https://github.com/anomalyco/opentui/commit/2b21a8c9e4bd1b3907b102d34cfaf1d8e8f01cec) factor to renderer private - [`4524c4d`](https://github.com/anomalyco/opentui/commit/4524c4db98cd6593d2ce20eb53f4c6b37b688bc4) use enum - [`d10a011`](https://github.com/anomalyco/opentui/commit/d10a011145a3818d01cd67b024b9018f50699976) stash wip - [`937f5bc`](https://github.com/anomalyco/opentui/commit/937f5bcb4e98e5184099b68503252a2ec1f627a5) cleanup - [`f0538e3`](https://github.com/anomalyco/opentui/commit/f0538e358739406e2a10df57c044da9174029a5a) coverage - [`d61085c`](https://github.com/anomalyco/opentui/commit/d61085c9927da0621164944a0ad0a77711bdae3c) Merge branch 'main' into main ### 📊 Changes **13 files changed** (+727 additions, -68 deletions) <details> <summary>View changed files</summary> 📝 `packages/core/src/examples/console-demo.ts` (+8 -9) ➕ `packages/core/src/lib/clipboard.test.ts` (+100 -0) ➕ `packages/core/src/lib/clipboard.ts` (+43 -0) 📝 `packages/core/src/renderer.ts` (+25 -1) 📝 `packages/core/src/testing/test-renderer.ts` (+4 -1) 📝 `packages/core/src/zig-structs.ts` (+1 -0) 📝 `packages/core/src/zig.ts` (+16 -4) 📝 `packages/core/src/zig/ansi.zig` (+4 -0) 📝 `packages/core/src/zig/lib.zig` (+16 -2) 📝 `packages/core/src/zig/renderer.zig` (+19 -1) 📝 `packages/core/src/zig/terminal.zig` (+211 -50) 📝 `packages/core/src/zig/tests/terminal_test.zig` (+221 -0) ➕ `packages/core/src/zig/tests/test_utils.zig` (+59 -0) </details> ### 📄 Description ## Summary - Add cross-platform clipboard support using OSC 52 escape sequences - Enable copy/paste operations to work over SSH connections - Replace macOS-only `pbcopy` in console-demo with portable OSC 52 ## Problem Clipboard operations don't work when running OpenTUI applications over SSH because the app doesn't have access to the local clipboard. This breaks copy/paste workflows for remote development. Fixes https://github.com/sst/opencode/issues/6111 Fixes https://github.com/anomalyco/opencode/issues/2773 ## Solution OSC 52 is an ANSI escape sequence that allows terminal applications to interact with the system clipboard through the terminal emulator. The terminal handles the clipboard operation locally, so it works seamlessly over SSH. ### New API ```typescript import { copyToClipboard, clearClipboard, isOsc52Supported } from "@opentui/core" // Copy text to clipboard copyToClipboard("Hello, world!") // With options copyToClipboard(text, { target: "clipboard", // or "primary", "secondary" silent: true // suppress errors }) // Check support if (isOsc52Supported()) { // OSC 52 likely supported } ``` ### Supported Environments - **Direct terminals**: iTerm2, Kitty, Alacritty, Windows Terminal, foot, WezTerm - **tmux**: Full passthrough support including nested sessions - **GNU Screen**: Proper DCS passthrough format ## Technical Details OSC 52 format: `ESC ] 52 ; <target> ; <base64-content> ST` For terminal multiplexers, the sequence must be wrapped in DCS passthrough: - tmux: `ESC P tmux; ESC ESC <seq> ESC \` - screen: `ESC P ESC ESC <seq> ESC \` ## Changes | File | Description | |------|-------------| | `packages/core/src/lib/clipboard.ts` | New OSC 52 clipboard module | | `packages/core/src/lib/clipboard.test.ts` | Comprehensive test suite (11 tests) | | `packages/core/src/lib/index.ts` | Export clipboard functions | | `packages/core/src/examples/console-demo.ts` | Use OSC 52 instead of pbcopy | ## Test plan - [x] Unit tests pass (`bun test packages/core/src/lib/clipboard.test.ts`) - [x] Tested copy operation over SSH session - [x] Verified paste works on local machine (macOS) - [ ] Test on Windows Terminal - [ ] Test inside tmux - [ ] Test inside GNU Screen 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 23:47:20 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/opentui#610
No description provided.