diff options
author | chaesngmin <[email protected]> | 2021-09-17 04:13:52 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2021-09-17 04:13:52 -0700 |
commit | 254ab2102b5f8f6187321a545998ead4c3abd27a (patch) | |
tree | 8f329f66cc4d62c6964d3925bbb40f0988f351d3 /lua/interface/text.lua | |
parent | eab0369ae8688b23946a8a9e6dab6061ec0c554a (diff) |
[Feature] Add lunarvim latest release tag to dashboard (#1436)
* feat: add lunarvim latest release tag to dashboard
* Add a function to center-align text
Rename align to align_left
Rename shift_left to shift_right
* refactor(dashboard): remove unnecessary comment
* refactor(dashboard): use `home_dir` variable for `lv_path`
* refactor(dashboard): use $LUNARVIM_RUNTIME_DIR for lv_path
* feat(bootstrap): add fn that returns lvim version
* refactor(dashboard): use version, lunarvim dir with bootstrap fns
* build: add global get_version() from bootstrap
Co-authored-by: Luc Sinet <[email protected]>
Diffstat (limited to 'lua/interface/text.lua')
-rw-r--r-- | lua/interface/text.lua | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lua/interface/text.lua b/lua/interface/text.lua index f68cc491..6bf280e8 100644 --- a/lua/interface/text.lua +++ b/lua/interface/text.lua @@ -13,20 +13,36 @@ local function max_len_line(lines) return max_len end ---- Center align lines relatively to the parent container +--- Left 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(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) |