Skip to content

Commit

Permalink
refactor(statusline)!: remove stop_when in favor of the more versatil…
Browse files Browse the repository at this point in the history
…e pick_child.

add utility function `pick_child_on_condition` to cover general usecase of
selecting among multiple buffer-specific statuslines.
  • Loading branch information
rebelot committed Feb 6, 2022
1 parent c805ac2 commit 7649842
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 0 additions & 4 deletions lua/heirline/statusline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ function StatusLine:nonlocal(attr)
return getmetatable(self).__index(self, attr)
end


function StatusLine:local_(attr)
local orig_mt = getmetatable(self)
setmetatable(self, {})
Expand Down Expand Up @@ -146,9 +145,6 @@ function StatusLine:eval()
local child = self[i]
local out = child:eval()
table.insert(stl, out)
if self.stop_when and self:stop_when(out, child) then
break
end
end

self.stl = table.concat(stl, "")
Expand Down
11 changes: 11 additions & 0 deletions lua/heirline/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ function M.expand_or_contract_flexible_components(statusline, out)
saved_chars = saved_chars + (prev_len - cur_len)
end
end

if stl_len - saved_chars <= winw then
break
end
Expand Down Expand Up @@ -232,4 +233,14 @@ function M.expand_or_contract_flexible_components(statusline, out)
end
end

function M.pick_child_on_condition(self)
self.pick_child = {}
for i, child in ipairs(self) do
if not child.condition or child:condition() then
table.insert(self.pick_child, i)
break
end
end
end

return M

0 comments on commit 7649842

Please sign in to comment.