aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2023-11-07 08:47:27 -0600
committerGitHub <noreply@github.com>2023-11-07 08:47:27 -0600
commitcd31a72f9b22741c6ece1c47a91d990e2df218fa (patch)
tree3ace882e09a99a03b3eb91f74de9917c84c6f4ba /runtime/lua/vim
parent3ca967387c49c754561c3b11a574797504d40f38 (diff)
parenta14c7809181c11f859dd8560dd65d366411a08bc (diff)
downloadrneovim-cd31a72f9b22741c6ece1c47a91d990e2df218fa.tar.gz
rneovim-cd31a72f9b22741c6ece1c47a91d990e2df218fa.tar.bz2
rneovim-cd31a72f9b22741c6ece1c47a91d990e2df218fa.zip
Merge pull request #25872 from gpanders/osc52
feat(clipboard): add OSC 52 clipboard support
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/clipboard/osc52.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/runtime/lua/vim/clipboard/osc52.lua b/runtime/lua/vim/clipboard/osc52.lua
new file mode 100644
index 0000000000..0e8f9d378f
--- /dev/null
+++ b/runtime/lua/vim/clipboard/osc52.lua
@@ -0,0 +1,38 @@
+local M = {}
+
+function M.copy(lines)
+ local s = table.concat(lines, '\n')
+ io.stdout:write(string.format('\x1b]52;;%s\x1b\\', vim.base64.encode(s)))
+end
+
+function M.paste()
+ local contents = nil
+ local id = vim.api.nvim_create_autocmd('TermResponse', {
+ callback = function(args)
+ local resp = args.data ---@type string
+ local encoded = resp:match('\x1b%]52;%w?;([A-Za-z0-9+/=]*)')
+ if encoded then
+ contents = vim.base64.decode(encoded)
+ return true
+ end
+ end,
+ })
+
+ io.stdout:write('\x1b]52;;?\x1b\\')
+
+ 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 contents then
+ return vim.split(contents, '\n')
+ end
+
+ vim.notify('Timed out waiting for a clipboard response from the terminal', vim.log.levels.WARN)
+ return 0
+end
+
+return M