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:
		
							parent
							
								
									58b182d928
								
							
						
					
					
						commit
						589fb15094
					
				| 
						 | 
				
			
			@ -1,13 +1,6 @@
 | 
			
		|||
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")
 | 
			
		||||
 | 
			
		||||
return (function()
 | 
			
		||||
  math.randomseed(os.time())
 | 
			
		||||
 | 
			
		||||
    local ascii_arts = {
 | 
			
		||||
  local _ascii_arts = {
 | 
			
		||||
    kraken = {
 | 
			
		||||
      "                                   ",
 | 
			
		||||
      "                                   ",
 | 
			
		||||
| 
						 | 
				
			
			@ -268,19 +261,8 @@ return {
 | 
			
		|||
    },
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
    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>"),
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    local getFortune = function()
 | 
			
		||||
      local fortunes = {
 | 
			
		||||
  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',
 | 
			
		||||
      ' \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',
 | 
			
		||||
| 
						 | 
				
			
			@ -306,21 +288,40 @@ return {
 | 
			
		|||
      ' \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.',
 | 
			
		||||
    }
 | 
			
		||||
      return fortunes[math.random(1, #fortunes)]
 | 
			
		||||
    return _fortunes[math.random(1, #_fortunes)]
 | 
			
		||||
  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
 | 
			
		||||
      --[[local handle = assert(io.popen('fortune -s'))
 | 
			
		||||
    local fortune = handle:read("*all")
 | 
			
		||||
    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.buttons.opts.hl = "Debug"
 | 
			
		||||
    dashboard.section.footer.opts.hl = "Constant"
 | 
			
		||||
      dashboard.section.footer.opts.hl = "NonText"
 | 
			
		||||
      dashboard.config.opts.noautocmd = true
 | 
			
		||||
 | 
			
		||||
      vim.cmd [[autocmd User AlphaReady echo 'ready']]
 | 
			
		||||
 | 
			
		||||
      alpha.setup(dashboard.opts)
 | 
			
		||||
    end
 | 
			
		||||
}
 | 
			
		||||
  }
 | 
			
		||||
end)()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue