From f59879acbe2bff0f0366559ae17d07c4b563f075 Mon Sep 17 00:00:00 2001 From: Gabriel Ebner Date: Sun, 31 Oct 2021 11:38:30 +0100 Subject: [PATCH] Simplify osc52 code. --- config/nvim/lua/osc52.lua | 34 ++++++++++------------------------ vimrc | 2 +- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/config/nvim/lua/osc52.lua b/config/nvim/lua/osc52.lua index ccd26ed..90dd135 100644 --- a/config/nvim/lua/osc52.lua +++ b/config/nvim/lua/osc52.lua @@ -5,31 +5,19 @@ local M = {} local base64 = {} 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" end --- This is for `tmux` sessions which filters OSC 52 locally. -function M.get_OSC52_tmux(str, tgt) - return "\x1bPtmux;\x1b\x1b]52;" .. tgt .. ";" .. base64.encode(str) .. "\x07\x1b\\" +local function tmux_wrap(cmd) + return "\x1bPtmux;\x1b" .. cmd .. "\x1b\\" end --- base64s the entire source, wraps it in a single OSC52, and then --- 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) - +local function screen_wrap(cmd) -- Insert pair every 76 characters. -- TODO: insert "\x1b\\\x1bP" every 76 characters - -- Now wrap the whole thing in .... - b64 = "\x1bP\x1b]52;" .. tgt .. ";" .. b64 .. "\x07\x1b\x5c" - - return b64 + return "\x1bP" .. cmd .. "\x1b\x5c" end 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 - local osc52 + local osc52 = osc52_copy(str, tgt) 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 - osc52 = M.get_OSC52_DCS(str, tgt) - else - osc52 = M.get_OSC52(str, tgt) + osc52 = screen_wrap(osc52) end io.stdout:write(osc52) @@ -64,8 +50,8 @@ function M.enable() \ '*': { lines, regtype -> v:lua.osc52_clipboard_handler(lines, regtype, '*') }, \ }, \ 'paste': { - \ '+': { -> '' }, - \ '*': { -> '' }, + \ '+': { -> [] }, + \ '*': { -> [] }, \ }, \} ]] diff --git a/vimrc b/vimrc index 6812064..e834df7 100644 --- a/vimrc +++ b/vimrc @@ -152,7 +152,7 @@ set backupcopy=yes se inccommand=nosplit -set mouse=a +set mouse=nv set title se scl=yes:1 " say no to wobbly side column