diff options
-rw-r--r-- | nvim/.config/nvim/lua/tobyvin/utils/start.lua | 75 |
1 files changed, 60 insertions, 15 deletions
diff --git a/nvim/.config/nvim/lua/tobyvin/utils/start.lua b/nvim/.config/nvim/lua/tobyvin/utils/start.lua index c59bed5..901f19a 100644 --- a/nvim/.config/nvim/lua/tobyvin/utils/start.lua +++ b/nvim/.config/nvim/lua/tobyvin/utils/start.lua @@ -49,30 +49,54 @@ local function should_skip() return false end -local function pad_string(str, pad, count) - for _ = 1, count do - str = pad .. str +local function max_len(lines) + local max = 0 + for _, line in ipairs(lines) do + max = math.max(max, vim.fn.strdisplaywidth(line)) end - return str + return max end -if should_skip() then - return -end +local overwrite_len = 0 + +local function buf_append_lines(buf, lines, left_align, overwrite) + if type(lines) == "string" then + lines = { lines } + end + + local max_line_len = 0 + + if left_align then + max_line_len = max_len(lines) + end + + local width = vim.api.nvim_win_get_width(0) + for i, line in ipairs(lines) do + local line_len = max_line_len + if not left_align then + line_len = vim.fn.strdisplaywidth(line) + end -local buf = vim.api.nvim_create_buf(true, true) + local pad_len = math.floor((width / 2) - (line_len / 2)) + lines[i] = string.rep(" ", pad_len) .. line + end -local width = vim.api.nvim_win_get_width(0) -local pad_width = math.floor((width / 2) - (#header[1] / 2)) + local start = -1 + if overwrite then + start = start - overwrite_len + overwrite_len = #lines + end -for i, _ in ipairs(header) do - header[i] = pad_string(header[i], " ", pad_width) + vim.bo[buf].modifiable = true + vim.api.nvim_buf_set_lines(buf, start, -1, false, lines) + vim.bo[buf].modifiable = false end -vim.api.nvim_buf_set_lines(buf, 0, -1, false, header) +if should_skip() then + return +end -vim.bo[buf].modifiable = false -vim.bo[buf].buflisted = false +local buf = vim.api.nvim_create_buf(false, true) vim.api.nvim_set_current_buf(buf) @@ -95,3 +119,24 @@ vim.opt_local.relativenumber = false vim.opt_local.list = false vim.opt_local.spell = false vim.opt_local.signcolumn = "no" + +buf_append_lines(buf, header) + +vim.api.nvim_create_autocmd("User", { + group = vim.api.nvim_create_augroup("dashboard", { clear = true }), + pattern = { "Lazy*" }, + callback = function() + local stats = require("lazy").stats() + local lines = { + string.format("startup: %s ms", stats.startuptime), + string.format("plugins: %s (%s loaded)", stats.count, stats.loaded), + } + + if require("lazy.status").has_updates() then + table.insert(lines, string.format("updates: %s", require("lazy.status").updates())) + end + + buf_append_lines(buf, lines, true, true) + end, + desc = "dashboard lazy stats", +}) |