Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Resize images to columns #258

Merged
merged 8 commits into from
Apr 22, 2023
Merged

Resize images to columns #258

merged 8 commits into from
Apr 22, 2023

Conversation

swsnr
Copy link
Owner

@swsnr swsnr commented Apr 21, 2023

Instead of rendering images over the whole terminal size with the kitty graphics protocol, render them up to the given column limit so that images align with the surrounding text.

Use the kitty graphics protocol to render images in wezterm; the protocol is more powerful and more solid than the iterm2 one.

Refactor kitty image data representation and chunk writing to make it safer to use and easier to understand.

@swsnr swsnr force-pushed the resize-images-to-columns branch 3 times, most recently from a223c03 to 926757f Compare April 21, 2023 18:03
swsnr added 3 commits April 21, 2023 20:09

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
The protocol is more complex but also more powerful.
@swsnr swsnr force-pushed the resize-images-to-columns branch from e871be7 to e84a80c Compare April 21, 2023 18:11
swsnr added 3 commits April 21, 2023 20:51
Instead of scaling down to window width scale down to the number of
allowed columns.  This makes sure the image fits to the surrounding text
if --columns passed is much smaller than the window size.
Pass control code q=2 to silence all responses from the terminal as we
don't listen to those anyway, and I=1 to force the terminal to consider
every image we write as unique.

Also document all those cnotrol codes we use.
This was present since the original implementation in #104
but it looks as if it was just copied from code in kitty's
documentation.

I don't think we really need to flush all buffers here.
@swsnr swsnr force-pushed the resize-images-to-columns branch from e84a80c to 9b5f2e0 Compare April 21, 2023 18:52
swsnr added 2 commits April 22, 2023 09:06
Write chunk header statically instead of filling and clearing a vector;
the latter was copied verbatim from the Python reference implementation
but I find it cumbersome and inelegant in Rust.

Merge KittyImage and KittyImageFormat into a single KittyImageData enum
whose type ensures that `size` is specified when it must be specified
according to the specification.  The original implementation did not
prevent writing an RGB image without size/height which is invalid
according to the specification.
Make sure that we properly discard any mime type parameters the HTTP
header might have included.
@swsnr swsnr marked this pull request as ready for review April 22, 2023 07:08
@swsnr swsnr added the enhancement New feature or request label Apr 22, 2023
@swsnr swsnr self-assigned this Apr 22, 2023
@swsnr swsnr enabled auto-merge April 22, 2023 07:10
@swsnr swsnr merged commit ee4783a into main Apr 22, 2023
@swsnr swsnr deleted the resize-images-to-columns branch April 22, 2023 07:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant