diff --git a/lua/lualine/highlight.lua b/lua/lualine/highlight.lua index ab5ffb3..0966279 100644 --- a/lua/lualine/highlight.lua +++ b/lua/lualine/highlight.lua @@ -5,7 +5,7 @@ local lualine_require = require'lualine_require' local require = lualine_require.require local modules = lualine_require.lazy_require{ utils = 'lualine.utils.utils', - color_utils = 'lualine.utils.cterm_colors', + color_utils = 'lualine.utils.color_utils', } local section_highlight_map = {x = 'c', y = 'b', z = 'a'} local active_theme = nil @@ -35,14 +35,14 @@ function M.highlight(name, foreground, background, gui, link, reload) table.insert(command, 'guifg=' .. foreground) if create_cterm_colors then table.insert(command, - 'ctermfg=' .. modules.color_utils.get_cterm_color(foreground)) + 'ctermfg=' .. modules.color_utils.rgb2cterm(foreground)) end end if background and background ~= 'none' then table.insert(command, 'guibg=' .. background) if create_cterm_colors then table.insert(command, - 'ctermbg=' .. modules.color_utils.get_cterm_color(background)) + 'ctermbg=' .. modules.color_utils.rgb2cterm(background)) end end if gui then @@ -59,9 +59,7 @@ end function M.create_highlight_groups(theme) modules.utils.clear_highlights() active_theme = theme - if not vim.go.termguicolors then - create_cterm_colors = true - end + create_cterm_colors = not vim.go.termguicolors for mode, sections in pairs(theme) do for section, color in pairs(sections) do local highlight_group_name = {'lualine', section, mode} diff --git a/lua/lualine/utils/cterm_colors.lua b/lua/lualine/utils/color_utils.lua similarity index 99% rename from lua/lualine/utils/cterm_colors.lua rename to lua/lualine/utils/color_utils.lua index 5648b17..5541602 100644 --- a/lua/lualine/utils/cterm_colors.lua +++ b/lua/lualine/utils/color_utils.lua @@ -274,7 +274,7 @@ local color_table = { } -- LuaFormatter on -function M.get_cterm_color(hex_color) +function M.rgb2cterm(hex_color) 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 diff --git a/lua/tests/spec/utils_spec.lua b/lua/tests/spec/utils_spec.lua index b7a34f8..0e90f84 100644 --- a/lua/tests/spec/utils_spec.lua +++ b/lua/tests/spec/utils_spec.lua @@ -58,12 +58,12 @@ describe('Utils', function() end) describe('Cterm genarator', function() - local cterm = require 'lualine.utils.cterm_colors' + local cterm = require 'lualine.utils.color_utils' it('can convert rgb to cterm', function() local colors = {['#112233'] = 235, ['#7928ae'] = 97, ['#017bdc'] = 68} for rgb, ct in pairs(colors) do - eq(cterm.get_cterm_color(rgb), tostring(ct)) + eq(cterm.rgb2cterm(rgb), tostring(ct)) end end) end)