refactor(alpha): Use IIFE to inc. optimally

Increase performance by not sending unecessary objects like ascii_arts
and fortunes in the config.
This commit is contained in:
rajvatsal 2024-01-07 13:46:18 +05:30
parent 58b182d928
commit 589fb15094
1 changed files with 316 additions and 315 deletions

View File

@ -1,13 +1,6 @@
return { return (function()
'goolord/alpha-nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' }, -- removing fortune from dependencies fixed the highlighting(only for predefined highlights)
config = function()
local alpha = require("alpha")
local dashboard = require("alpha.themes.dashboard")
math.randomseed(os.time()) math.randomseed(os.time())
local _ascii_arts = {
local ascii_arts = {
kraken = { kraken = {
" ", " ",
" ", " ",
@ -268,19 +261,8 @@ return {
}, },
} }
dashboard.section.header.val = ascii_arts['pacman'] -- require("ascii").art.gaming.pacman['basic'] local _getFortune = function()
local _fortunes = {
-- Set menu
dashboard.section.buttons.val = {
dashboard.button("e", " New file", ":ene <BAR> startinsert <CR>"),
dashboard.button("r", " Recently used files", ":Telescope oldfiles<CR>"),
dashboard.button("f", " Find file", ":Telescope find_files<CR>"),
dashboard.button("t", " Find text", ":Telescope live_grep <CR>"),
dashboard.button("q", " Quit NVIM", ":qa<CR>"),
}
local getFortune = function()
local fortunes = {
' \nI\'m sick of following my dreams, man. I\'m just going\nto ask where they\'re going and hook up with em later.\n \n—Mitch Hedberg', ' \nI\'m sick of following my dreams, man. I\'m just going\nto ask where they\'re going and hook up with em later.\n \n—Mitch Hedberg',
' \nBefore you criticize someone, you should walk a mile in\ntheir shoes. That way when you criticize them, you are a\nmile away from them and you have their shoes. \n \n—Jack Handey', ' \nBefore you criticize someone, you should walk a mile in\ntheir shoes. That way when you criticize them, you are a\nmile away from them and you have their shoes. \n \n—Jack Handey',
'Before you marry a person, you should first make them use a computer with slow Internet to see who they really are. —Will Ferrell', 'Before you marry a person, you should first make them use a computer with slow Internet to see who they really are. —Will Ferrell',
@ -306,21 +288,40 @@ return {
' \nYou\'re everything I want in someone I don\'t want\nanymore.', ' \nYou\'re everything I want in someone I don\'t want\nanymore.',
' \nFriendships must be built on a solid foundation of\nalcohol, sarcasm, inappropriateness, and shenanigans.', ' \nFriendships must be built on a solid foundation of\nalcohol, sarcasm, inappropriateness, and shenanigans.',
} }
return fortunes[math.random(1, #fortunes)] return _fortunes[math.random(1, #_fortunes)]
end end
return {
'goolord/alpha-nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' }, -- removing fortune from dependencies fixed the highlighting(only for predefined highlights)
config = function()
local alpha = require("alpha")
local dashboard = require("alpha.themes.dashboard")
dashboard.section.header.val = _ascii_arts['pacman'] -- require("ascii").art.gaming.pacman['basic']
-- Set menu
dashboard.section.buttons.val = {
dashboard.button("e", " New file", ":ene <BAR> startinsert <CR>"),
dashboard.button("r", " Recently used files", ":Telescope oldfiles<CR>"),
dashboard.button("f", " Find file", ":Telescope find_files<CR>"),
dashboard.button("t", " Find text", ":Telescope live_grep <CR>"),
dashboard.button("q", " Quit NVIM", ":qa<CR>"),
}
-- Set footer -- Set footer
--[[local handle = assert(io.popen('fortune -s')) --[[local handle = assert(io.popen('fortune -s'))
local fortune = handle:read("*all") local fortune = handle:read("*all")
handle:close()]] handle:close()]]
dashboard.section.footer.val = getFortune() -- require('alpha.fortune')() dashboard.section.footer.val = require('alpha.fortune')()
dashboard.section.header.opts.hl = "Error" dashboard.section.header.opts.hl = "Error"
dashboard.section.buttons.opts.hl = "Debug" dashboard.section.buttons.opts.hl = "Debug"
dashboard.section.footer.opts.hl = "Constant" dashboard.section.footer.opts.hl = "NonText"
dashboard.config.opts.noautocmd = true dashboard.config.opts.noautocmd = true
vim.cmd [[autocmd User AlphaReady echo 'ready']] vim.cmd [[autocmd User AlphaReady echo 'ready']]
alpha.setup(dashboard.opts) alpha.setup(dashboard.opts)
end end
} }
end)()