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

Support uploading image attachments from clipboard #36

Merged
merged 1 commit into from
May 20, 2023

Conversation

benjajaja
Copy link
Contributor

:upload argument is made optional. If omitted, then it will try to grab an image from the clipboard instead.

The user might not know this behaviour and the command does not indicate that the clipboard will be grabbed and uploaded without any confirmation. There could be sensitive information in it.

There should be some mechanism to confirm/ask the user, or await a "manual paste" (Ctrl-V? Shift-Ctrl-V?). I don't really know how to go on about "command steps" or something like that. @ulyssa wdyt?

@ulyssa
Copy link
Owner

ulyssa commented Feb 8, 2023

I think the way that this should probably work is through the "* register. When it's an image, iamb can then ask the user with a y/N prompt if they want to upload it. I just added support for using "* and "+ in ulyssa/modalkit#31, but it will still need ulyssa/modalkit#83.

@benjajaja
Copy link
Contributor Author

That's really nice, the vim way.

@ulyssa
Copy link
Owner

ulyssa commented Apr 29, 2023

I've released a version of modalkit that includes ulyssa/modalkit#83 and just pushed #45 which includes two examples of how to use PromptYesNo:

If you add a match for EditError::Register(RegisterError::ClipboardImage(data)) here, then you can turn that into a SendAction::UploadImage(ImageData<'static>) variant that the user is prompted to run.

@benjajaja
Copy link
Contributor Author

benjajaja commented May 6, 2023

Thanks @ulyssa, those two things have been super easy to use!
Arboard doesn't provide the mime type, and I have tried out two mime sniffing crates to no avail, only this image::DynamicImage::ImageRgba8 stuff works. Not even image::guess_format worked.
But that stuff could easily be swapped out later if someone figures this out.

I have tried this PR with png and jpeg images.

@benjajaja benjajaja marked this pull request as ready for review May 6, 2023 20:19
@benjajaja benjajaja changed the title Draft: Upload attachment from clipboard Upload attachment from clipboard May 6, 2023
@benjajaja
Copy link
Contributor Author

benjajaja commented May 8, 2023

Reading the arboard docs again, there is no mime-type because the bytes are always RGBA8, so the image crate usage to convert it to png seems correct.

@ulyssa ulyssa changed the title Upload attachment from clipboard Support uploading image attachments from clipboard May 20, 2023
@ulyssa ulyssa self-assigned this May 20, 2023
@ulyssa ulyssa merged commit 2899d4f into ulyssa:main May 20, 2023
@ulyssa
Copy link
Owner

ulyssa commented May 20, 2023

Merged! Thank you for implementing this, @benjajaja !

@schrmh
Copy link

schrmh commented Oct 21, 2023

The documentation for this is a bit unhelpful imo.
»Clipboard images can be uploaded by pasting from the clipboard register "*p, and following the confirmation dialog.«
Took me a bit to figure out that I have to write "+p to (usually) paste images on X11 instead of :upload.

E.g. this would be more helpful:
»To upload information from the clipboard, vim-like registers are used.

  • Write "*p to paste a PNG image on Windows or content from the PRIMARY selection (usually contains last selected text) on X11.
  • Write "+p to paste from the CLIPBOARD selection on X11.

Follow the confirmation dialog.«

@ulyssa
Copy link
Owner

ulyssa commented Nov 4, 2023

@schrmh Thank you for catching that this was underdocumented! I've updated the website to describe both registers, and provide example descriptions of behaviour.

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.

3 participants