From 3128cff6b198daabfddeedd382c0b8707319504f Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Wed, 8 Nov 2023 12:42:47 -0600 Subject: fix(clipboard): increase OSC 52 wait timeout (#25936) When pasting with OSC 52 some terminals show a prompt to the user asking for permission to read from the system clipboard. When this prompt appears, 1s is not long enough to wait. Increase the timeout to 10s and show a message to the user indicating how to interrupt the wait after 1s. --- runtime/lua/vim/clipboard/osc52.lua | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'runtime/lua') diff --git a/runtime/lua/vim/clipboard/osc52.lua b/runtime/lua/vim/clipboard/osc52.lua index 0e8f9d378f..78f5754c30 100644 --- a/runtime/lua/vim/clipboard/osc52.lua +++ b/runtime/lua/vim/clipboard/osc52.lua @@ -20,19 +20,41 @@ function M.paste() io.stdout:write('\x1b]52;;?\x1b\\') - vim.wait(1000, function() + local ok, res + + -- Wait 1s first for terminals that respond quickly + ok, res = vim.wait(1000, function() return contents ~= nil end) - -- Delete the autocommand if it didn't already delete itself - pcall(vim.api.nvim_del_autocmd, id) + if res == -1 then + -- If no response was received after 1s, print a message and keep waiting + vim.api.nvim_echo( + { { 'Waiting for OSC 52 response from the terminal. Press Ctrl-C to interrupt...' } }, + false, + {} + ) + ok, res = vim.wait(9000, function() + return contents ~= nil + end) + end - if contents then - return vim.split(contents, '\n') + if not ok then + vim.api.nvim_del_autocmd(id) + if res == -1 then + vim.notify( + 'Timed out waiting for a clipboard response from the terminal', + vim.log.levels.WARN + ) + elseif res == -2 then + -- Clear message area + vim.api.nvim_echo({ { '' } }, false, {}) + end + return 0 end - vim.notify('Timed out waiting for a clipboard response from the terminal', vim.log.levels.WARN) - return 0 + -- If we get here, contents should be non-nil + return vim.split(assert(contents), '\n') end return M -- cgit