Simplify osc52 code.
This commit is contained in:
parent
f5ec5806ed
commit
f59879acbe
@ -5,31 +5,19 @@ local M = {}
|
|||||||
local base64 = {}
|
local base64 = {}
|
||||||
local max_osc52_sequence = 100000
|
local max_osc52_sequence = 100000
|
||||||
|
|
||||||
function M.get_OSC52(str, tgt)
|
local function osc52_copy(str, tgt)
|
||||||
return "\x1b]52;" .. tgt .. ";" .. base64.encode(str) .. "\x07"
|
return "\x1b]52;" .. tgt .. ";" .. base64.encode(str) .. "\x07"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- This is for `tmux` sessions which filters OSC 52 locally.
|
local function tmux_wrap(cmd)
|
||||||
function M.get_OSC52_tmux(str, tgt)
|
return "\x1bPtmux;\x1b" .. cmd .. "\x1b\\"
|
||||||
return "\x1bPtmux;\x1b\x1b]52;" .. tgt .. ";" .. base64.encode(str) .. "\x07\x1b\\"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- base64s the entire source, wraps it in a single OSC52, and then
|
local function screen_wrap(cmd)
|
||||||
-- breaks the result in small chunks which are each wrapped in a DCS sequence.
|
|
||||||
--
|
|
||||||
-- This is appropriate when running on `screen`. Screen doesn't support OSC 52,
|
|
||||||
-- but will pass the contents of a DCS sequence to the outer terminal unmolested.
|
|
||||||
-- It imposes a small max length to DCS sequences, so we send in chunks.
|
|
||||||
function M.get_OSC52_DCS(str, tgt)
|
|
||||||
local b64 = base64.encode(str)
|
|
||||||
|
|
||||||
-- Insert <end-dcs><start-dcs> pair every 76 characters.
|
-- Insert <end-dcs><start-dcs> pair every 76 characters.
|
||||||
-- TODO: insert "\x1b\\\x1bP" every 76 characters
|
-- TODO: insert "\x1b\\\x1bP" every 76 characters
|
||||||
|
|
||||||
-- Now wrap the whole thing in <start-dcs><start-osc52>...<end-osc52><end-dcs>.
|
return "\x1bP" .. cmd .. "\x1b\x5c"
|
||||||
b64 = "\x1bP\x1b]52;" .. tgt .. ";" .. b64 .. "\x07\x1b\x5c"
|
|
||||||
|
|
||||||
return b64
|
|
||||||
end
|
end
|
||||||
|
|
||||||
M.terminal = vim.api.nvim_eval'$TERM'
|
M.terminal = vim.api.nvim_eval'$TERM'
|
||||||
@ -39,13 +27,11 @@ function M.copy(str, tgt)
|
|||||||
|
|
||||||
if #str > max_osc52_sequence then error'string to long to copy via OSC52' end
|
if #str > max_osc52_sequence then error'string to long to copy via OSC52' end
|
||||||
|
|
||||||
local osc52
|
local osc52 = osc52_copy(str, tgt)
|
||||||
if M.terminal:match'^tmux' ~= nil then
|
if M.terminal:match'^tmux' ~= nil then
|
||||||
osc52 = M.get_OSC52_tmux(str, tgt)
|
osc52 = tmux_wrap(osc52)
|
||||||
elseif M.terminal:match'^screen' ~= nil then
|
elseif M.terminal:match'^screen' ~= nil then
|
||||||
osc52 = M.get_OSC52_DCS(str, tgt)
|
osc52 = screen_wrap(osc52)
|
||||||
else
|
|
||||||
osc52 = M.get_OSC52(str, tgt)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
io.stdout:write(osc52)
|
io.stdout:write(osc52)
|
||||||
@ -64,8 +50,8 @@ function M.enable()
|
|||||||
\ '*': { lines, regtype -> v:lua.osc52_clipboard_handler(lines, regtype, '*') },
|
\ '*': { lines, regtype -> v:lua.osc52_clipboard_handler(lines, regtype, '*') },
|
||||||
\ },
|
\ },
|
||||||
\ 'paste': {
|
\ 'paste': {
|
||||||
\ '+': { -> '' },
|
\ '+': { -> [] },
|
||||||
\ '*': { -> '' },
|
\ '*': { -> [] },
|
||||||
\ },
|
\ },
|
||||||
\}
|
\}
|
||||||
]]
|
]]
|
||||||
|
2
vimrc
2
vimrc
@ -152,7 +152,7 @@ set backupcopy=yes
|
|||||||
|
|
||||||
se inccommand=nosplit
|
se inccommand=nosplit
|
||||||
|
|
||||||
set mouse=a
|
set mouse=nv
|
||||||
set title
|
set title
|
||||||
|
|
||||||
se scl=yes:1 " say no to wobbly side column
|
se scl=yes:1 " say no to wobbly side column
|
||||||
|
Loading…
Reference in New Issue
Block a user