fix(tty): filter terminal probes by channel #40356

Problem:
Terminal probes sent with `nvim_ui_send()` can reach more than one stdout TTY
UI. Probes with a known TTY UI owner should not accept `TermResponse`s from
unrelated UI channels. 

Solution:
Thread the existing `chan` filter through owned terminal probes. This covers
startup/attach background detection, fallback truecolor detection, and
`vim.tty.query()` forwarding opts to `vim.tty.request()`.

Note: Not every terminal escape path is updated here. I only passed `chan` when
the caller already knows which TTY UI owns the probe. For example, this does
not include:
- (Followup) OSC 52 (system clipboard) detection. It needs to capture the
  `UIEnter` channel. Adding `{ chan = ... }` only to the nested query would be
  half a fix.
- OSC 52 _paste_ is left global because the provider callback does not have
  a UI channel (paste is invoked without a ui channel/tty ui object).
This commit is contained in:
Barrett Ruth
2026-06-24 09:40:36 -05:00
committed by GitHub
parent 08a1228f82
commit 8bf7fc810a
4 changed files with 37 additions and 16 deletions

View File

@@ -137,7 +137,7 @@ end
--- Query whether the host terminal supports displaying images.
--- Blocks until the terminal responds or times out.
---
---@param opts? {timeout?: integer} timeout in milliseconds (default: 1000)
---@param opts? {timeout?: integer, chan?: integer} timeout in milliseconds (default: 1000)
---@return boolean supported true if the terminal supports image display
---@return string? msg error detail if the terminal responded but not with OK
function M._supported(opts)

View File

@@ -160,11 +160,12 @@ end
--- Query whether this terminal supports the kitty graphics protocol.
--- Blocks until the terminal responds or times out.
---
---@param opts? {timeout?: integer} timeout in milliseconds (default: 1000)
---@param opts? {timeout?: integer, chan?: integer} timeout in milliseconds (default: 1000)
---@return boolean supported
---@return string? msg error detail if terminal responded but not with OK
function M.supported(opts)
local timeout = opts and opts.timeout or 1000
opts = opts or {}
local timeout = opts.timeout or 1000
-- Do not use APC on terminals that echo unknown sequences
if vim.env.TERM_PROGRAM == 'Apple_Terminal' then
@@ -180,7 +181,7 @@ function M.supported(opts)
vim.tty.query_apc(
seq({ a = 'q', i = query_id, s = 1, v = 1 }),
{ timeout = timeout },
{ timeout = timeout, chan = opts.chan },
function(resp)
-- kitty APC response: \027_G[<fields>,]i=<id>[,<fields>];<status>
-- status is "OK" or an error code+message like "ENODATA:Missing image data"