mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 03:15:39 +00:00
feat(terminal)!: include cursor position in TermRequest event data (#31609)
When a plugin registers a TermRequest handler there is currently no way for the handler to know where the terminal's cursor position was when the sequence was received. This is often useful information, e.g. for OSC 133 sequences which are used to annotate shell prompts. Modify the event data for the TermRequest autocommand to be a table instead of just a string. The "sequence" field of the table contains the sequence string and the "cursor" field contains the cursor position when the sequence was received. To maintain consistency between TermRequest and TermResponse (and to future proof the latter), TermResponse's event data is also updated to be a table with a "sequence" field. BREAKING CHANGE: event data for TermRequest and TermResponse is now a table
This commit is contained in:
@@ -373,7 +373,7 @@ describe(':terminal buffer', function()
|
||||
})
|
||||
vim.api.nvim_create_autocmd('TermRequest', {
|
||||
callback = function(args)
|
||||
if args.data == '\027]11;?' then
|
||||
if args.data.sequence == '\027]11;?' then
|
||||
table.insert(_G.input, '\027]11;rgb:0000/0000/0000\027\\')
|
||||
end
|
||||
end
|
||||
@@ -389,6 +389,42 @@ describe(':terminal buffer', function()
|
||||
}, exec_lua('return _G.input'))
|
||||
end)
|
||||
|
||||
it('TermRequest includes cursor position #31609', function()
|
||||
command('autocmd! nvim.terminal TermRequest')
|
||||
local screen = Screen.new(50, 10)
|
||||
local term = exec_lua([[
|
||||
_G.cursor = {}
|
||||
local term = vim.api.nvim_open_term(0, {})
|
||||
vim.api.nvim_create_autocmd('TermRequest', {
|
||||
callback = function(args)
|
||||
_G.cursor = args.data.cursor
|
||||
end
|
||||
})
|
||||
return term
|
||||
]])
|
||||
-- Enter terminal mode so that the cursor follows the output
|
||||
feed('a')
|
||||
|
||||
-- Put some lines into the scrollback. This tests the conversion from terminal line to buffer
|
||||
-- line.
|
||||
api.nvim_chan_send(term, string.rep('>\n', 20))
|
||||
screen:expect([[
|
||||
> |*8
|
||||
^ |
|
||||
{5:-- TERMINAL --} |
|
||||
]])
|
||||
|
||||
-- Emit an OSC escape sequence
|
||||
api.nvim_chan_send(term, 'Hello\nworld!\027]133;D\027\\')
|
||||
screen:expect([[
|
||||
> |*7
|
||||
Hello |
|
||||
world!^ |
|
||||
{5:-- TERMINAL --} |
|
||||
]])
|
||||
eq({ 22, 6 }, exec_lua('return _G.cursor'))
|
||||
end)
|
||||
|
||||
it('no heap-buffer-overflow when using jobstart("echo",{term=true}) #3161', function()
|
||||
local testfilename = 'Xtestfile-functional-terminal-buffers_spec'
|
||||
write_file(testfilename, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
||||
|
||||
Reference in New Issue
Block a user