alpha.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. function M.setup()
  44. local alpha = require "alpha"
  45. local mode = lvim.builtin.alpha.mode
  46. local config = lvim.builtin.alpha[mode].config
  47. -- this makes it easier to use a completely custom configuration
  48. if vim.tbl_isempty(config) then
  49. config = resolve_config(mode)
  50. end
  51. alpha.setup(config)
  52. end
  53. return M