mirror of
https://github.com/hyzendust/KickestEnd.nvim.git
synced 2026-02-15 09:21:12 +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:
@@ -1,5 +1,5 @@
|
|||||||
local splash = {
|
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 | |',
|
'| Esc | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | |',
|
||||||
'|_______|______|______|______|______|______|______|______|______|______|______|______|________|__________|',
|
'|_______|______|______|______|______|______|______|______|______|______|______|______|________|__________|',
|
||||||
@@ -5,9 +5,46 @@ return {
|
|||||||
local alpha = require 'alpha'
|
local alpha = require 'alpha'
|
||||||
local dashboard = require 'alpha.themes.dashboard'
|
local dashboard = require 'alpha.themes.dashboard'
|
||||||
|
|
||||||
-- Load ASCII splash
|
-- Load random ASCII arts
|
||||||
local splash = require 'ascii_splash'
|
-- Keep track of last shown ASCII art
|
||||||
dashboard.section.header.val = splash
|
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
|
-- Setup buttons
|
||||||
dashboard.section.buttons.val = {
|
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)
|
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,
|
end,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user