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

pr/199 #209

Merged
merged 5 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lua/image/backends/kitty/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,13 @@ backend.clear = function(image_id, shallow)
if not image then return end

if image.is_rendered then
local tty = get_clear_tty_override()
helpers.write_graphics({
action = codes.control.action.delete,
display_delete = "i",
image_id = image.internal_id,
quiet = 2,
tty = get_clear_tty_override(),
tty = tty,
})
end

Expand Down
12 changes: 12 additions & 0 deletions lua/image/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ api.setup = function(options)
then
local images_to_restore_on_focus = {}
local initial_tmux_window_id = utils.tmux.get_window_id()
local initial_tmux_session = utils.tmux.get_current_session()

vim.api.nvim_create_autocmd("FocusLost", {
group = group,
Expand All @@ -268,6 +269,7 @@ api.setup = function(options)
if
state.options.editor_only_render_when_focused
or (utils.tmux.is_tmux and utils.tmux.get_window_id() ~= initial_tmux_window_id)
or (utils.tmux.is_tmux and utils.tmux.get_current_session() ~= initial_tmux_session)
then
state.disable_decorator_handling = true

Expand All @@ -291,6 +293,16 @@ api.setup = function(options)
state.disable_decorator_handling = false

vim.schedule_wrap(function()
-- force rerender
local images = api.get_images()
for _, current_image in ipairs(images) do
if current_image.is_rendered then
current_image:clear()
current_image:render()
end
end

-- render images cleared on focus loss
for _, current_image in ipairs(images_to_restore_on_focus) do
current_image:render()
end
Expand Down
31 changes: 26 additions & 5 deletions lua/image/utils/tmux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ local create_dm_getter = function(name)
end
end

local create_dm_window_getter = function(name)
return function()
if not is_tmux then return nil end
local result = vim.fn.system(
"tmux list-windows -t $(tmux display-message -p '#{client_session}') -F '#{" .. name .. "}' -f '#{window_active}'"
)
return vim.fn.trim(result)
end
end

local create_dm_pane_getter = function(name)
return function()
if not is_tmux then return nil end
local result = vim.fn.system(
"tmux list-panes -t $(tmux display-message -p '#{client_session}') -F '#{" .. name .. "}' -f '#{pane_active}'"
)
return vim.fn.trim(result)
end
end

local escape = function(sequence)
return "\x1bPtmux;" .. sequence:gsub("\x1b", "\x1b\x1b") .. "\x1b\\"
end
Expand All @@ -23,11 +43,12 @@ return {
has_passthrough = has_passthrough,
get_pid = create_dm_getter("pid"),
get_socket_path = create_dm_getter("socket_path"),
get_window_id = create_dm_getter("window_id"),
get_window_name = create_dm_getter("window_name"),
get_pane_id = create_dm_getter("pane_id"),
get_pane_pid = create_dm_getter("pane_pid"),
get_pane_tty = create_dm_getter("pane_tty"),
get_current_session = create_dm_getter("client_session"),
get_window_id = create_dm_window_getter("window_id"),
get_window_name = create_dm_window_getter("window_name"),
get_pane_id = create_dm_pane_getter("pane_id"),
get_pane_pid = create_dm_pane_getter("pane_pid"),
get_pane_tty = create_dm_pane_getter("pane_tty"),
get_cursor_x = create_dm_getter("cursor_x"),
get_cursor_y = create_dm_getter("cursor_y"),
escape = escape,
Expand Down
Loading