notify.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. local M = {}
  2. local Log = require "lvim.core.log"
  3. local defaults = {
  4. active = false,
  5. on_config_done = nil,
  6. opts = {
  7. ---@usage Animation style one of { "fade", "slide", "fade_in_slide_out", "static" }
  8. stages = "slide",
  9. ---@usage Function called when a new window is opened, use for changing win settings/config
  10. on_open = nil,
  11. ---@usage Function called when a window is closed
  12. on_close = nil,
  13. ---@usage timeout for notifications in ms, default 5000
  14. timeout = 5000,
  15. -- Render function for notifications. See notify-render()
  16. render = "default",
  17. ---@usage highlight behind the window for stages that change opacity
  18. background_colour = "Normal",
  19. ---@usage minimum width for notification windows
  20. minimum_width = 50,
  21. ---@usage Icons for the different levels
  22. icons = {
  23. ERROR = lvim.icons.diagnostics.Error,
  24. WARN = lvim.icons.diagnostics.Warning,
  25. INFO = lvim.icons.diagnostics.Information,
  26. DEBUG = lvim.icons.diagnostics.Debug,
  27. TRACE = lvim.icons.diagnostics.Trace,
  28. },
  29. },
  30. }
  31. function M.config()
  32. if not lvim.use_icons then
  33. defaults.opts.icons = {
  34. ERROR = "[ERROR]",
  35. WARN = "[WARNING]",
  36. INFO = "[INFO]",
  37. DEBUG = "[DEBUG]",
  38. TRACE = "[TRACE]",
  39. }
  40. end
  41. lvim.builtin.notify = vim.tbl_deep_extend("force", defaults, lvim.builtin.notify or {})
  42. end
  43. function M.setup()
  44. if #vim.api.nvim_list_uis() == 0 then
  45. -- no need to configure notifications in headless
  46. return
  47. end
  48. local opts = lvim.builtin.notify and lvim.builtin.notify.opts or defaults
  49. local notify = require "notify"
  50. notify.setup(opts)
  51. vim.notify = notify
  52. Log:configure_notifications(notify)
  53. end
  54. return M