diff --git a/README.md b/README.md index dc5dfeb..9651a6a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lua/lualine/component.lua b/lua/lualine/component.lua index e985509..17610da 100644 --- a/lua/lualine/component.lua +++ b/lua/lualine/component.lua @@ -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() diff --git a/tests/spec/component_spec.lua b/tests/spec/component_spec.lua index 8f89720..c193109 100644 --- a/tests/spec/component_spec.lua +++ b/tests/spec/component_spec.lua @@ -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)