Skip to content

feat: osc 5522 clipboard#4035

Open
UnnaturalTwilight wants to merge 5 commits into
sxyazi:mainfrom
UnnaturalTwilight:osc-5522-pr
Open

feat: osc 5522 clipboard#4035
UnnaturalTwilight wants to merge 5 commits into
sxyazi:mainfrom
UnnaturalTwilight:osc-5522-pr

Conversation

@UnnaturalTwilight

Copy link
Copy Markdown

Rationale of this PR

Adds support for using OSC 5522 (Kitty Clipboard Extension) to read and write all mime types from the system clipboard.

The main protocol can be found here: https://sw.kovidgoyal.net/kitty/clipboard/#copying-all-data-types-to-the-clipboard
The specification for paste events can be found here: https://rockorager.dev/misc/bracketed-paste-mime/
In cases where Kitty's implementation differs from the above specifications I have followed Kitty's implementation.

This pr implements support for copying and pasting text/uri-list as well as text/plain. The paste events have been exposed to lua similarly to drag and drop allowing supporting more formats easily. I have left the existing clipboard functions as is so ya.clipboard() and similar continue to use external clipboard tools. In the case of the copy keybindings support for OSC 5522 is detected and OSC 5522 is used if available, otherwise the original clipboard commands are used.

For now I have left the same 1MB size limit as the drag and drop however this will need to be revisited to support directly pasting files such as images from the clipboard.

I have tested this with Kitty 0.47.1

Checklist

@UnnaturalTwilight

Copy link
Copy Markdown
Author

Due to the significant discrepancy between Kitty's actual behavior and what is described at https://rockorager.dev/misc/bracketed-paste-mime/ I wrote up a Gist describing how the spec is actually implemented in Kitty.
https://gist.github.com/UnnaturalTwilight/2617336353fb5f8056413e3c759aa6d3
I believe Kitty's behavior follows the description and intent of the original spec, however the examples provided on that page do not match Kitty's behavior or my implementation. As Kitty is the only terminal I could find that currently implements the paste events mode I think it makes sense to treat its implementation as correct.

Comment thread yazi-plugin/preset/components/root.lua Outdated
Comment thread yazi-plugin/src/runtime/term.rs Outdated
Comment thread yazi-core/src/tasks/file.rs Outdated
Comment thread yazi-cli/src/env/env.rs Outdated
Comment thread yazi-actor/Cargo.toml
Comment thread yazi-plugin/preset/components/root.lua Outdated
Comment thread yazi-actor/src/mgr/copy.rs Outdated
Comment thread yazi-actor/src/app/clipboard.rs Outdated
Comment thread yazi-emulator/src/emulator.rs Outdated
Comment thread yazi-binding/src/clipboard.rs Outdated
Comment thread yazi-actor/src/app/mod.rs Outdated
Comment thread yazi-parser/src/spark/spark.rs Outdated
Comment thread yazi-binding/src/lib.rs Outdated
Comment thread yazi-term/src/sequence/clipboard.rs Outdated
Comment thread yazi-term/src/sequence/clipboard.rs Outdated
Comment thread yazi-term/src/sequence/clipboard.rs Outdated
Comment thread yazi-term/src/event/clipboard.rs Outdated
Comment thread yazi-term/src/event/clipboard.rs Outdated
Comment thread yazi-term/src/sequence/clipboard.rs Outdated
Comment thread yazi-term/src/sequence/clipboard.rs Outdated
Comment thread yazi-term/src/sequence/clipboard.rs Outdated
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.

2 participants