fix: transitional hl throwing errors for nil fg/bg in colors

fixes #600
This commit is contained in:
shadmansaleh 2022-03-07 17:38:20 +06:00
parent d2e0ac595b
commit 531b2f8a4b
2 changed files with 6 additions and 3 deletions

View File

@ -76,8 +76,8 @@ function M.get_lualine_hl(name)
return modules.utils.extract_highlight_colors(hl.link)
end
local hl_def = {
fg = hl.fg ~= 'None' and vim.deepcopy(hl.fg),
bg = hl.bg ~= 'None' and vim.deepcopy(hl.bg),
fg = hl.fg ~= 'None' and vim.deepcopy(hl.fg) or nil,
bg = hl.bg ~= 'None' and vim.deepcopy(hl.bg) or nil,
}
if hl.gui then
for _, flag in ipairs(vim.split(hl.gui, ',')) do
@ -456,7 +456,7 @@ function M.get_transitional_highlights(left_hl, right_hl)
if bg == fg then
return nil -- Separator won't be visible anyway
end
M.highlight(highlight_name, fg, bg, nil)
M.highlight(highlight_name, fg, bg, nil, nil)
attach_hl(left_hl, highlight_name, 'bg', 'fg')
attach_hl(right_hl, highlight_name, 'bg', 'bg')
end

View File

@ -278,6 +278,9 @@ local color_table = {
---@param hex_color string
---@return string
function M.rgb2cterm(hex_color)
if hex_color == 'None' then
return 'None'
end
local function get_color_distance(color1, color2)
-- returns how much color2 deviates from color1
local dr = math.abs(color1[1] - color2[1]) / (color1[1] + 1) * 100