From 57ee7bb2fd1b9724c25cca7d4cc202b6014708a0 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Wed, 28 Feb 2024 23:21:58 +0100 Subject: [PATCH] Implement vim background color propagation for wezterm Currently unsupported: resetting after quitting TODO: Extract into separate Lua script (as well as kitty equivalent) --- vim/plugin/colors.vim | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/vim/plugin/colors.vim b/vim/plugin/colors.vim index 306833d..2159a58 100644 --- a/vim/plugin/colors.vim +++ b/vim/plugin/colors.vim @@ -1,8 +1,14 @@ let g:only_generic_hl=1 -function! s:kitty_bg_color() +function! s:wez_color(value) + let g:__color = a:value + lua vim.g.__color = vim.base64.encode(vim.g.__color) + call chansend(v:stderr, "\x1b]1337;SetUserVar=bgcolor=".g:__color."\x07") +endfun + +function! s:term_bg_color() + let l:num_color=synIDattr(hlID("normal"), "bg") if $TERM=="xterm-kitty" || $KITTY_LISTEN_ON != "" - let l:num_color=synIDattr(hlID("normal"), "bg") if l:num_color!="" if match(l:num_color, "^\\d\\{3}$")==0 let l:color=system("kitty @ --to $KITTY_LISTEN_ON get-colors | grep 'color".l:num_color."'") @@ -13,27 +19,30 @@ function! s:kitty_bg_color() call jobstart('kitty @ --to $KITTY_LISTEN_ON set-colors background="'.l:color.'"') call jobstart("cat ".$HOME."/darkrc/kitty_".&bg.".conf | grep cursor | sed -e 's/ /=/' | xargs -L 1 kitty @ --to $KITTY_LISTEN_ON set-colors") end + elseif $TERM_PROGRAM=="WezTerm" + call wez_color(l:num_color) end endfun -augroup kitty - au ColorScheme * call kitty_bg_color() +augroup termcolors + au ColorScheme * call term_bg_color() augroup END -function! s:kitty_bg_color_reset() - if filereadable($HOME."/.dark") - let l:file = $HOME."/darkrc/kitty_dark.conf" - else - let l:file = $HOME."/darkrc/kitty_light.conf" +function! s:term_bg_color_reset() + if $TERM=="xterm-kitty" || $KITTY_LISTEN_ON != "" + if filereadable($HOME."/.dark") + let l:file = $HOME."/darkrc/kitty_dark.conf" + else + let l:file = $HOME."/darkrc/kitty_light.conf" + end + call system("kitty @ --to ".$KITTY_LISTEN_ON." set-colors ".l:file) + elseif $TERM_PROGRAM=="WezTerm" end - call system("kitty @ --to ".$KITTY_LISTEN_ON." set-colors ".l:file) endfun -if $TERM=="xterm-kitty" || $KITTY_LISTEN_ON != "" - augroup kitty - au VimLeavePre * call kitty_bg_color_reset() - augroup END -end +augroup termcolors + au VimLeavePre * call term_bg_color_reset() +augroup END com! Dark silent! let g:colors_name_bak = g:colors_name \ | let g:ayucolor="dark"