Feat: Add condition option
This commit is contained in:
parent
cdd7dc44a4
commit
d6758af65b
|
@ -200,6 +200,7 @@ right_padding | 1 | Adds padding to the right of components | all
|
|||
upper | false | Changes components to be uppercase | 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
|
||||
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
|
||||
##### Global options example
|
||||
```lua
|
||||
options = {icons_enabled = true}
|
||||
|
|
|
@ -263,7 +263,12 @@ option (default_value)
|
|||
• icon (differs for each component)
|
||||
displays an icon infront of a component
|
||||
|
||||
• color (nil)
|
||||
• 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.
|
||||
|
||||
• color (Theme colors)
|
||||
color option can be used to set custom color to a component
|
||||
Color format:
|
||||
`lua color = {fg = '#rrggbb', bg= '#rrggbb', gui='style'}`
|
||||
|
|
|
@ -118,6 +118,9 @@ local Component = {
|
|||
-- Driver code of the class
|
||||
draw = function(self, default_highlight)
|
||||
self.status = ''
|
||||
if self.options.condition ~= nil and self.options.condition() ~= true then
|
||||
return self.status
|
||||
end
|
||||
local status = self:update_status()
|
||||
if self.options.format then status = self.options.format(status or '') end
|
||||
if type(status) == 'string' and #status > 0 then
|
||||
|
|
Loading…
Reference in New Issue