feat(app): add --clipboard so Enter copies the drawing via OSC 52 - #34
Open
unclecode wants to merge 1 commit into
Open
feat(app): add --clipboard so Enter copies the drawing via OSC 52#34unclecode wants to merge 1 commit into
unclecode wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: newonCopyoption alongsideonSave. 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 Artvs. the currentEnter/Ctrl+S Export Art).@termdraw/app: new--clipboard/-cflag, which wiresonCopyto emit OSC 52.Copied drawing to clipboard.This is entirely opt-in. With no
onCopyhandler and no--clipboardflag, 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
pbcopywould only ever reach the remote machine.Caveats, documented in the README:
set-clipboardisonorexternal.screenneeds its own wrapper; that is not handled here.Validation
bun run lint- cleanbun run typecheck- clean across all three packagesbun run build- passesbun 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 cleangit archiveexport 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
--clipboardis active; and the footer text in both modes.Cheers