refactor(highlights): set_highlight over highlight

This commit is contained in:
Matt Leong 2022-01-03 16:08:50 -08:00
parent 3be2d316fc
commit df13f58678
8 changed files with 116 additions and 74 deletions

View file

@ -173,7 +173,6 @@ return packer.startup(function()
event = 'BufWinEnter', event = 'BufWinEnter',
config = function() config = function()
require('cosmic.plugins.terminal') require('cosmic.plugins.terminal')
require('cosmic.plugins.terminal.mappings')
end, end,
disable = vim.tbl_contains(user_plugins.disable, 'terminal'), disable = vim.tbl_contains(user_plugins.disable, 'terminal'),
}) })

View file

@ -5,7 +5,7 @@ local condition = require('galaxyline.condition')
local fileinfo = require('galaxyline.providers.fileinfo') local fileinfo = require('galaxyline.providers.fileinfo')
local utils = require('cosmic.utils') local utils = require('cosmic.utils')
local colors = require('cosmic.theme.colors') local colors = require('cosmic.theme.colors')
local highlight = require('cosmic.theme.utils').highlight local set_highlight = require('cosmic.theme.utils').set_highlight
local icons = require('cosmic.theme.icons') local icons = require('cosmic.theme.icons')
local config = require('cosmic.config') local config = require('cosmic.config')
local get_highlight = require('cosmic.theme.utils').get_highlight local get_highlight = require('cosmic.theme.utils').get_highlight
@ -150,22 +150,51 @@ gls.left = {
end end
local label, mode_color, mode_nested = unpack(m) local label, mode_color, mode_nested = unpack(m)
highlight('GalaxyViMode', mode_color, mode_nested) set_highlight('GalaxyViMode', {
highlight('GalaxyViModeInv', mode_nested, mode_color) guibg = mode_color,
highlight('GalaxyViModeNested', mode_nested, 'StatusLine') guifg = mode_nested,
highlight('GalaxyViModeNestedInv', 'StatusLine', mode_nested) })
highlight('GalaxyPercentBracket', 'StatusLine', mode_color) set_highlight('GalaxyViModeInv', {
highlight('GalaxyText', 'StatusLine', mode_color) guibg = mode_nested,
guifg = mode_color,
highlight('GalaxyGitLCBracket', mode_nested, mode_color) })
set_highlight('GalaxyViModeNested', {
guibg = mode_nested,
guifg = 'StatusLine',
})
set_highlight('GalaxyViModeNestedInv', {
guibg = 'StatusLine',
guifg = mode_nested,
})
set_highlight('GalaxyPercentBracket', {
guibg = 'StatusLine',
guifg = mode_color,
})
set_highlight('GalaxyText', {
guibg = 'StatusLine',
guifg = mode_color,
})
set_highlight('GalaxyGitLCBracket', {
guibg = mode_nested,
guifg = mode_color,
})
if condition.buffer_not_empty() then if condition.buffer_not_empty() then
highlight('GalaxyViModeBracket', mode_nested, mode_color) set_highlight('GalaxyViModeBracket', {
guibg = mode_nested,
guifg = mode_color,
})
else else
if condition.check_git_workspace() then if condition.check_git_workspace() then
highlight('GalaxyGitLCBracket', 'StatusLine', mode_color) set_highlight('GalaxyGitLCBracket', {
guibg = 'StatusLine',
guifg = mode_color,
})
end end
highlight('GalaxyViModeBracket', 'StatusLine', mode_color) set_highlight('GalaxyViModeBracket', {
guibg = 'StatusLine',
guifg = mode_color,
})
end end
return ' ' .. label .. ' ' return ' ' .. label .. ' '
end, end,

View file

@ -0,0 +1,43 @@
local _, colors = pcall(require, 'cosmic.theme.colors')
if not colors then
return
end
local set_highlight = require('cosmic.theme.utils').set_highlight
-- notification highlights
set_highlight('NotifyINFOBorder', {
guifg = colors.hint,
})
set_highlight('NotifyINFOTitle', {
guifg = colors.hint,
})
set_highlight('NotifyINFOIcon', {
guifg = colors.hint,
})
set_highlight('NotifyWARNBorder', {
guifg = colors.warn,
})
set_highlight('NotifyWARNTitle', {
guifg = colors.warn,
})
set_highlight('NotifyWARNIcon', {
guifg = colors.warn,
})
set_highlight('NotifyERRORBorder', {
guifg = colors.error,
})
set_highlight('NotifyERRORTitle', {
guifg = colors.error,
})
set_highlight('NotifyERRORIcon', {
guifg = colors.error,
})
set_highlight('NotifyTRACEBorder', {
guifg = colors.trace,
})
set_highlight('NotifyTRACETitle', {
guifg = colors.trace,
})
set_highlight('NotifyTRACEIcon', {
guifg = colors.trace,
})

View file

@ -15,3 +15,5 @@ require('notify').setup(utils.merge({
}, config.notify or {})) }, config.notify or {}))
vim.notify = require('notify') vim.notify = require('notify')
require('cosmic.plugins.notify.highlights')

