11local M = {}
22M .ping_anwsered = 0
3- M .custom_highlight = false
43M .info_floatwin = {}
54
65-- See https://github.com/tjdevries/rofl.nvim/blob/632c10f2ec7c56882a3f7eda8849904bcac6e8af/lua/rofl.lua
@@ -54,10 +53,10 @@ M.config_values = {
5453
5554 -- default highlight stuff goes here
5655 snipruncolors = {
57- SniprunVirtualTextOk = { bg = " #66eeff" ,fg = " #000000" ,ctermbg = " Cyan" ,ctermfg = " Black" },
58- SniprunFloatingWinOk = { fg = " #66eeff" ,ctermfg = " Cyan" },
59- SniprunVirtualTextErr = { bg = " #881515" ,fg = " #000000" ,ctermbg = " DarkRed" ,ctermfg = " Black" },
60- SniprunFloatingWinErr = { fg = " #881515" ,ctermfg = " DarkRed" },
56+ SniprunVirtualTextOk = { default = true , bg = " #66eeff" , fg = " #000000" , ctermbg = " Cyan" , ctermfg = " Black" },
57+ SniprunFloatingWinOk = { default = true , fg = " #66eeff" , ctermfg = " Cyan" },
58+ SniprunVirtualTextErr = { default = true , bg = " #881515" , fg = " #000000" , ctermbg = " DarkRed" , ctermfg = " Black" },
59+ SniprunFloatingWinErr = { default = true , fg = " #881515" , ctermfg = " DarkRed" },
6160 },
6261
6362 -- whether the user can toggle the live_mode. It's kept as an option so it's not activated by chance
@@ -92,14 +91,14 @@ function M.setup(opts)
9291 error (string.format (' [Sniprun] Key %s does not exist in config values' ,key ))
9392 return
9493 end
95- if key == ' snipruncolors' then
96- M .custom_highlight = true
97- end
9894 if key == ' live_mode_toggle' and opts [key ] == ' enable' then
9995 require (' sniprun.live_mode' )
10096 end
10197 end
10298
99+ -- Replace default highlights with custom ones rather than merging them together.
100+ M .config_values .snipruncolors = vim .tbl_extend (" force" , M .config_values .snipruncolors , opts .snipruncolors or {})
101+
103102 -- merge user config into default config values
104103 M .config_values = vim .tbl_deep_extend (" force" , M .config_values , opts )
105104
@@ -115,16 +114,15 @@ end
115114
116115
117116local highlight = function (group , styles )
118- local gui = styles .gui and ' gui=' .. styles .gui or ' gui=NONE'
119- local sp = styles .sp and ' guisp=' .. styles .sp or ' guisp=NONE'
120- local fg = styles .fg and ' guifg=' .. styles .fg or ' guifg=NONE'
121- local bg = styles .bg and ' guibg=' .. styles .bg or ' guibg=NONE'
122- local ctermbg = styles .ctermbg and ' ctermbg=' .. styles .ctermbg or ' ctermbg=NONE'
123- local ctermfg = styles .ctermfg and ' ctermfg=' .. styles .ctermfg or ' ctermfg=NONE'
124- -- This somehow works for default highlighting. with or even without cterm colors
125- -- hacky way tho.Still I think better than !hlexists
126- vim .cmd (' highlight ' .. group .. ' ' .. gui .. ' ' .. sp .. ' ' .. fg .. ' ' .. bg .. ' ' .. ctermbg .. ' ' .. ctermfg )
127- vim .api .nvim_command (' autocmd ColorScheme * highlight ' .. group .. ' ' .. gui .. ' ' .. sp .. ' ' .. fg .. ' ' .. bg .. ' ' .. ctermbg .. ' ' .. ctermfg )
117+ -- Maintain compatibility with the previous way of setting highlights.
118+ local attrs = {}
119+ if styles .gui then
120+ for val in vim .gsplit (styles .gui , " ," , { plain = true }) do
121+ attrs [val ] = true
122+ end
123+ end
124+
125+ vim .api .nvim_set_hl (0 , group , vim .tbl_extend (" force" , attrs , styles ))
128126end
129127
130128
135133
136134
137135function M .setup_highlights ()
138- local colors_table = M .config_values [" snipruncolors" ]
139- if M .custom_highlight then
140- vim .cmd (' augroup snip_highlights' )
141- vim .cmd (' autocmd!' )
142- for group , styles in pairs (colors_table ) do
143- -- print('setting up for '..group,'with style :','bg :',styles.bg,'fg :',styles.fg)
144- highlight (group , styles )
145- end
146- vim .cmd (' augroup END' )
147- else
148- for group , styles in pairs (colors_table ) do
149- local gui = styles .gui and ' gui=' .. styles .gui or ' gui=NONE'
150- local sp = styles .sp and ' guisp=' .. styles .sp or ' guisp=NONE'
151- local fg = styles .fg and ' guifg=' .. styles .fg or ' guifg=NONE'
152- local bg = styles .bg and ' guibg=' .. styles .bg or ' guibg=NONE'
153- local ctermbg = styles .ctermbg and ' ctermbg=' .. styles .ctermbg or ' ctermbg=NONE'
154- local ctermfg = styles .ctermfg and ' ctermfg=' .. styles .ctermfg or ' ctermfg=NONE'
155-
156- vim .cmd (" if !hlexists('" .. group .. " ') \n hi " .. group .. " " .. gui .. " " .. sp .. " " .. fg .. " " .. bg .. " " .. ctermbg .. " " .. ctermfg )
157- end
136+ local snipruncolors = M .config_values .snipruncolors
137+ for group , styles in pairs (snipruncolors ) do
138+ highlight (group , styles )
158139 end
159140end
160141
208189function M .start ()
209190 if M .job_id ~= nil then return end
210191 M .job_id = vim .fn .jobstart ({ M .config_values .binary_path }, { rpc = true })
192+ M .setup_highlights () -- some configurations break highlights (lunarvim/lazy for example)
211193end
212194
213195function M .notify (method , ...)
0 commit comments