fix(termcap): use tmux passthrough sequence when running in tmux (#26281)

tmux intercepts and ignores XTGETTCAP so wrap the query in the tmux
passthrough sequence to make sure the query arrives at the "host"
terminal.

Users must still set the 'allow-passthrough' option in their tmux.conf.
This commit is contained in:
Gregory Anders 2023-11-28 16:34:18 -06:00 committed by GitHub
parent 79b6ff28ad
commit b7831c7f99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,10 +34,6 @@ function M.query(caps, cb)
local seq = local seq =
vim.text.hexdecode(v):gsub('\\E', '\027'):gsub('%%p%d', ''):gsub('\\(%d+)', string.char) vim.text.hexdecode(v):gsub('\\E', '\027'):gsub('%%p%d', ''):gsub('\\(%d+)', string.char)
-- TODO: When libtermkey is patched to accept BEL as an OSC terminator, this workaround can
-- be removed
seq = seq:gsub('\007$', '\027\\')
cb(cap, seq) cb(cap, seq)
count = count - 1 count = count - 1
@ -54,6 +50,12 @@ function M.query(caps, cb)
end end
local query = string.format('\027P+q%s\027\\', table.concat(encoded, ';')) local query = string.format('\027P+q%s\027\\', table.concat(encoded, ';'))
-- If running in tmux, wrap with the passthrough sequence
if os.getenv('TMUX') then
query = string.format('\027Ptmux;\027%s\027\\', query)
end
io.stdout:write(query) io.stdout:write(query)
end end