summaryrefslogtreecommitdiff
path: root/lua/lvim/core/notify.lua
blob: b08c45a633245f3e0440b586d169e8c55289899d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
local M = {}

local Log = require "lvim.core.log"

local defaults = {
  active = true,
  on_config_done = nil,
  opts = {
    ---@usage Animation style one of { "fade", "slide", "fade_in_slide_out", "static" }
    stages = "slide",

    ---@usage Function called when a new window is opened, use for changing win settings/config
    on_open = nil,

    ---@usage Function called when a window is closed
    on_close = nil,

    ---@usage timeout for notifications in ms, default 5000
    timeout = 5000,

    -- Render function for notifications. See notify-render()
    render = "default",

    ---@usage highlight behind the window for stages that change opacity
    background_colour = "Normal",

    ---@usage minimum width for notification windows
    minimum_width = 50,

    ---@usage Icons for the different levels
    icons = {
      ERROR = lvim.icons.diagnostics.Error,
      WARN = lvim.icons.diagnostics.Warning,
      INFO = lvim.icons.diagnostics.Information,
      DEBUG = lvim.icons.diagnostics.Debug,
      TRACE = lvim.icons.diagnostics.Trace,
    },
  },
}

function M.config()
  if not lvim.use_icons then
    defaults.opts.icons = {
      ERROR = "[ERROR]",
      WARN = "[WARNING]",
      INFO = "[INFO]",
      DEBUG = "[DEBUG]",
      TRACE = "[TRACE]",
    }
  end
  lvim.builtin.notify = vim.tbl_deep_extend("force", defaults, lvim.builtin.notify or {})
end

function M.setup()
  if #vim.api.nvim_list_uis() == 0 then
    -- no need to configure notifications in headless
    return
  end

  local opts = lvim.builtin.notify and lvim.builtin.notify.opts or defaults

  local status_ok, notify = pcall(require, "notify")
  if not status_ok then
    return
  end

  notify.setup(opts)
  vim.notify = notify
  Log:configure_notifications(notify)
end

return M