aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/lua/vim/clipboard/osc52.lua36
1 files changed, 29 insertions, 7 deletions
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