Skip to content

Commit

Permalink
fix: remove tmux cursor delay and silence winclosed error
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd committed Sep 20, 2023
1 parent f654b72 commit 0b2dae8
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 8 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ require("image").setup({
max_width_window_percentage = nil,
max_height_window_percentage = 50,
kitty_method = "normal",
kitty_tmux_write_delay = 10, -- makes rendering more reliable with Kitty+Tmux
window_overlap_clear_enabled = false, -- toggles images when windows are overlapped
window_overlap_clear_ft_ignore = { "cmp_menu", "cmp_docs", "" },
})
Expand Down
4 changes: 2 additions & 2 deletions lua/image/backends/kitty/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ local write = function(data)
-- vim.fn.chansend(vim.v.stderr, data)
end

local move_cursor = function(x, y, save, tmux_delay)
local move_cursor = function(x, y, save)
if save then write("\x1b[s") end
write("\x1b[" .. y .. ";" .. x .. "H")
if is_tmux and tmux_delay then vim.loop.sleep(tmux_delay) end
vim.loop.sleep(1)
end

local restore_cursor = function()
Expand Down
2 changes: 1 addition & 1 deletion lua/image/backends/kitty/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ backend.render = function(image, x, y, width, height)
display_payload.display_y = pixel_top
end

helpers.move_cursor(x + 1, y + 1, true, backend.state.options.kitty_tmux_write_delay)
helpers.move_cursor(x + 1, y + 1, true)
helpers.write_graphics(display_payload)
image.is_rendered = true
backend.state.images[image.id] = image
Expand Down
5 changes: 3 additions & 2 deletions lua/image/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ local default_options = {
max_width_window_percentage = nil,
max_height_window_percentage = 50,
kitty_method = "normal",
kitty_tmux_write_delay = 10,
window_overlap_clear_enabled = false,
window_overlap_clear_ft_ignore = { "cmp_menu", "cmp_docs", "" },
}
Expand Down Expand Up @@ -194,7 +193,9 @@ api.setup = function(options)
vim.schedule(function()
local images = api.get_images()
for _, current_image in ipairs(images) do
if vim.api.nvim_win_is_valid(current_image.window) then
local ok, is_valid = pcall(vim.api.nvim_win_is_valid, current_image.window)
if not ok then return end
if is_valid then
current_image:render()
else
current_image:clear()
Expand Down
1 change: 0 additions & 1 deletion lua/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
---@field max_width_window_percentage? number
---@field max_height_window_percentage? number
---@field kitty_method "normal"|"unicode-placeholders"
---@field kitty_tmux_write_delay? number
---@field window_overlap_clear_enabled? boolean
---@field window_overlap_clear_ft_ignore? string[]

Expand Down
1 change: 0 additions & 1 deletion minimal-setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ require("lazy").setup({
max_width_window_percentage = nil,
max_height_window_percentage = 50,
kitty_method = "normal",
kitty_tmux_write_delay = 10,
},
},
})
Expand Down

0 comments on commit 0b2dae8

Please sign in to comment.