feat: add draw_empty option to always draw component event when it's empty (#964)
* feat: add draw_empty option to always draw component event when it's empty Closes #963 * tests: add test for component draw_empty option * docs: add docs for component draw_empty option --------- Co-authored-by: Carl Johnson <carl.darick.johnson@gmail.com>
This commit is contained in:
parent
508b0785bc
commit
9805076155
|
@ -419,6 +419,9 @@ sections = {
|
|||
|
||||
cond = nil, -- Condition function, the component is loaded when the function returns `true`.
|
||||
|
||||
draw_empty = false, -- Whether to draw component even if it's empty.
|
||||
-- Might be useful if you want just the separator.
|
||||
|
||||
-- Defines a custom color for the component:
|
||||
--
|
||||
-- 'highlight_group_name' | { fg = '#rrggbb'|cterm_value(0-255)|'color_name(red)', bg= '#rrggbb', gui='style' } | function
|
||||
|
|
|
@ -274,7 +274,7 @@ function M:draw(default_highlight, is_focused)
|
|||
if self.options.fmt then
|
||||
status = self.options.fmt(status or '', self)
|
||||
end
|
||||
if type(status) == 'string' and #status > 0 then
|
||||
if type(status) == 'string' and (#status > 0 or self.options.draw_empty) then
|
||||
self.status = status
|
||||
self:apply_icon()
|
||||
self:apply_padding()
|
||||
|
|
|
@ -211,6 +211,19 @@ describe('Component:', function()
|
|||
assert.stub(hl.component_format_highlight).was_called_with(comp2.options.color_highlight)
|
||||
hl.component_format_highlight:revert()
|
||||
end)
|
||||
|
||||
it('draw_empty', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
separator = '>',
|
||||
fmt = function()
|
||||
return ''
|
||||
end,
|
||||
draw_empty = true,
|
||||
}
|
||||
assert_component(nil, opts, '>')
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
|
|
Loading…
Reference in New Issue