Add: Load random ascii_arts from ascii_arts folder with a naming format of ascii_art_1/2/3/*

This commit is contained in:
psychhim
2025-10-15 21:52:27 +05:30
parent 8c389bc574
commit e2a7d8dbad
2 changed files with 51 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
local splash = {
' Now Use this device only: ',
' Now use this device only: ',
' ________________________________________________________________________________________________________',
'| Esc | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | |',
'|_______|______|______|______|______|______|______|______|______|______|______|______|________|__________|',

View File

@@ -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,
}