Skip to content

Commit

Permalink
feat(statusline): give components an id; get component by id
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelot committed Jan 18, 2022
1 parent 8bbe790 commit 99b51ba
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lua/heirline/statusline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ function StatusLine:new(child)
return new
end

function StatusLine:make_ids(index)
local parent_id = self:nonlocal("id") or {}

self.id = vim.tbl_extend('force', parent_id, {[#parent_id + 1] = index})

for i, c in ipairs(self) do
c:make_ids(i)
end
end

function StatusLine:get(id)
id = id or {}
local curr = self
for _, i in ipairs(id) do
curr = curr[i]
end
return curr
end


function StatusLine:nonlocal(attr)
return getmetatable(self).__index(self, attr)
end
Expand Down

0 comments on commit 99b51ba

Please sign in to comment.