Skip to content

Prevent page clear/show flash on kitty when pages have been cleared from memory.#148

Merged
itsjunetime merged 4 commits intomainfrom
june/no_kitty_flash
Apr 24, 2026
Merged

Prevent page clear/show flash on kitty when pages have been cleared from memory.#148
itsjunetime merged 4 commits intomainfrom
june/no_kitty_flash

Conversation

@itsjunetime
Copy link
Copy Markdown
Owner

Kitty has a special way of displaying images to the terminal. Basically, when you transfer an image for the first time, kitty gives you back an 'id' which you can use to display that same image again. This is very useful for a program like tdf, where many of the images are repeated.

However, kitty also has some limits on how many images it'll store for you - if you send over too many images, it'll start deleting 'old' images, rendering their ids useless. So if you try to use the id of an image that was deleted, kitty will simply respond with an 'image not found'-type error, and you'll have to re-render/re-send the image to get it to actually show.

The Issue

This caused some annoying issues with the way that we would previously display images with kitty. What we would do is:

  1. Clear all previously-shown images
  2. Draw new images

Pretty simple - if one of the new images failed to display (for whatever reason) there would just be a big blank slot on the UI instead of the image. This meant that whenever we encountered a deleted id, the image UI would go blank for a second due to the image not being found, then flash back into existence once it was re-rendered by our background thread.

On my machine, this process is quick enough to feel very jarring.

The Fix

This PR changes the order of rendering to be:

  1. Draw all images at a z-index of N+1
  2. If all images drew successfully, clear all images that exist at a z-index of N
  3. Increment stored z-index to prepare for next time

This ensures that each time we have a 'normal' sequence of events (where there are no dead ids), we still display the new images just as quickly as normal, on top of the old ones (which are then cleared after they're not visible).

However, this is a much better experience when we have dead ids. In this circumstance, the old images still stay there until the new images are ready. On my machine, this normally manifests as a very small (in the order of 100ms, if I had to wildly guess based on playing around with this for just a little bit) delay in displaying the new images each time we run into a dead id.

This is not perfectly ideal, since we still have the delay after trying to display an image, failing to do so, and having to re-render it, but it'll be much better than before.

@itsjunetime itsjunetime merged commit 5e4fbff into main Apr 24, 2026
5 checks passed
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.

1 participant