@@ -292,15 +292,27 @@ M.get_outer_layout_config = function()
292292 }
293293end
294294
295+ --- Return the highlight definition map. Use a light background color (the foreground color of Normal
296+ --- highlight) when vim.o.background and the `color` are dark.
297+ --- @param color string
298+ --- @return vim.api.keyset.highlight
299+ local function label_hl (color )
300+ local r , g , b = color :match (" %#(%x%x)(%x%x)(%x%x)" )
301+ local luminance = (0.299 * tonumber (r , 16 ) + 0.587 * tonumber (g , 16 ) + 0.114 * tonumber (b , 16 )) / 255
302+ local normal = vim .api .nvim_get_hl (0 , { name = " Normal" , link = false })
303+ local normal_fg = normal .fg and string.format (" #%06x" , normal .fg ) or " #ffffff"
304+ local bg = (vim .o .background == " dark" and luminance < 0.5 ) and normal_fg or nil
305+ return { fg = color , bg = bg }
306+ end
307+
295308M .color_details = function (bufnr )
296309 local details_namespace = vim .api .nvim_create_namespace (" Details" )
297310 for i , line in ipairs (vim .api .nvim_buf_get_lines (bufnr , 0 , - 1 , false )) do
298311 if line :match (" ^* Labels" ) then
299312 for j , label in ipairs (state .LABELS ) do
300313 local start_idx , end_idx = line :find (label .Name , 1 , true )
301314 if start_idx ~= nil and end_idx ~= nil then
302- vim .cmd (" highlight " .. " label" .. j .. " guifg=white" )
303- vim .api .nvim_set_hl (0 , (" label" .. j ), { fg = label .Color })
315+ vim .api .nvim_set_hl (0 , (" label" .. j ), label_hl (label .Color ))
304316 vim .hl .range (bufnr , details_namespace , (" label" .. j ), { i - 1 , start_idx - 1 }, { i - 1 , end_idx })
305317 end
306318 end
0 commit comments