feat: add custom color support for icons

This commit is contained in:
shadmansaleh 2022-03-02 20:02:58 +06:00
parent 37a314b9e3
commit 32c85cd214
3 changed files with 37 additions and 4 deletions

View File

@ -352,7 +352,12 @@ sections = {
{
'mode',
icons_enabled = true, -- Enables the display of icons alongside the component.
icon = nil, -- Defines the icon to be displayed in front of the component.
-- Defines the icon to be displayed in front of the component.
-- Can be string|table
-- As table it must contain the icon as first entry and can use
-- color option to custom color the icon. Example:
-- {'branch', icon = ''} / {'branch', icon = {'', color={fg='green'}}}
icon = nil,
separator = nil, -- Determines what separator to use for the component.
-- Note:

View File

@ -365,7 +365,12 @@ General component options These are options that control behavior
{
'mode',
icons_enabled = true, -- Enables the display of icons alongside the component.
icon = nil, -- Defines the icon to be displayed in front of the component.
-- Defines the icon to be displayed in front of the component.
-- Can be string|table
-- As table it must contain the icon as first entry and can use
-- color option to custom color the icon. Example:
-- {'branch', icon = ''} / {'branch', icon = {'', color={fg='green'}}}
icon = nil,
separator = nil, -- Determines what separator to use for the component.
-- Note:

View File

@ -58,6 +58,15 @@ function M:create_option_highlights()
false
)
end
-- setup icon highlight
if type(self.options.icon) == 'table' and self.options.icon.color then
self.options.icon_color_highlight = highlight.create_component_highlight_group(
self.options.icon.color,
self.options.component_name .. 'icon',
self.options,
false
)
end
end
---adds spaces to left and right of a component
@ -111,8 +120,22 @@ end
---apply icon in front of component (prepemds component with icon)
function M:apply_icon()
if self.options.icons_enabled and self.options.icon then
self.status = self.options.icon .. ' ' .. self.status
local icon = self.options.icon
if self.options.icons_enabled and icon then
if type(icon) == 'table' then
icon = icon[1]
end
if self.options.icon_color_highlight then
self.status = table.concat {
highlight.component_format_highlight(self.options.icon_color_highlight),
icon,
self:get_default_hl(),
' ',
self.status,
}
else
self.status = table.concat({ icon, self.status }, ' ')
end
end
end