diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-10-05 08:46:35 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-10-05 08:46:35 +0200 |
commit | 77cdf208765ad351e48724ed5ad57e55703eca61 (patch) | |
tree | 7f19757b255ab66895d9240a5aca77a35cef8aac /.config/nvim/lua/interface | |
parent | 4fd170aa9d55b7bcd1f0a9445c9e136b560e3220 (diff) |
Add major update to LSP from lunarvim
Diffstat (limited to '.config/nvim/lua/interface')
-rw-r--r-- | .config/nvim/lua/interface/text.lua | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/.config/nvim/lua/interface/text.lua b/.config/nvim/lua/interface/text.lua index f68cc49..c17d403 100644 --- a/.config/nvim/lua/interface/text.lua +++ b/.config/nvim/lua/interface/text.lua @@ -17,16 +17,35 @@ end -- @param container The container where lines will be displayed -- @param lines The text to align -- @param alignment The alignment value, range: [0-1] -function M.align(container, lines, alignment) +function M.align_left(container, lines, alignment) local max_len = max_len_line(lines) local indent_amount = math.ceil(math.max(container.width - max_len, 0) * alignment) - return M.shift_left(lines, indent_amount) + return M.shift_right(lines, indent_amount) +end + +--- Center align lines relatively to the parent container +-- @param container The container where lines will be displayed +-- @param lines The text to align +-- @param alignment The alignment value, range: [0-1] +function M.align_center(container, lines, alignment) + local output = {} + local max_len = max_len_line(lines) + + for _, line in ipairs(lines) do + local padding = string.rep( + " ", + (math.max(container.width, max_len) - line:len()) * alignment + ) + table.insert(output, padding .. line) + end + + return output end --- Shift lines by a given amount -- @params lines The lines the shift -- @param amount The amount of spaces to add -function M.shift_left(lines, amount) +function M.shift_right(lines, amount) local output = {} local padding = string.rep(" ", amount) |