aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua')
-rw-r--r--runtime/lua/vim/_editor.lua2
-rw-r--r--runtime/lua/vim/_meta/api.lua11
-rw-r--r--runtime/lua/vim/clipboard/osc52.lua38
3 files changed, 50 insertions, 1 deletions
diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua
index 0da127b18f..0bdf0c90a5 100644
--- a/runtime/lua/vim/_editor.lua
+++ b/runtime/lua/vim/_editor.lua
@@ -650,7 +650,7 @@ local on_key_cbs = {}
---if on_key() is called without arguments.
function vim.on_key(fn, ns_id)
if fn == nil and ns_id == nil then
- return #on_key_cbs
+ return vim.tbl_count(on_key_cbs)
end
vim.validate({
diff --git a/runtime/lua/vim/_meta/api.lua b/runtime/lua/vim/_meta/api.lua
index 6c6e11a0d3..2142a429a2 100644
--- a/runtime/lua/vim/_meta/api.lua
+++ b/runtime/lua/vim/_meta/api.lua
@@ -2065,6 +2065,17 @@ function vim.api.nvim_ui_set_focus(gained) end
--- @param value any
function vim.api.nvim_ui_set_option(name, value) end
+--- Tells Nvim when a terminal event has occurred.
+--- The following terminal events are supported:
+---
+--- • "osc_response": The terminal sent a OSC response sequence to Nvim. The
+--- payload is the received OSC sequence.
+---
+---
+--- @param event string Event name
+--- @param value any
+function vim.api.nvim_ui_term_event(event, value) end
+
--- @param width integer
--- @param height integer
function vim.api.nvim_ui_try_resize(width, height) end
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