From e93dcfdf394ef16732f06021d941146be912043c Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 24 Oct 2025 06:58:22 +0200 Subject: [PATCH] fix(image): work around tmux extended-keys breaking TermResponse. Closes #2332 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When tmux has extended-keys enabled, Neovim's TermResponse autocmd doesn't fire, causing terminal response sequences to leak as literal text into buffers. Workaround: Detect this configuration and query tmux directly for the terminal name using `tmux display-message -p "#{client_termname}"` instead of sending escape sequences. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- lua/snacks/image/terminal.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lua/snacks/image/terminal.lua b/lua/snacks/image/terminal.lua index 3787e8cd..48be08a4 100644 --- a/lua/snacks/image/terminal.lua +++ b/lua/snacks/image/terminal.lua @@ -230,6 +230,18 @@ function M.detect(cb) M.transform = function(data) return ("\027Ptmux;" .. data:gsub("\027", "\027\027")) .. "\027\\" end + -- NOTE: When tmux has extended-keys enabled, Neovim's TermResponse autocmd doesn't fire. + -- Terminal response sequences leak as literal text instead of being captured. + -- Workaround: Query tmux directly for the terminal name instead of sending escape sequences. + -- See: https://github.com/folke/snacks.nvim/issues/2332 + local ok, out = pcall(vim.fn.system, { "tmux", "show", "-g", "extended-keys" }) + if ok and vim.trim(out):find(" on$") then + ok, out = pcall(vim.fn.system, { "tmux", "display-message", "-p", "#{client_termname}" }) + if ok then + ret.terminal = vim.trim(out):gsub("^xterm%-", "") + return vim.schedule(on_done) + end + end end local id = vim.api.nvim_create_autocmd("TermResponse", {