2020-12-30 14:48:51 +00:00
|
|
|
local M = { }
|
|
|
|
|
|
|
|
local function highlight (name, foreground, background, special)
|
2021-01-03 19:11:22 +00:00
|
|
|
local command = {
|
|
|
|
'highlight', name,
|
|
|
|
'guifg=' .. foreground,
|
|
|
|
'guibg=' .. background,
|
|
|
|
'gui=' .. (special or 'none'),
|
|
|
|
}
|
|
|
|
return table.concat(command, ' ')
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
|
|
|
|
2021-01-04 01:14:29 +00:00
|
|
|
function M.create_highlight_groups(theme)
|
2020-12-30 14:48:51 +00:00
|
|
|
for mode, sections in pairs(theme) do
|
|
|
|
for section, colorscheme in pairs(sections) do
|
2021-01-03 19:11:22 +00:00
|
|
|
local special = nil
|
2020-12-30 14:48:51 +00:00
|
|
|
if section == 'a' then
|
2021-01-03 19:11:22 +00:00
|
|
|
special = 'bold'
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
2021-01-04 01:14:29 +00:00
|
|
|
local highlight_group_name = { 'lualine', section, mode }
|
|
|
|
vim.cmd(highlight(table.concat(highlight_group_name, '_'), colorscheme.fg, colorscheme.bg, special))
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-04 01:14:29 +00:00
|
|
|
function M.format_highlight(is_focused, highlight_group)
|
2020-12-30 14:48:51 +00:00
|
|
|
local mode = require('lualine.components.mode')()
|
2021-01-04 01:14:29 +00:00
|
|
|
highlight_group = [[%#]] .. highlight_group
|
|
|
|
if not is_focused then
|
|
|
|
highlight_group = highlight_group .. [[_inactive]]
|
2020-12-30 14:48:51 +00:00
|
|
|
else
|
|
|
|
if mode == 'V-BLOCK' or mode == 'V-LINE' then
|
2021-01-04 01:14:29 +00:00
|
|
|
highlight_group = highlight_group .. '_visual'
|
2020-12-30 14:48:51 +00:00
|
|
|
elseif mode == 'V-REPLACE' then
|
2021-01-04 01:14:29 +00:00
|
|
|
highlight_group = highlight_group .. '_replace'
|
2020-12-30 14:48:51 +00:00
|
|
|
else
|
2021-01-04 01:14:29 +00:00
|
|
|
highlight_group = highlight_group .. '_' .. mode:lower()
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
|
|
|
end
|
2021-01-04 01:14:29 +00:00
|
|
|
highlight_group = highlight_group .. [[#]]
|
|
|
|
return highlight_group
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|