alpha.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. local M = {}
  2. function M.config()
  3. local lvim_dashboard = require "lvim.core.alpha.dashboard"
  4. local lvim_startify = require "lvim.core.alpha.startify"
  5. lvim.builtin.alpha = {
  6. dashboard = { config = {}, section = lvim_dashboard.get_sections() },
  7. startify = { config = {}, section = lvim_startify.get_sections() },
  8. active = true,
  9. mode = "dashboard",
  10. }
  11. end
  12. local function resolve_buttons(theme_name, entries)
  13. local selected_theme = require("alpha.themes." .. theme_name)
  14. local val = {}
  15. for _, entry in pairs(entries) do
  16. local on_press = function()
  17. local sc_ = entry[1]:gsub("%s", ""):gsub("SPC", "<leader>")
  18. local key = vim.api.nvim_replace_termcodes(sc_, true, false, true)
  19. vim.api.nvim_feedkeys(key, "normal", false)
  20. end
  21. local button_element = selected_theme.button(entry[1], entry[2], entry[3])
  22. -- this became necessary after recent changes in alpha.nvim (06ade3a20ca9e79a7038b98d05a23d7b6c016174)
  23. button_element.on_press = on_press
  24. table.insert(val, button_element)
  25. end
  26. return val
  27. end
  28. local function resolve_config(theme_name)
  29. local selected_theme = require("alpha.themes." .. theme_name)
  30. local resolved_section = selected_theme.section
  31. local section = lvim.builtin.alpha[theme_name].section
  32. for name, el in pairs(section) do
  33. for k, v in pairs(el) do
  34. if name:match "buttons" and k == "entries" then
  35. resolved_section[name].val = resolve_buttons(theme_name, v)
  36. elseif v then
  37. resolved_section[name][k] = v
  38. end
  39. end
  40. end
  41. return selected_theme.config
  42. end
  43. local function configure_additional_autocmds()
  44. local group = "_dashboard_settings"
  45. vim.api.nvim_create_augroup(group, {})
  46. vim.api.nvim_create_autocmd("FileType", {
  47. group = group,
  48. pattern = "alpha",
  49. command = "set showtabline=0 | autocmd BufLeave <buffer> set showtabline=" .. vim.opt.showtabline._value,
  50. })
  51. if not lvim.builtin.lualine.options.globalstatus then
  52. -- https://github.com/goolord/alpha-nvim/issues/42
  53. vim.api.nvim_create_autocmd("FileType", {
  54. group = group,
  55. pattern = "alpha",
  56. command = "set laststatus=0 | autocmd BufUnload <buffer> set laststatus=" .. vim.opt.laststatus._value,
  57. })
  58. end
  59. end
  60. function M.setup()
  61. local alpha = require "alpha"
  62. local mode = lvim.builtin.alpha.mode
  63. local config = lvim.builtin.alpha[mode].config
  64. -- this makes it easier to use a completely custom configuration
  65. if vim.tbl_isempty(config) then
  66. config = resolve_config(mode)
  67. end
  68. alpha.setup(config)
  69. configure_additional_autocmds()
  70. end
  71. return M