Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for non-text clipboard content #36

Open
liquidev opened this issue Nov 13, 2021 · 12 comments
Open

Add support for non-text clipboard content #36

liquidev opened this issue Nov 13, 2021 · 12 comments
Labels
enhancement New feature or request

Comments

@liquidev
Copy link

Some data that goes through the clipboard is not necessarily text, one example is images. Currently copypasta uses Strings to transfer all clipboard data, which all guarantee that the data inside is valid UTF-8, and panic if it's not. This prevents users from transferring non-text data through the clipboard.

@chrisduerr
Copy link
Member

While non-text clipboard support is a valid feature request, that should really never be in the form of just some arbitrary Vec<u8>.

That said, this is not something I have any usecase for at all. So if someone is interested in this feature you'll likely have to send a PR yourself.

@chrisduerr chrisduerr added the enhancement New feature or request label Nov 14, 2021
@liquidev
Copy link
Author

Yeah, I've researched a bit more on how system clipboards work and it's not just as simple as putting a PNG file into the clipboard after all… Different systems handle image files differently. On Linux (X11 and Wayland) you have to set the MIME type to image/png; on Windows you have to specify that the clipboard should be a BMP file and put one in there, I don't know about macOS.

There seem to be other forks of rust-clipboard like arboard, but there the readme says the author is not interested in maintaining the library and will be archiving the repository soon. Copypasta seems to be the most supported one (thanks to it being used in alacritty), so introducing support for other formats to this library would make sense from a support perspective.

@chrisduerr chrisduerr changed the title Accept Vec<u8> as a parameter/return value instead of a String Add support for non-text clipboard content Nov 15, 2021
@chrisduerr
Copy link
Member

Copypasta seems to be the most supported one

I'm definitely happy to maintain copypasta and fix issues popping up. But it does everything I want both for Alacritty and any other application I might want to write. But as stated previously, I'm happy to put in the time to review PRs related to a more sophisticated API which includes image support.

@conradev
Copy link
Contributor

conradev commented Apr 19, 2023

One feature that I really would like to implement in alacritty is better support for the "file" clipboard type on macOS. If I drag a file into macOS Terminal from Finder, it pastes the full path to the file and properly escapes any spaces. In alacritty, only the base name is pasted. macOS has multiple representations for a given item, and so the default string representation of a file is just the base name.

There are a few approaches that I can see to bring this to alacritty:

  1. Adding this behavior to copypasta
  2. Exposing macOS-specific functionality for alacritty to implement the behavior
  3. Building a cross-platform API to encapsulate being able to get files from the clipboard and using that from alacritty

I'm currently leaning towards 2, but I'd love to get your thoughts @chrisduerr on which approach would be best

@chrisduerr
Copy link
Member

One feature that I really would like to implement in alacritty is better support for the "file" clipboard type on macOS. If I drag a file into macOS Terminal from Finder, it pastes the full path to the file and properly escapes any spaces. In alacritty, only the base name is pasted. macOS has multiple representations for a given item, and so the default string representation of a file is just the base name.

That is intentional. We do not want to escape file paths in Alacritty.

@conradev
Copy link
Contributor

Why is that? Is there a security/correctness concern, or is the ability to copy a file in a file manager and paste it as a path in the terminal window not desirable to you?

@chrisduerr
Copy link
Member

Why is that? Is there a security/correctness concern, or is the ability to copy a file in a file manager and paste it as a path in the terminal window not desirable to you?

Because it is so much easier to just quote something you want escaped than to remove the escape characters from something you don't want escaped.

@conradev
Copy link
Contributor

conradev commented Apr 29, 2023

@chrisduerr oh, that makes sense! My use of the term escaping was incorrect, then, because I do not care how the path gets into the terminal, as long as I have some way of getting it in there. Escaping/quoting is a fine exercise to leave up to the reader, because I know how to use quotes.

If the change was only so that files get pasted as their full file paths and not base names, would that be a change that you'd consider?

@chrisduerr
Copy link
Member

If the change was only so that files get pasted as their full file paths and not base names, would that be a change that you'd consider?

I kinda assumed that how it works already. I don't really use it myself. So I'd be open to the idea I guess.

@muja
Copy link

muja commented Jun 25, 2023

FYI I made a PR to rust-clipboard years ago where this was also addressed.. it's not very trivial especially considering multiple platforms. There are some thoughts on that in the PR.
aweinstock314/rust-clipboard#60

@chrisduerr
Copy link
Member

I'm not sure major changes to copypasta are worthwhile considering any non-trivial application should make use of a different clipboard library anyway.

Focusing on text-only makes sense for something that is completely separate, but if you actually want proper clipboard management the better solution is proper integration with your window management loop.

@Exidex
Copy link

Exidex commented Jun 10, 2024

Worth noting that Web Clipboard API does allow for arbitrary Vec<u8> data with attached MIME type. There is a list of supported MIME types here. Its still just: text, html and png, but it may be worth designing api in similar way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

5 participants