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

Use custom image writers for kitty/iterm #157

Merged
merged 3 commits into from
Jan 21, 2024
Merged

Conversation

mfontanini
Copy link
Owner

@mfontanini mfontanini commented Jan 20, 2024

This introduces custom code to write images when using the kitty or iterm protocols. viuer is still used for ascii blocks and sixel, but it would be nice to get rid of that dependency at some point. The initial motivation for this PR was to fix #153: the PR I made on viuer (atanunq/viuer#53) has not shown any movement and the project is generally quite dead, I decided to implement this here instead. #153 is still open but with the ground work done on this PR it should be pretty easily fixable.

The new features/improvements this PR adds are:

  • Animated gif support for the kitty terminal. Wezterm/iterm already supported this and still do, this is now also supported in kitty.
  • Improved performance when printing images in every terminal. viuer always performs some non negligible amount of work when printing images:
    • When using kitty in local mode, it will convert the image into rgba8 and then write it on the filesystem every time you want to print it. This means if you want to print the same image 20 times, it will convert it and write it 20 times into the filesystem.
    • When using kitty in remote mode, it will always convert it into rgba8 before printing it, so partially the same as the above case execept without writing it into the filesystem.
    • When using iterm, it will always decode the image to get its dimensions every time you want to print it. This reduces the delay slightly when printing large images, e.g. gifs.
  • Reduced memory usage when using kitty in local mode as images are now persisted into a temporary directory using the right format as soon as they're loaded so that at the time we tell kitty to print the image, all we need to do is tell it where it is.
  • As an added bonus, this somehow fixed some extra padding that was being printed in wezterm after images. e.g. after an image, there used to be at least 2 newlines, whereas now there's only one. I still need to test on iterm.
  • This now also lets you configure --image-protocol to be kitty-local or kitty-remote as now we can decide what to use rather than being tied to what viuer decides.

Not that it really matters but the memory usage when running the demo presentation under kitty went down from ~15mb to ~14mb and the CPU usage when switching back and forth between the 2 slides in that presentation that contain an image went from ~3% to ~0.3%.

@mfontanini mfontanini merged commit cf1357d into master Jan 21, 2024
5 checks passed
@mfontanini mfontanini deleted the print-image-rewrite branch January 21, 2024 00:18
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.

Modals show up behind images in kitty terminal
1 participant