fix(image): delay sending first image, to make ghostty happy. Closes #1333

This commit is contained in:
Folke Lemaitre 2025-02-20 10:17:08 +01:00
parent 5a2acf82b2
commit 9aa8cbb803
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -51,6 +51,16 @@ vim.api.nvim_create_autocmd("VimResized", {
end,
})
-- HACK: ghostty doesn't like it when sending images too fast,
-- after Neovim startup, so we delay the first image
local queue = {} ---@type string[]?
vim.defer_fn(function()
if queue and #queue > 0 then
io.stdout:write(table.concat(queue, ""))
queue = nil
end
end, 100)
function M.size()
if size then
return size
@ -172,12 +182,20 @@ function M.request(opts)
if Snacks.image.config.debug.request and opts.m ~= 1 then
Snacks.debug.inspect(opts)
end
io.stdout:write(data)
M.write(data)
end
---@param pos {[1]: number, [2]: number}
function M.set_cursor(pos)
io.stdout:write("\27[" .. pos[1] .. ";" .. (pos[2] + 1) .. "H")
M.write("\27[" .. pos[1] .. ";" .. (pos[2] + 1) .. "H")
end
function M.write(data)
if queue then
table.insert(queue, data)
else
io.stdout:write(data)
end
end
return M