Refactor: Remove cterm from hlighlight extractor (#174)

- remove cterm color extraction
- fix lint issues
- apply lua-format
This commit is contained in:
Shadman 2021-04-13 18:36:51 +06:00 committed by GitHub
parent 8a99a0e9e7
commit 4f53d053a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 49 deletions

View File

@ -83,7 +83,8 @@ local Component = {
self.status = highlight.component_format_highlight(
self.options.color_highlight) .. self.status
elseif self.options.color_highlight_link then
self.status = '%#' .. self.options.color_highlight_link ..'#'.. self.status
self.status = '%#' .. self.options.color_highlight_link .. '#' ..
self.status
end
self.status = self.status .. default_highlight
end,
@ -117,7 +118,9 @@ local Component = {
-- variable to store component output for manupulation
status = '',
-- Actual function the updates a component . Must be overwritten with component functionality
-- luacheck: push no unused args
update_status = function(self) end,
-- luacheck: pop
-- Driver code of the class
draw = function(self, default_highlight)

View File

@ -36,17 +36,17 @@ Diagnostics.new = function(self, options, child)
-- apply colors
if not new_diagnostics.options.color_error then
new_diagnostics.options.color_error =
utils.extract_highlight_colors('DiffDelete', 'guifg') or
utils.extract_highlight_colors('DiffDelete', 'fg') or
Diagnostics.default_colors.error
end
if not new_diagnostics.options.color_warn then
new_diagnostics.options.color_warn =
utils.extract_highlight_colors('DiffText', 'guifg') or
utils.extract_highlight_colors('DiffText', 'fg') or
Diagnostics.default_colors.warn
end
if not new_diagnostics.options.color_info then
new_diagnostics.options.color_info =
utils.extract_highlight_colors('Normal', 'guifg') or
utils.extract_highlight_colors('Normal', 'fg') or
Diagnostics.default_colors.info
end

View File

@ -33,17 +33,17 @@ Diff.new = function(self, options, child)
-- apply colors
if not new_instence.options.color_added then
new_instence.options.color_added = utils.extract_highlight_colors('DiffAdd',
'guifg') or
'fg') or
Diff.default_colors.added
end
if not new_instence.options.color_modified then
new_instence.options.color_modified =
utils.extract_highlight_colors('DiffChange', 'guifg') or
utils.extract_highlight_colors('DiffChange', 'fg') or
Diff.default_colors.modified
end
if not new_instence.options.color_removed then
new_instence.options.color_removed =
utils.extract_highlight_colors('DiffDelete', 'guifg') or
utils.extract_highlight_colors('DiffDelete', 'fg') or
Diff.default_colors.removed
end

View File

@ -8,7 +8,7 @@ EvalFuncComponent.update_status = function(self)
end
EvalFuncComponent.eval_lua = function(code)
return tostring(loadstring('return '..code)())
return tostring(loadstring('return ' .. code)())
end
EvalFuncComponent.vim_function = function(name)

View File

@ -12,13 +12,15 @@ function M.highlight(name, foreground, background, gui, reload)
if foreground and foreground ~= 'none' then
table.insert(command, 'guifg=' .. foreground)
if cterm_colors then
table.insert(command, 'ctermfg=' .. utils_colors.get_cterm_color(foreground))
table.insert(command,
'ctermfg=' .. utils_colors.get_cterm_color(foreground))
end
end
if background and background ~= 'none' then
table.insert(command, 'guibg=' .. background)
if cterm_colors then
table.insert(command, 'ctermbg=' .. utils_colors.get_cterm_color(background))
table.insert(command,
'ctermbg=' .. utils_colors.get_cterm_color(background))
end
end
if gui then
@ -141,7 +143,7 @@ function M.format_highlight(is_focused, highlight_group)
section_highlight_map[highlight_group:match(
'lualine_(.)')]
end
local highlight_name = highlight_group
local highlight_name
if not is_focused then
highlight_name = highlight_group .. [[_inactive]]
else
@ -199,8 +201,8 @@ function M.get_transitional_highlights(left_section_data, right_section_data,
-- Create the highlight_group if needed
-- Get colors from highlights
-- using string.format to convert decimal to hexadecimal
local fg = utils.extract_highlight_colors(left_highlight_name, 'guibg')
local bg = utils.extract_highlight_colors(right_highlight_name, 'guibg')
local fg = utils.extract_highlight_colors(left_highlight_name, 'bg')
local bg = utils.extract_highlight_colors(right_highlight_name, 'bg')
if not fg then fg = 'none' end
if not bg then bg = 'none' end
-- swap the bg and fg when reverse is true. As in that case highlight will

View File

@ -251,14 +251,14 @@ end
local function set_tabline()
if next(config.tabline) ~= nil then
vim.o.tabline = "%!v:lua.require'lualine'.tabline()"
vim.o.tabline = '%!v:lua.require\'lualine\'.tabline()'
vim.o.showtabline = 2
end
end
local function set_statusline()
if next(config.sections) ~= nil or next(config.inactive_sections) ~= nil then
vim.o.statusline = "%!v:lua.require'lualine'.statusline()"
vim.o.statusline = '%!v:lua.require\'lualine\'.statusline()'
vim.api.nvim_exec([[
autocmd lualine WinLeave,BufLeave * lua vim.wo.statusline=require'lualine'.statusline()
autocmd lualine WinEnter,BufEnter * set statusline<
@ -277,8 +277,4 @@ local function setup(user_config)
set_tabline()
end
return {
setup = setup,
statusline = status_dispatch,
tabline = tabline,
}
return {setup = setup, statusline = status_dispatch, tabline = tabline}

View File

@ -15,10 +15,10 @@ local function getHi(scope, syntaxlist)
if vim.fn.hlexists(highlight_name) ~= 0 then
local color = utils.extract_highlight_colors(highlight_name)
if color.reverse then
if scope == 'guibg' then
scope = 'guifg'
if scope == 'bg' then
scope = 'fg'
else
scope = 'guibg'
scope = 'bg'
end
end
if color[scope] then return color[scope] end
@ -104,20 +104,20 @@ end
-- Get the colors to create theme
local colors = {
normal = getHi('guibg', {'PmenuSel', 'PmenuThumb', 'TabLineSel'}),
insert = getHi('guifg', {'String', 'MoreMsg'}),
replace = getHi('guifg', {'Number', 'Type'}),
visual = getHi('guifg', {'Special', 'Boolean', 'Constant'}),
command = getHi('guifg', {'Identifier'}),
back1 = getHi('guibg', {'Normal', 'StatusLineNC'}),
fore = getHi('guifg', {'Normal', 'StatusLine'}),
back2 = getHi('guibg', {'StatusLine'})
normal = getHi('bg', {'PmenuSel', 'PmenuThumb', 'TabLineSel'}),
insert = getHi('fg', {'String', 'MoreMsg'}),
replace = getHi('fg', {'Number', 'Type'}),
visual = getHi('fg', {'Special', 'Boolean', 'Constant'}),
command = getHi('fg', {'Identifier'}),
back1 = getHi('bg', {'Normal', 'StatusLineNC'}),
fore = getHi('fg', {'Normal', 'StatusLine'}),
back2 = getHi('bg', {'StatusLine'})
}
-- Change brightness of colors
-- darken incase of light theme lighten incase of dark theme
if get_color_brightness(utils.extract_highlight_colors('Normal', 'guibg')) > 0.5 then
if get_color_brightness(utils.extract_highlight_colors('Normal', 'bg')) > 0.5 then
brightness_modifier_parameter = -brightness_modifier_parameter
end

View File

@ -2,26 +2,19 @@
-- MIT license, see LICENSE for more details.
local M = {}
-- Note for now only works for termguicolors scope can be background or foreground
-- Note for now only works for termguicolors scope can be bg or fg or any other
-- attr parameter like bold/italic/reverse
function M.extract_highlight_colors(color_group, scope)
if vim.fn.hlexists(color_group) == 0 then return nil end
local gui_colors = vim.api.nvim_get_hl_by_name(color_group, true)
local cterm_colors = vim.api.nvim_get_hl_by_name(color_group, false)
local color = {
ctermfg = cterm_colors.foreground,
ctermbg = cterm_colors.background
}
if gui_colors.background then
color.guibg = string.format('#%06x', gui_colors.background)
gui_colors.background = nil
local color = vim.api.nvim_get_hl_by_name(color_group, true)
if color.background ~= nil then
color.bg = string.format('#%06x', color.background)
color.background = nil
end
if gui_colors.foreground then
color.guifg = string.format('#%06x', gui_colors.foreground)
gui_colors.foreground = nil
if color.foreground ~= nil then
color.fg = string.format('#%06x', color.foreground)
color.foreground = nil
end
cterm_colors.background = nil
cterm_colors.foreground = nil
color = vim.tbl_extend('keep', color, gui_colors, cterm_colors)
if scope then return color[scope] end
return color
end