Skip to content

Commit

Permalink
feat(elastic_components)!: allow make_elastic_components accept
Browse files Browse the repository at this point in the history
components instead of just providers
  • Loading branch information
rebelot committed Jan 24, 2022
1 parent 0e7565e commit 31339a4
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lua/heirline/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,18 @@ function M.get_win_attr(self, attr, default)
return self[attr][winnr]
end

function M.make_elastic_component(priority, providers)
function M.make_elastic_component(priority, ...)
local new = {}
local components = { ... }
for i, c in ipairs(components) do
new[i] = vim.tbl_deep_extend("keep", c, {})
end
new.static = {
priority = priority,
providers = providers,
next_p = function(self)
local pi = M.get_win_attr(self, "pi") + 1
if pi > #self.providers then
pi = #self.providers
if pi > #self then
pi = #self
end
M.set_win_attr(self, "pi", pi)
end,
Expand All @@ -134,6 +137,13 @@ function M.make_elastic_component(priority, providers)
self.elastic_ids[self.priority] = self.elastic_ids[self.priority] or {}
table.insert(self.elastic_ids[self.priority], self.id)
M.set_win_attr(self, "pi", 1)

for _, c in ipairs(self) do
c.condition = function(self_)
return self_.id[#self_.id] == M.get_win_attr(self_, "pi")
end
end

self.once = true
end
end
Expand All @@ -142,12 +152,6 @@ function M.make_elastic_component(priority, providers)
return not self.deferred
end

new.provider = function(self)
local pi = M.get_win_attr(self, "pi")
local provider = self.providers[pi]
return type(provider) == 'function' and (provider(self) or "") or provider
end

return new
end

Expand Down Expand Up @@ -190,7 +194,7 @@ function M.elastic_before(statusline, last_out)
local max_count = 0
for _, id in ipairs(ids) do
local ec = statusline:get(id)
max_count = max_count + #ec.providers
max_count = max_count + #ec
end

local i = 0
Expand Down

0 comments on commit 31339a4

Please sign in to comment.