From 31fb75bd1b8584397dc33f6901df363218915b7f Mon Sep 17 00:00:00 2001 From: Alexander Bugge Stage Date: Thu, 19 Nov 2026 10:21:28 +0100 Subject: [PATCH] fix(sixel): let tmux place sixel images itself when it can tmux 3.4+ built with sixel renders sixel output from panes on its own, mapping it into the pane and keeping it in place across splits. Wrapping the image in passthrough instead sends it untouched to the outer terminal, where it is drawn at that terminal's cursor, not the pane-relative cursor position the backend just moved to: images land at the top-left of the whole window and stack on each other. When the attached client's termfeatures include sixel, the DCS sequence now goes straight to the pane; passthrough stays for tmux without native sixel. --- lua/image/backends/sixel.lua | 6 ++---- lua/image/utils/tmux.lua | 6 ++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/image/backends/sixel.lua b/lua/image/backends/sixel.lua index ac61f77..002b175 100644 --- a/lua/image/backends/sixel.lua +++ b/lua/image/backends/sixel.lua @@ -129,9 +129,7 @@ local send_sixel = function(sixel_data, x, y) if not has_st_end then wrapped_data = wrapped_data .. "\27\\" end -- tmux passthrough: wrap DCS sequence so tmux forwards it to the terminal - if utils.tmux.is_tmux then - wrapped_data = utils.tmux.escape(wrapped_data) - end + if utils.tmux.is_tmux and not utils.tmux.has_native_sixel then wrapped_data = utils.tmux.escape(wrapped_data) end -- build sequence local sequence = "" @@ -259,7 +257,7 @@ function backend.setup(state) end -- tmux check - if utils.tmux.is_tmux and not utils.tmux.has_passthrough then + if utils.tmux.is_tmux and not utils.tmux.has_native_sixel and not utils.tmux.has_passthrough then log.warn("tmux detected but passthrough may not be enabled for sixel") end diff --git a/lua/image/utils/tmux.lua b/lua/image/utils/tmux.lua index d0df7e9..156c608 100644 --- a/lua/image/utils/tmux.lua +++ b/lua/image/utils/tmux.lua @@ -4,9 +4,14 @@ local pane_position = nil local pane_position_clear_scheduled = false local has_passthrough = false +local has_native_sixel = false if is_tmux then local ok, result = pcall(vim.fn.system, { "tmux", "show", "-Apv", "allow-passthrough" }) if ok and (result:sub(-3) == "on\n" or result:sub(-4) == "all\n") then has_passthrough = true end + local features_ok, features = pcall(vim.fn.system, { "tmux", "display-message", "-p", "#{client_termfeatures}" }) + if features_ok and vim.v.shell_error == 0 then + has_native_sixel = ("," .. vim.trim(features) .. ","):find(",sixel,", 1, true) ~= nil + end end local create_dm_getter = function(name) @@ -91,6 +96,7 @@ end return { is_tmux = is_tmux, + has_native_sixel = has_native_sixel, has_passthrough = has_passthrough, get_pid = create_dm_getter("pid"), get_socket_path = create_dm_getter("socket_path"),