Skip to content

feat(app): add --clipboard so Enter copies the drawing via OSC 52 - #34

Open
unclecode wants to merge 1 commit into
benvinegar:mainfrom
unclecode:feat/clipboard-copy
Open

feat(app): add --clipboard so Enter copies the drawing via OSC 52#34
unclecode wants to merge 1 commit into
benvinegar:mainfrom
unclecode:feat/clipboard-copy

Conversation

@unclecode

@unclecode unclecode commented Aug 11, 2026

Copy link
Copy Markdown

First of all, Thanks for publishing this under MIT - it is a genuinely nice tool.

Why

Exporting is currently the only way to get a drawing out of termDRAW. When the goal is simply to paste the art somewhere - a README, an issue, a chat with a coding agent - that means leaving the editor and dealing with a file. This adds an opt-in copy path so the drawing can go straight to the clipboard.

What

  • @termdraw/opentui: new onCopy option alongside onSave. When a host wires it, Enter routes to copy and Ctrl+S keeps exporting. When it is omitted, Enter and Ctrl+S stay merged exactly as they are today. The footer renders whichever binding is active (Enter Copy • Ctrl+S Export Art vs. the current Enter/Ctrl+S Export Art).
  • @termdraw/app: new --clipboard / -c flag, which wires onCopy to emit OSC 52.
  • Copying leaves the editor open, unlike export — copying is not a way of finishing, so the drawing stays editable and can be copied again after further edits. The status bar confirms with Copied drawing to clipboard.

This is entirely opt-in. With no onCopy handler and no --clipboard flag, behavior is unchanged; there is a test asserting Enter still saves in that case.

Why OSC 52

OSC 52 is handled by the terminal rather than the host OS, so it works unchanged over SSH and inside multiplexers, where a local helper like pbcopy would only ever reach the remote machine.

Caveats, documented in the README:

  • It is fire-and-forget. Terminals send no acknowledgement, so a terminal that does not implement OSC 52 (or has it disabled) ignores the request silently.
  • tmux forwards it only when set-clipboard is on or external.
  • screen needs its own wrapper; that is not handled here.

Validation

  • bun run lint - clean
  • bun run typecheck - clean across all three packages
  • bun run build - passes
  • bun test - 82 pass / 5 fail before, 87 pass / 5 fail after. The 5 remaining failures are pre-existing PTY timeouts in the tuistory-driven specs; they reproduce identically on an unmodified checkout in this environment.
  • bun run format:check - could not run here: oxfmt resolves a config from a directory above the repo and fails on an unrelated file outside the checkout. Formatting was verified instead by running oxfmt against a clean git archive export of the tree, which reported all files correctly formatted.

Also verified by hand in a terminal: drawing, pressing Enter, and pasting the result elsewhere; Ctrl+S still exporting and exiting while --clipboard is active; and the footer text in both modes.

Cheers

Exporting is currently the only way to get a drawing out of termDRAW, which means
leaving the editor and handling a file even when the goal is just to paste the art
somewhere. This adds an opt-in copy path.

- `@termdraw/opentui` gains an `onCopy` option alongside `onSave`. When a host wires it,
  Enter routes to copy and Ctrl+S keeps exporting; when it is omitted, Enter and Ctrl+S
  stay merged exactly as before. The footer reflects whichever binding is active.
- Copying leaves the editor open, unlike export: it is not a way of finishing, so the
  drawing stays editable and can be copied again after further edits. The status bar
  confirms with "Copied drawing to clipboard."
- `@termdraw/app` gains `--clipboard` / `-c`, which wires `onCopy` to emit OSC 52.

OSC 52 is handled by the terminal rather than the host OS, so it works unchanged over
SSH and inside multiplexers, where a helper like pbcopy would only reach the remote
machine. It is fire-and-forget: terminals send no acknowledgement, and one that does not
implement it (or has it disabled) ignores the request silently. tmux forwards it only
when set-clipboard is on or external; screen needs its own wrapper and is not handled.

Validation: bun run lint, bun run typecheck, bun test, bun run build. Test counts went
82 pass / 5 fail to 87 pass / 5 fail — the 5 remaining failures are pre-existing PTY
timeouts in the tuistory-driven specs and reproduce on an unmodified checkout here.
`bun run format:check` could not run in this environment (oxfmt resolves a config from a
parent directory outside the repo); formatting was verified with oxfmt on a clean export
of the tree instead.
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.

1 participant