goolord / alpha-nvim

a lua powered greeter like vim-startify / dashboard-nvim
MIT License
1.87k stars 112 forks source link

Cannot set dashboard.section.terminal #257

Closed Asthestarsfalll closed 8 months ago

Asthestarsfalll commented 8 months ago

I attempt to add a terminal on dashboard, but it occurs an error:

Error executing lua callback: /home/xxx/.local/share/nvim/lazy/alpha-nvim/lua/alpha.lua:389: attempt to call a nil value
stack traceback:
        /home/xxx/.local/share/nvim/lazy/alpha-nvim/lua/alpha.lua:389: in function 'layout'
        /home/xxx/.local/share/nvim/lazy/alpha-nvim/lua/alpha.lua:630: in function 'draw'
        /home/xxx/.local/share/nvim/lazy/alpha-nvim/lua/alpha.lua:724: in function 'start'
        /home/xxx/.config/nvim/lua/astronvim/autocmds.lua:248: in function </home/xxx/.config/nvim/lua/astronvim/autocmds.lua:228>

My config:

return {
  "goolord/alpha-nvim",
  cmd = "Alpha",
  opts = function()
    local dashboard = require "alpha.themes.dashboard"

    dashboard.opts.opts.noautocmd = true
    dashboard.section.terminal.command = "cat " .. os.getenv "HOME" .. "/.config/nvim/lua/user/plugins/Lucy.txt"
    dashboard.section.terminal.width = 20
    dashboard.section.terminal.height = 20
    dashboard.section.terminal.opts.redraw = true

    dashboard.opts.layout = {
      { type = "padding", val = 4 },
      dashboard.section.terminal,
      { type = "padding", val = 4 },
      dashboard.section.buttons,
      dashboard.section.footer,
    }

    return dashboard
  end,
  config = function(_, opts)
    require("alpha").setup(opts.config)

    vim.api.nvim_create_autocmd("User", {
      pattern = "LazyVimStarted",
      desc = "Add Alpha dashboard footer",
      once = true,
      callback = function()
        local stats = require("lazy").stats()
        local ms = math.floor(stats.startuptime * 100 + 0.5) / 100
        opts.section.footer.val = { " ", " ", " ", "Loaded " .. stats.count .. " plugins  in " .. ms .. "ms" }
        opts.section.footer.opts.hl = "DashboardFooter"
        pcall(vim.cmd.AlphaRedraw)
      end,
    })
  end,
}

Have I done something wrong? How can I resolve this issue? Thank you in advance for your help!

goolord commented 8 months ago

https://github.com/goolord/alpha-nvim/blob/4b36c1ca9ea475bdc006896657cf1ccc486aeffa/doc/alpha.txt#L168-L169

requiring "alpha.term" will fix this for you as per the docs, the alpha.term module functions as an extension