feat(ui): add dashboard animation

This commit is contained in:
Mattias Sjödin 2023-09-03 15:34:36 +02:00
parent f9dadc11b3
commit 22c0046e7c
No known key found for this signature in database
GPG key ID: 9C0C3CE838F23F6F

View file

@ -279,16 +279,67 @@ return {
event = "VimEnter",
opts = function()
local dashboard = require("alpha.themes.dashboard")
local logo = [[
Z
Z
z
local interval_ms = 700
local frame_index = 1
local frames = {
[[
z
]]
]],
[[
z
]],
[[
Z
]],
[[
Z
]],
}
-- Function to update the header with the next frame
local function update_header()
dashboard.section.header.val = vim.split(frames[frame_index], "\n")
frame_index = (frame_index % #frames) + 1
end
-- Init
update_header()
-- Start timer to update the header
local timer_id = vim.fn.timer_start(interval_ms, function()
update_header()
pcall(vim.cmd.AlphaRedraw)
end, { ["repeat"] = -1 })
-- end timer when Dashboard is closed
vim.api.nvim_create_autocmd("User", {
pattern = "AlphaClosed",
callback = function()
if timer_id then
vim.fn.timer_stop(timer_id)
end
end,
})
dashboard.section.header.val = vim.split(logo, "\n")
dashboard.section.buttons.val = {
dashboard.button("f", "" .. " Find file", ":Telescope find_files <CR>"),
dashboard.button("n", "" .. " New file", ":ene <BAR> startinsert <CR>"),