Feat: Add condition option

This commit is contained in:
shadmansaleh 2021-04-06 19:31:45 +06:00
parent cdd7dc44a4
commit d6758af65b
3 changed files with 10 additions and 1 deletions

View File

@ -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}

View File

@ -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'}`

View File

@ -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