Skip to content

Commit

Permalink
feat(text): center text
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Nov 29, 2022
1 parent 7303017 commit 88869e6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lua/lazy/view/text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ function Text:highlight(patterns)
end
end

function Text:center()
local last = self._lines[#self._lines]
if not last then
return
end
local width = 0
for _, segment in ipairs(last) do
width = width + vim.fn.strwidth(segment.str)
end
width = vim.api.nvim_win_get_width(self.win) - 2 * self.padding - width
table.insert(last, 1, {
str = string.rep(" ", math.floor(width / 2 + 0.5)),
})
return self
end

function Text:trim()
while #self._lines > 0 and #self._lines[1] == 0 do
table.remove(self._lines, 1)
Expand Down

0 comments on commit 88869e6

Please sign in to comment.