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
|
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
|
||||||
##### Global options example
|
##### Global options example
|
||||||
```lua
|
```lua
|
||||||
options = {icons_enabled = true}
|
options = {icons_enabled = true}
|
||||||
|
|
|
@ -263,7 +263,12 @@ option (default_value)
|
||||||
• icon (differs for each component)
|
• icon (differs for each component)
|
||||||
displays an icon infront of a 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 option can be used to set custom color to a component
|
||||||
Color format:
|
Color format:
|
||||||
`lua color = {fg = '#rrggbb', bg= '#rrggbb', gui='style'}`
|
`lua color = {fg = '#rrggbb', bg= '#rrggbb', gui='style'}`
|
||||||
|
|
|
@ -118,6 +118,9 @@ local Component = {
|
||||||
-- Driver code of the class
|
-- Driver code of the class
|
||||||
draw = function(self, default_highlight)
|
draw = function(self, default_highlight)
|
||||||
self.status = ''
|
self.status = ''
|
||||||
|
if self.options.condition ~= nil and self.options.condition() ~= true then
|
||||||
|
return self.status
|
||||||
|
end
|
||||||
local status = self:update_status()
|
local status = self:update_status()
|
||||||
if self.options.format then status = self.options.format(status or '') end
|
if self.options.format then status = self.options.format(status or '') end
|
||||||
if type(status) == 'string' and #status > 0 then
|
if type(status) == 'string' and #status > 0 then
|
||||||
|
|
Loading…
Reference in New Issue