aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/tty.lua
diff options
context:
space:
mode:
authorBarrett Ruth <62671086+barrettruth@users.noreply.github.com>2026-06-24 09:40:36 -0500
committerGitHub <noreply@github.com>2026-06-24 10:40:36 -0400
commit8bf7fc810a1ed1cd401abd1b90741085923f78df (patch)
tree3706d7d342e26697d315fd1667e7f11217521816 /runtime/lua/vim/tty.lua
parent08a1228f8243415d199f4a6c3adce8dc1b36b551 (diff)
downloadrneovim-8bf7fc810a1ed1cd401abd1b90741085923f78df.tar.gz
rneovim-8bf7fc810a1ed1cd401abd1b90741085923f78df.tar.bz2
rneovim-8bf7fc810a1ed1cd401abd1b90741085923f78df.zip
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).
Diffstat (limited to 'runtime/lua/vim/tty.lua')
-rw-r--r--runtime/lua/vim/tty.lua20
1 files changed, 18 insertions, 2 deletions
diff --git a/runtime/lua/vim/tty.lua b/runtime/lua/vim/tty.lua
index 06b8eddcec..73de366bc1 100644
--- a/runtime/lua/vim/tty.lua
+++ b/runtime/lua/vim/tty.lua
@@ -80,13 +80,23 @@ end
--- emulator supports the XTGETTCAP sequence.
---
--- @param caps string|table A terminal capability or list of capabilities to query
+--- @param opts? { timeout?: integer, on_timeout?: fun(), group?: integer|string, chan?: integer }
--- @param on_response fun(cap:string, found:boolean, seq:string?) Called for each capability in
--- `caps`. `found` is true if the capability was found, else false. `seq` is the control
--- sequence if found, or nil for boolean capabilities.
-function M.query(caps, on_response)
+---@overload fun(caps:string|table, on_response:fun(cap:string, found:boolean, seq:string?))
+function M.query(caps, opts, on_response)
+ if type(opts) == 'function' then
+ on_response = opts
+ opts = {}
+ end
+
vim.validate('caps', caps, { 'string', 'table' })
+ vim.validate('opts', opts, 'table', true)
vim.validate('on_response', on_response, 'function')
+ opts = opts or {}
+
if type(caps) ~= 'table' then
caps = { caps }
end
@@ -103,11 +113,17 @@ function M.query(caps, on_response)
local payload = ('\027P+q%s\027\\'):format(table.concat(encoded, ';'))
M.request(payload, {
+ timeout = opts.timeout,
+ group = opts.group,
+ chan = opts.chan,
on_timeout = function()
-- Call the callback for all capabilities that were not found.
for k in pairs(pending) do
on_response(k, false, nil)
end
+ if opts.on_timeout then
+ opts.on_timeout()
+ end
end,
}, function(resp)
local k, rest = resp:match('^\027P1%+r(%x+)(.*)$')
@@ -144,7 +160,7 @@ end
--- Return `true` from `on_response` to stop listening.
---
---@param payload string APC sequence to send (full escape sequence including prefix/suffix)
----@param opts {timeout?:integer} Options table (timeout in milliseconds, default 1000)
+---@param opts {timeout?:integer, chan?:integer} Options table (timeout in milliseconds, default 1000)
---@param on_response fun(resp:string):boolean? Callback invoked for each APC TermResponse
---@overload fun(payload:string, on_response:fun(resp:string):boolean?)
function M.query_apc(payload, opts, on_response)