Skip to content

Large images inconsistent display using direct mode #95

@SigmaRichards

Description

@SigmaRichards

This is something I've been exploring the cause of for a bit. Using kitty in direct-mode when displaying images (e.g. over SSH) occasionally causes images to not be displayed. I find this occurs regularly when the cropped + resized images are over 30kb.

The easiest way to test is by using ssh localhost, however, it occurs outside of ssh if you directly set is_SSH in lua/image/backends/kitty/init.lua. This happens both in and out of TMUX.

During one of the failures, I noted that the characters received by the terminal (i.e. the output of kitty --dump-commands) included a 5 character addition and further in the sequence a 1 character deletion - causing everything within this section to become corrupted once decoded. However, the bytes as reported by lua before being sent appear to be correct.

When using direct-mode, the protocol sends the 4096 base64 characters (effectively sending 3072 bytes each time) so 30kb is roughly 10 write-commands. When the file is small enough for only 9 write commands to be sufficient, the success rate is 90%, 10 commands is about 50% success, and 11 is about 10%.

Potential fix

I'm still trying to explore exactly what causes this issue, however, below is something I found which improves the success rate significantly. Annoyingly, it's another case of I can't explain why it helps.

+++ b/lua/image/backends/kitty/helpers.lua
@@ -92,6 +92,7 @@ local write_graphics = function(config, data)
       else
         control_payload = "m=1"
       end
+      vim.loop.sleep(1)
     end
   else
     -- utils.debug("kitty control payload:", control_payload)

I haven't had the issue occur at all using ssh AND tmux with this change. However, it will occasionally still occur when using JUST ssh. I'm still exploring, but if/when I come across something more conclusive I'll post a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions