Skip to content

Commit

Permalink
fix: session clear & forced rerender on focusgained
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd committed Jul 31, 2024
1 parent 838579b commit 3f0cbb5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
1 change: 0 additions & 1 deletion lua/image/backends/kitty/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ backend.clear = function(image_id, shallow)

if image.is_rendered then
local tty = get_clear_tty_override()
if tty == nil then tty = utils.tmux.get_active_pane_tty() end
helpers.write_graphics({
action = codes.control.action.delete,
display_delete = "i",
Expand Down
12 changes: 11 additions & 1 deletion lua/image/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +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_attached_session() ~= initial_tmux_session)
or (utils.tmux.is_tmux and utils.tmux.get_current_session() ~= initial_tmux_session)
then
state.disable_decorator_handling = true

Expand All @@ -293,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
16 changes: 0 additions & 16 deletions lua/image/utils/tmux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,6 @@ local create_dm_getter = function(name)
end
end

local get_active_pane_tty = function()
if not is_tmux then return nil end
local result = vim.fn.system(
"tmux list-sessions -F '#{session_name} #{session_attached}' | awk '$2 == \"1\" {print $1}' | xargs -I{} tmux list-panes -t {} -F '#{pane_active} #{pane_tty}' | awk '$1 == \"1\" {print $2}'"
)
return vim.fn.trim(result)
end

local get_attached_session = function()
if not is_tmux then return nil end
local result = vim.fn.system("tmux list-sessions | grep \"(attached)\" | sed -E 's/:.*$//'")
return vim.fn.trim(result)
end

local escape = function(sequence)
return "\x1bPtmux;" .. sequence:gsub("\x1b", "\x1b\x1b") .. "\x1b\\"
end
Expand All @@ -37,13 +23,11 @@ return {
has_passthrough = has_passthrough,
get_pid = create_dm_getter("pid"),
get_socket_path = create_dm_getter("socket_path"),
get_attached_session = get_attached_session,
get_current_session = create_dm_getter("session_name"),
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_active_pane_tty = get_active_pane_tty,
get_pane_tty = create_dm_getter("pane_tty"),
get_cursor_x = create_dm_getter("cursor_x"),
get_cursor_y = create_dm_getter("cursor_y"),
Expand Down

0 comments on commit 3f0cbb5

Please sign in to comment.