From 3dbe74f2eef627e2dc19b79fe06753d5dc09003f Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Wed, 15 May 2024 09:00:31 +0200 Subject: update nvim MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Robert Günzler --- .vim/lua/internal/syncbg.lua | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .vim/lua/internal/syncbg.lua (limited to '.vim/lua/internal/syncbg.lua') diff --git a/.vim/lua/internal/syncbg.lua b/.vim/lua/internal/syncbg.lua new file mode 100644 index 0000000..418e17e --- /dev/null +++ b/.vim/lua/internal/syncbg.lua @@ -0,0 +1,46 @@ +local M = {} + +M.init = function() + -- get tty + local tty_handle = io.popen('tty') + if tty_handle == nil then return end + local tty = tty_handle:read('*a') + tty_handle:close() + if tty:find("not a tty") then error('not a tty') end + + M.tty = tty +end + +M.update = function() + if M.tty == nil then return end + + if not M.normal then + -- get colorscheme Normal highlight + local normal = vim.api.nvim_get_hl(0, { name = 'Normal', create = false }) + if (normal.bg == nil) then return end + -- cache old value for use with VimResume + M.normal = normal + end + + -- emit CSI to change terminal background to Normal.bg + os.execute('printf "\\033]11;' .. string.format('#%06x', M.normal.bg) .. '\\007" > ' .. M.tty) + + -- set colorscheme Normal.bg to NONE, making it transparent + vim.cmd [[hi Normal ctermbg=NONE guibg=NONE]] +end + +M.reset = function() + if M.tty == nil then return end + + os.execute('printf "\\033]111\\007" > ' .. M.tty) +end + +M.setup = function(opts) + opts = opts or {} + + M.init() + vim.api.nvim_create_autocmd({ 'ColorScheme', 'UIEnter', 'VimResume' }, { callback = M.update }) + vim.api.nvim_create_autocmd({ 'UILeave' }, { callback = M.reset }) +end + +return M -- cgit 1.4.1