feat(tui): add nvim_ui_send (#35406)

This function allows the Nvim core to write arbitrary data to a TTY
connected to a UI's stdout.
This commit is contained in:
Gregory Anders
2025-08-22 15:05:43 -05:00
committed by GitHub
parent 5d8e870c11
commit 586b1b2d9b
16 changed files with 161 additions and 13 deletions

View File

@@ -10,7 +10,9 @@ local exec = n.exec
local feed = n.feed
local api = n.api
local request = n.request
local poke_eventloop = n.poke_eventloop
local pcall_err = t.pcall_err
local uv = vim.uv
describe('nvim_ui_attach()', function()
before_each(function()
@@ -71,6 +73,72 @@ describe('nvim_ui_attach()', function()
end)
end)
describe('nvim_ui_send', function()
before_each(function()
clear()
end)
it('works with stdout_tty', function()
local fds = assert(uv.pipe())
local read_pipe = assert(uv.new_pipe())
read_pipe:open(fds.read)
local read_data = {}
read_pipe:read_start(function(err, data)
assert(not err, err)
if data then
table.insert(read_data, data)
end
end)
local screen = Screen.new(50, 10, { stdout_tty = true })
screen:set_stdout(fds.write)
api.nvim_ui_send('Hello world')
poke_eventloop()
screen:expect([[
^ |
{1:~ }|*8
|
]])
eq('Hello world', table.concat(read_data))
end)
it('ignores ui_send event for UIs without stdout_tty', function()
local fds = assert(uv.pipe())
local read_pipe = assert(uv.new_pipe())
read_pipe:open(fds.read)
local read_data = {}
read_pipe:read_start(function(err, data)
assert(not err, err)
if data then
table.insert(read_data, data)
end
end)
local screen = Screen.new(50, 10)
screen:set_stdout(fds.write)
api.nvim_ui_send('Hello world')
poke_eventloop()
screen:expect([[
^ |
{1:~ }|*8
|
]])
eq('', table.concat(read_data))
end)
end)
it('autocmds UIEnter/UILeave', function()
clear { args_rm = { '--headless' } }
exec([[