Feat: Allow color option to accept highlight group

This commit is contained in:
shadmansaleh 2021-04-07 00:05:14 +06:00
parent 7c6d1f9074
commit 9e957e341e
3 changed files with 12 additions and 4 deletions

View File

@ -206,7 +206,7 @@ upper | false | Changes components to be uppercase | All
lower | false | Changes components to be lowercase | All lower | false | Changes components to be lowercase | All
format | nil | Takes a function . The funtion gets the result of component as argument and it's return value is displayed. So this function can parse and format the output as user wants. | All format | nil | Takes a function . The funtion gets the result of component as argument and it's return value is displayed. So this function can parse and format the output as user wants. | All
condition | nil | Takes a function. The component is loaded if the function returns true otherwise not. It can be used to load some comoonents on specific cases. | All condition | nil | Takes a function. The component is loaded if the function returns true otherwise not. It can be used to load some comoonents on specific cases. | All
color | nil | Sets custom color for the component in this format<br></br>`color = {fg = '#rrggbb', bg= '#rrggbb', gui='style'}`<br></br>The fields of color table are optional and default to theme | All color | nil | Sets custom color for the component in this format<br></br>`color = {fg = '#rrggbb', bg= '#rrggbb', gui='style'}`<br></br>The fields of color table are optional and default to theme <br></br>Color option can also be a string containing highlight group name `color = "WarningMsg"`. One neat trick set the color to highlight group name then change that highlight with :hi command to change color of that component at runtime. | All
#### Using global options #### Using global options
Global options can be set in two ways. One is as part of options table in setup. Global options can be set in two ways. One is as part of options table in setup.

View File

@ -287,7 +287,11 @@ option (default_value)
Color format: Color format:
`lua color = {fg = '#rrggbb', bg= '#rrggbb', gui='style'}` `lua color = {fg = '#rrggbb', bg= '#rrggbb', gui='style'}`
the members of color table are optional and default to theme the members of color table are optional and default to theme
Color option can also be a string containing highlight group name >
color = "WarningMsg"`
< One neat trick set the color to highlight group name then change
that highlight with :hi command to change color of that component
at runtime.
Using global options~ Using global options~
@ -536,4 +540,4 @@ Vimscript config example
lua require("lualine").setup() lua require("lualine").setup()
< <
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
vim:tw=80:sw=4:ts=8:noet:ft=help:norl:noet: vim:tw=80:sw=4:ts=8:noet:ft=help:norl:et:

View File

@ -37,11 +37,13 @@ local Component = {
create_option_highlights = function(self) create_option_highlights = function(self)
-- set custom highlights -- set custom highlights
if self.options.color then if type(self.options.color) == 'table' then
self.options.color_highlight = highlight.create_component_highlight_group( self.options.color_highlight = highlight.create_component_highlight_group(
self.options.color, self.options.color,
self.options.component_name, self.options.component_name,
self.options) self.options)
elseif type(self.options.color) == 'string' then
self.options.color_highlight_link = self.options.color
end end
end, end,
@ -80,6 +82,8 @@ local Component = {
if self.options.color_highlight then if self.options.color_highlight then
self.status = highlight.component_format_highlight( self.status = highlight.component_format_highlight(
self.options.color_highlight) .. self.status self.options.color_highlight) .. self.status
elseif self.options.color_highlight_link then
self.status = '%#' .. self.options.color_highlight_link ..'#'.. self.status
end end
self.status = self.status .. default_highlight self.status = self.status .. default_highlight
end, end,