mirror of
https://github.com/hyzendust/KickestEnd.nvim.git
synced 2026-02-15 05:01:14 +01:00
Add: Load random ascii_arts from ascii_arts folder with a naming format of ascii_art_1/2/3/*
This commit is contained in:
@@ -5,9 +5,46 @@ return {
|
||||
local alpha = require 'alpha'
|
||||
local dashboard = require 'alpha.themes.dashboard'
|
||||
|
||||
-- Load ASCII splash
|
||||
local splash = require 'ascii_splash'
|
||||
dashboard.section.header.val = splash
|
||||
-- Load random ASCII arts
|
||||
-- Keep track of last shown ASCII art
|
||||
local last_ascii = nil
|
||||
-- load a random ASCII art
|
||||
local function load_random_ascii()
|
||||
local ascii_dir = vim.fn.stdpath 'config' .. '/lua/ascii_arts/'
|
||||
local pattern = ascii_dir .. 'ascii_art_*.lua'
|
||||
local ascii_art_files = vim.fn.glob(pattern, false, true)
|
||||
if vim.tbl_isempty(ascii_art_files) then
|
||||
return { 'Alpha' }
|
||||
end
|
||||
-- Convert file paths to module names (for require)
|
||||
local ascii_modules = {}
|
||||
for _, path in ipairs(ascii_art_files) do
|
||||
local name = path:match 'ascii_arts/([^/]+)%.lua$'
|
||||
if name then
|
||||
table.insert(ascii_modules, 'ascii_arts.' .. name)
|
||||
end
|
||||
end
|
||||
-- If only one ASCII exists, return it
|
||||
if #ascii_modules == 1 then
|
||||
last_ascii = ascii_modules[1]
|
||||
local ok, splash = pcall(require, last_ascii)
|
||||
return ok and splash or { 'Alpha' }
|
||||
end
|
||||
-- Pick a random one that isn't the same as last
|
||||
math.randomseed(os.time() + vim.loop.hrtime())
|
||||
local selected = ascii_modules[math.random(#ascii_modules)]
|
||||
while selected == last_ascii and #ascii_modules > 1 do
|
||||
selected = ascii_modules[math.random(#ascii_modules)]
|
||||
end
|
||||
last_ascii = selected
|
||||
local ok, splash = pcall(require, selected)
|
||||
return (ok and type(splash) == 'table') and splash or { 'Alpha' }
|
||||
end
|
||||
-- Function to refresh dashboard header dynamically
|
||||
local function refresh_header()
|
||||
dashboard.section.header.val = load_random_ascii()
|
||||
alpha.redraw()
|
||||
end
|
||||
|
||||
-- Setup buttons
|
||||
dashboard.section.buttons.val = {
|
||||
@@ -25,7 +62,16 @@ return {
|
||||
),
|
||||
}
|
||||
|
||||
-- Setup Alpha dashboard
|
||||
-- Setup Alpha initially
|
||||
dashboard.section.header.val = load_random_ascii()
|
||||
alpha.setup(dashboard.opts)
|
||||
|
||||
-- Auto-refresh header whenever Alpha is opened
|
||||
vim.api.nvim_create_autocmd('User', {
|
||||
pattern = 'AlphaReady',
|
||||
callback = function()
|
||||
refresh_header()
|
||||
end,
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user