From 531b2f8a4b06411d303467be3698872995aa620e Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Mon, 7 Mar 2022 17:38:20 +0600 Subject: [PATCH] fix: transitional hl throwing errors for nil fg/bg in colors fixes #600 --- lua/lualine/highlight.lua | 6 +++--- lua/lualine/utils/color_utils.lua | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lua/lualine/highlight.lua b/lua/lualine/highlight.lua index b046762..7072857 100644 --- a/lua/lualine/highlight.lua +++ b/lua/lualine/highlight.lua @@ -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 diff --git a/lua/lualine/utils/color_utils.lua b/lua/lualine/utils/color_utils.lua index 8c8a184..b44e407 100644 --- a/lua/lualine/utils/color_utils.lua +++ b/lua/lualine/utils/color_utils.lua @@ -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