Enhance: Cterm colors only loaded when termguicolors = false

This commit is contained in:
shadmansaleh 2021-04-08 08:43:06 +06:00
parent 67d0989051
commit 82f68c42df
1 changed files with 8 additions and 2 deletions

View File

@ -5,16 +5,21 @@ local utils_colors = require 'lualine.utils.cterm_colors'
local utils = require 'lualine.utils.utils' local utils = require 'lualine.utils.utils'
local section_highlight_map = {x = 'c', y = 'b', z = 'a'} local section_highlight_map = {x = 'c', y = 'b', z = 'a'}
local active_theme = nil local active_theme = nil
local cterm_colors = false
function M.highlight(name, foreground, background, gui, reload) function M.highlight(name, foreground, background, gui, reload)
local command = {'highlight', name} local command = {'highlight', name}
if foreground and foreground ~= 'none' then if foreground and foreground ~= 'none' then
table.insert(command, 'ctermfg=' .. utils_colors.get_cterm_color(foreground))
table.insert(command, 'guifg=' .. foreground) table.insert(command, 'guifg=' .. foreground)
if cterm_colors then
table.insert(command, 'ctermfg=' .. utils_colors.get_cterm_color(foreground))
end
end end
if background and background ~= 'none' then if background and background ~= 'none' then
table.insert(command, 'ctermbg=' .. utils_colors.get_cterm_color(background))
table.insert(command, 'guibg=' .. background) table.insert(command, 'guibg=' .. background)
if cterm_colors then
table.insert(command, 'ctermbg=' .. utils_colors.get_cterm_color(background))
end
end end
if gui then if gui then
table.insert(command, 'cterm=' .. gui) table.insert(command, 'cterm=' .. gui)
@ -29,6 +34,7 @@ end
function M.create_highlight_groups(theme) function M.create_highlight_groups(theme)
utils.clear_highlights() utils.clear_highlights()
active_theme = theme active_theme = theme
cterm_colors = not vim.o.termguicolors
for mode, sections in pairs(theme) do for mode, sections in pairs(theme) do
for section, colorscheme in pairs(sections) do for section, colorscheme in pairs(sections) do
local highlight_group_name = {'lualine', section, mode} local highlight_group_name = {'lualine', section, mode}