mirror of
https://github.com/LunarVim/LunarVim.git
synced 2024-09-20 10:35:08 +02:00
[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 <luc.sinet@gmail.com>
This commit is contained in:
parent
eab0369ae8
commit
254ab2102b
5 changed files with 44 additions and 7 deletions
|
@ -22,6 +22,7 @@ stds.nvim = {
|
|||
"get_runtime_dir",
|
||||
"get_config_dir",
|
||||
"get_cache_dir",
|
||||
"get_version",
|
||||
-- vim = { fields = { "cmd", "api", "fn", "o" } },
|
||||
},
|
||||
}
|
||||
|
|
|
@ -32,6 +32,15 @@ function _G.get_cache_dir()
|
|||
return lvim_cache_dir
|
||||
end
|
||||
|
||||
function _G.get_version(type)
|
||||
local lvim_full_ver = vim.fn.system("git -C " .. get_runtime_dir() .. "/lvim describe --tag")
|
||||
if type == "short" then
|
||||
return vim.fn.split(lvim_full_ver, "-")[1]
|
||||
else
|
||||
return string.sub(lvim_full_ver, 1, #lvim_full_ver - 1)
|
||||
end
|
||||
end
|
||||
|
||||
function M:init()
|
||||
self.runtime_dir = get_runtime_dir()
|
||||
self.config_dir = get_config_dir()
|
||||
|
|
|
@ -69,7 +69,18 @@ M.setup = function()
|
|||
|
||||
vim.g.dashboard_session_directory = lvim.builtin.dashboard.session_directory
|
||||
|
||||
vim.g.dashboard_custom_footer = lvim.builtin.dashboard.footer
|
||||
local lvim_site = "lunarvim.org"
|
||||
local lvim_version = get_version "short"
|
||||
local num_plugins_loaded = #vim.fn.globpath(get_runtime_dir() .. "/site/pack/packer/start", "*", 0, 1)
|
||||
|
||||
local text = require "interface.text"
|
||||
vim.g.dashboard_custom_footer = text.align_center({ width = 0 }, {
|
||||
"LunarVim loaded " .. num_plugins_loaded .. " plugins ",
|
||||
"",
|
||||
"v" .. lvim_version,
|
||||
"",
|
||||
lvim_site,
|
||||
}, 0.49) -- Use 0.49 as counts for 2 characters
|
||||
|
||||
require("core.autocmds").define_augroups {
|
||||
_dashboard = {
|
||||
|
|
|
@ -97,7 +97,7 @@ function M.toggle_popup(ft)
|
|||
local caps_text = "* Capabilities list: "
|
||||
local caps_text_len = caps_text:len()
|
||||
local enabled_caps = text.format_table(client_enabled_caps, 3, " | ")
|
||||
enabled_caps = text.shift_left(enabled_caps, caps_text_len)
|
||||
enabled_caps = text.shift_right(enabled_caps, caps_text_len)
|
||||
enabled_caps[1] = fmt("%s%s", caps_text, enabled_caps[1]:sub(caps_text_len + 1))
|
||||
vim.list_extend(lsp_info, enabled_caps)
|
||||
end
|
||||
|
@ -155,7 +155,7 @@ function M.toggle_popup(ft)
|
|||
vim.list_extend(content, section)
|
||||
end
|
||||
|
||||
return text.align(popup, content, 0.5)
|
||||
return text.align_left(popup, content, 0.5)
|
||||
end
|
||||
|
||||
local function set_syntax_hl()
|
||||
|
|
|
@ -13,20 +13,36 @@ local function max_len_line(lines)
|
|||
return max_len
|
||||
end
|
||||
|
||||
--- 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_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_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(container, lines, alignment)
|
||||
function M.align_center(container, lines, alignment)
|
||||
local output = {}
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue