goolord / alpha-nvim

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

Can not call Alpha from buffer if Terminal is used in Alpha. #275

Open FahimAnayet opened 5 months ago

FahimAnayet commented 5 months ago

I use terminal as header option in Alpha. It works fine. But when I leave alpha and on some point I want to go back to alpha the following error appears. This problem was bugging me for a long time. But I thought I did any mistakes. If the problem was on my config please correct me. My config is given below. And yes If I do not use terminal no problem appears at all. And thank you for this fast beautiful plugin, really appreciate your work.

  ❌ Error  14:48:11 msg_show.lua_error Error executing Lua callback: ...yet/.local/share/nvim/lazy/alpha-nvim/lua/alpha/term.lua:72: Invalid window id: 1001
stack traceback:
    [C]: in function 'nvim_win_get_config'
    ...yet/.local/share/nvim/lazy/alpha-nvim/lua/alpha/term.lua:72: in function 'reposition'
    ...yet/.local/share/nvim/lazy/alpha-nvim/lua/alpha/term.lua:85: in function <...yet/.local/share/nvim/lazy/alpha-nvim/lua/alpha/term.lua:79>
    ...imanayet/.local/share/nvim/lazy/alpha-nvim/lua/alpha.lua:389: in function 'layout'
    ...imanayet/.local/share/nvim/lazy/alpha-nvim/lua/alpha.lua:629: in function 'draw'
    ...imanayet/.local/share/nvim/lazy/alpha-nvim/lua/alpha.lua:723: in function 'start'
    ...imanayet/.local/share/nvim/lazy/alpha-nvim/lua/alpha.lua:750: in function <...imanayet/.local/share/nvim/lazy/alpha-nvim/lua/alpha.lua:749>
-- Setup terminal header
require("alpha.term")
local term_height = 5
local logo1 = {
    type = "terminal",
    command = "cxxmatrix -m 'Neo VIM' --preserve-background",
    width = 50,
    height = term_height,
    opts = {
        position = "center",
        redraw = true,
        window_config = {},
    },
}

local logo = {
    type = "terminal",
    command = "tmatrix -t 'NeoVim' -c default",
    -- command = "pipes.sh",
    width = 50,
    height = term_height,
    opts = {
        redraw = true,
        position = "center",
    }
}

local info = {
    type = "text",
    val = function()
        local stat = require("lazy").stats()
        local v = vim.version()
        local res = { string.format(
            "󰂖 %d total  %d loaded  %s ms  v%d.%d.%d",
            stat.count,
            stat.loaded,
            stat.startuptime,
            v.major,
            v.minor,
            v.patch
        ) }
        return res
    end,
    opts = {
        position = "center",
        hl = "Type",
    },
}

local function configure()
    local theme = require("alpha.themes.theta")
    local themeconfig = theme.config
    local dashboard = require("alpha.themes.dashboard")
    local mru_files = {
        type = "group",
        val = function()
            return {
                { type = "text",    val = "Recent Files", opts = { hl = "SpecialComment", position = "center" } },
                { type = "padding", val = 1 },
                theme.mru(0, cdir, 5)
            }
        end,
        opts = { shrink_margin = false },
    }
    local buttons = {
        type = "group",
        val = {
            { type = "text",    val = "Quick links", opts = { hl = "SpecialComment", position = "center" } },
            { type = "padding", val = 1 },
            dashboard.button("i", "  New file", "<cmd>ene | startinsert <CR>"),
            dashboard.button("f", "󰈞  Find file", "<cmd>lua require('fzf-lua').files()<CR>"),
            dashboard.button("r", "󰋚  Recent files", "<cmd>lua require('fzf-lua').oldfiles()<CR>"),
            dashboard.button("c", "  Configuration", "<cmd>e ~/.config/nvim/plugin/settings.lua <CR>"),
            dashboard.button("q", "󰯆  Quit", "<cmd>qa<CR>"),
            { type = "padding", val = 1 },
        },
        position = "center",
    }

    themeconfig.layout[2] = logo1
    themeconfig.layout[4] = mru_files
    themeconfig.layout[6] = buttons
    themeconfig.layout[7] = info

    return themeconfig
end

vim.api.nvim_create_autocmd("User", {
    callback = function()
        pcall(vim.cmd.AlphaRedraw)
    end,
})

require 'alpha'.setup(configure())

This is on the startup. And expected behaviour every time.

This is when I call Alpha from any buffer. [NB. I try changing terminal command to just echo 'hi' thinking that was the problem. But nope.] Actual behaviour. Screen Shot 2024-04-09 at 3 22 15 PM

lfilho commented 5 months ago

Same problem here. Initial homescreen/dashboard loads fine with my terminal as a ascii art header. Then I open a file, then if I try to open the dashboard again, the error above is given.

I'm using LazyVim and configuring it like so:

  {
    "goolord/alpha-nvim",
    opts = function()
      require("alpha")
      require("alpha.term")
      local dashboard = require("alpha.themes.dashboard")
      dashboard.section.buttons.val = {
        dashboard.button("f", " " .. " Find file", ":Telescope find_files <CR>"),
        dashboard.button("w", " " .. " Find text", ":Telescope live_grep <CR>"),
        dashboard.button("n", " " .. " New file", ":ene <BAR> startinsert <CR>"),
        dashboard.button("o", " " .. " Recent files", ":Telescope oldfiles <CR>"),
        dashboard.button("m", " " .. " Bookmarks", ":Telescope marks <CR>"),
        dashboard.button("c", " " .. " Config", ":e $MYVIMRC <CR>"), 
        dashboard.button("s", " " .. " Load last session", ":SessionManager load_last_session<CR>"),
        dashboard.button("l", " " .. " Lazy", ":Lazy<CR>"),
        dashboard.button("q", " " .. " Quit", ":qa<CR>"),
      }
      for _, button in ipairs(dashboard.section.buttons.val) do
        button.opts.hl = "AlphaButtons"
        button.opts.hl_shortcut = "AlphaShortcut"
      end
      dashboard.section.footer.opts.hl = "Type"
      dashboard.section.header.opts.hl = "AlphaShortcut"
      dashboard.section.buttons.opts.hl = "AlphaButtons"

      local width = 46
      local height = 25 -- two pixels per vertical space
      dashboard.section.terminal.command = "cat | " .. os.getenv("HOME") .. "/.config/nvim/art/this-is-fine.sh"
      dashboard.section.terminal.width = width
      dashboard.section.terminal.height = height
      dashboard.section.terminal.opts.redraw = true

      dashboard.section.header.val = "🔥 Welcome back! This is gonna be fine! 🔥"

      dashboard.config.layout = {
        {
          type = "padding",
          val = 1,
        },
        dashboard.section.terminal,
        {
          type = "padding",
          val = 8,
        },
        dashboard.section.header,
        {
          type = "padding",
          val = 2,
        },
        dashboard.section.buttons,
        {
          type = "padding",
          val = 1,
        },
        dashboard.section.footer,
      }

      return dashboard
    end,
  },