Skip to content

tui: /copy + Ctrl+Y copy an assistant reply's raw markdown to the clipboard#363

Open
erain wants to merge 1 commit into
mainfrom
tui-copy-clipboard-362
Open

tui: /copy + Ctrl+Y copy an assistant reply's raw markdown to the clipboard#363
erain wants to merge 1 commit into
mainfrom
tui-copy-clipboard-362

Conversation

@erain

@erain erain commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Closes #362.

Problem

Copying an assistant reply out of the TUI to paste elsewhere was painful: terminal selection drags in glamour styling (ANSI codes, box-drawing, wrapped/indented lines), so the pasted text came out mangled.

Fix

The clean source already exists — the transcript keeps each assistant item's raw markdown in transcriptItem.Text, separate from the glamour-rendered Rendered (finalized in handleTurnDone). This plumbs that raw text to the system clipboard.

  • /copy [N] — copies the last assistant reply, or reply N (1-based over assistant turns, tool-only turns skipped). Listed in slashSpecs() so it shows in /help and the / picker.
  • Ctrl+Y — the no-arg form of /copy, handled in handleInputKey before the pickers/textarea so it fires from any input state.
  • OSC 52 delivery (go-osc52, promoted from indirect to direct dep), written to the tty. Works locally and over SSH with no external binary (unlike pbcopy/xclip), and doesn't fight bubbletea's alt-screen stdout renderer.
  • A · copied last reply (1234 chars) to clipboard. system line confirms; friendly messages when there's no reply yet or N is out of range.

Tests

  • pickCopyTarget factored out as a pure function: covers default-is-last, explicit N, trimming, and the zero/too-high/non-numeric bounds.
  • assistantTexts skips blank/tool-only turns and non-assistant items.
  • copyToClipboard asserts the OSC 52 envelope + base64 payload (clipboard writer is overridable in tests).
  • runSlashCopy confirmation + empty-transcript paths.
  • Updated TestSlashMatchesStayAlphabetical for the new /ccopy match.

Full go test ./..., gofmt, and go vet are green. README + CHANGELOG updated.

🤖 Generated with Claude Code

…pboard (closes #362)

Selecting an assistant reply out of the terminal dragged in glamour
styling (ANSI codes, box-drawing, wrapped/indented lines), so the paste
was mangled. The transcript already keeps each reply's raw markdown in
transcriptItem.Text, separate from the glamour-rendered Rendered field —
this plumbs that clean text to the system clipboard.

- /copy [N]: copies the last assistant reply, or reply N (1-based over
  assistant turns), as raw markdown. Added to slashSpecs so it shows in
  /help and the / picker.
- Ctrl+Y: the no-arg form of /copy, handled in handleInputKey before the
  pickers and textarea so it fires from any input state.
- Delivery via OSC 52 (go-osc52, promoted to a direct dep) written to the
  tty — works locally and over SSH with no external binary, and doesn't
  fight bubbletea's alt-screen stdout renderer.
- Pure pickCopyTarget keeps the numbering/bounds logic unit-testable.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown

glue-review

No concerns — LGTM.


🤖 Posted by glue-review.

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.

TUI: copy an assistant reply's raw markdown to the system clipboard (/copy + Ctrl+Y)

1 participant