fix(image): work around tmux extended-keys breaking TermResponse. Closes #2332

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 <noreply@anthropic.com>
This commit is contained in:
Folke Lemaitre 2025-10-24 06:58:22 +02:00
parent 277ba028b3
commit e93dcfdf39
No known key found for this signature in database
GPG key ID: 9B52594D560070AB

View file

@ -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", {