View file

@ -0,0 +1,8 @@
local set_highlight = require('cosmic.theme.utils').set_highlight
-- terminal highlights
set_highlight('FloatBorder', {
guibg = 'None',
})
vim.cmd('hi! link FloatermBorder FloatBorder')

View file

@ -6,3 +6,6 @@ g.floaterm_height = 0.8
g.floaterm_title = '[' .. title .. ']:($1/$2)' g.floaterm_title = '[' .. title .. ']:($1/$2)'
g.floaterm_borderchars = '─│─│╭╮╯╰' g.floaterm_borderchars = '─│─│╭╮╯╰'
g.floaterm_opener = 'vsplit' g.floaterm_opener = 'vsplit'
require('cosmic.plugins.terminal.mappings')
require('cosmic.plugins.terminal.highlights')

View file

@ -2,61 +2,31 @@ local _, colors = pcall(require, 'cosmic.theme.colors')
if not colors then if not colors then
return return
end end
local highlight = require('cosmic.theme.utils').highlight
local get_highlight = require('cosmic.theme.utils').get_highlight local get_highlight = require('cosmic.theme.utils').get_highlight
local set_highlight = require('cosmic.theme.utils').set_highlight local set_highlight = require('cosmic.theme.utils').set_highlight
local utils = require('cosmic.utils')
local statusline_colors = get_highlight('StatusLine') local statusline_colors = get_highlight('StatusLine')
local error_colors = get_highlight('DiagnosticError') local error_colors = get_highlight('DiagnosticError')
set_highlight(
'DiagnosticErrorInv',
utils.merge(error_colors, {
guibg = error_colors.guifg,
guifg = statusline_colors.guibg,
})
)
local warning_colors = get_highlight('DiagnosticWarn') local warning_colors = get_highlight('DiagnosticWarn')
set_highlight(
'DiagnosticWarnInv',
utils.merge(warning_colors, {
guibg = warning_colors.guifg,
guifg = statusline_colors.guibg,
})
)
local hint_colors = get_highlight('DiagnosticHint') local hint_colors = get_highlight('DiagnosticHint')
set_highlight(
'DiagnosticHintInv',
utils.merge(hint_colors, {
guibg = hint_colors.guifg,
guifg = statusline_colors.guibg,
})
)
local info_colors = get_highlight('DiagnosticInfo') local info_colors = get_highlight('DiagnosticInfo')
set_highlight(
'DiagnosticInfoInv',
utils.merge(info_colors, {
guibg = info_colors.guifg,
guifg = statusline_colors.guibg,
})
)
-- notification highlights set_highlight('DiagnosticErrorInv', {
highlight('NotifyINFOBorder', nil, colors.hint) guibg = error_colors.guifg,
highlight('NotifyINFOTitle', nil, colors.hint) guifg = statusline_colors.guibg,
highlight('NotifyINFOIcon', nil, colors.hint) })
highlight('NotifyWARNBorder', nil, colors.warn)
highlight('NotifyWARNTitle', nil, colors.warn)
highlight('NotifyWARNIcon', nil, colors.warn)
highlight('NotifyERRORBorder', nil, colors.error)
highlight('NotifyERRORTitle', nil, colors.error)
highlight('NotifyERRORIcon', nil, colors.error)
highlight('NotifyTRACEBorder', nil, colors.trace)
highlight('NotifyTRACETitle', nil, colors.trace)
highlight('NotifyTRACEIcon', nil, colors.trace)
vim.cmd('hi FloatBorder guibg=None') set_highlight('DiagnosticWarnInv', {
vim.cmd('hi! link FloatermBorder FloatBorder') guibg = warning_colors.guifg,
guifg = statusline_colors.guibg,
})
set_highlight('DiagnosticHintInv', {
guibg = hint_colors.guifg,
guifg = statusline_colors.guibg,
})
set_highlight('DiagnosticInfoInv', {
guibg = info_colors.guifg,
guifg = statusline_colors.guibg,
})

View file

@ -1,17 +1,5 @@
local M = {} local M = {}
M.highlight = function(group, bg, fg, gui)
if gui ~= nil and gui ~= '' then
vim.api.nvim_command(('hi %s guibg=%s guifg=%s gui=%s'):format(group, bg, fg, gui))
elseif bg == nil then
vim.api.nvim_command(('hi %s guifg=%s'):format(group, fg))
elseif fg == nil then
vim.api.nvim_command(('hi %s guibg=%s'):format(group, bg))
else
vim.api.nvim_command(('hi %s guibg=%s guifg=%s'):format(group, bg, fg))
end
end
M.set_highlight = function(hi, colors) M.set_highlight = function(hi, colors)
local hi_str = '' local hi_str = ''