-- notifications cache _G.statusline_notifications = {} _G.statusline_notifications_archive = {} -- out vim.notify implementation local notify = function(m, l, o) local lvl_string = l local hi = nil if l and type(l) == 'number' then if l == vim.log.levels.TRACE then hi = 'deEmph' elseif l == vim.log.levels.DEBUG then hi = 'DiagnosticHint' elseif l == vim.log.levels.INFO then hi = 'DiagnosticInfo' elseif l == vim.log.levels.WARN then hi = 'DiagnosticWarn' elseif l == vim.log.levels.ERROR then hi = 'DiagnosticError' end -- get level string lvl_string = vim.lsp.log_levels[l] end local display = m if lvl_string then display = lvl_string .. ' ' .. display end table.insert(_G.statusline_notifications, { message = m, level = l, options = o, lvl_string = lvl_string, hi = hi, display = display, }) if _G.statusline_enable_notifysend then local args = {} if lvl_string then if lvl_string == 'ERROR' then table.insert(args, '--category=error') end if lvl_string == 'WARN' then table.insert(args, '--category=warning') end end table.insert(args, 'nvim') table.insert(args, display) require('internal.job').jobstart({ command = 'notify-send', args = args }) end end -- overwrite vim.notify vim.notify = function(m, l, o) if vim.in_fast_event() then vim.schedule(function() notify(m, l, o) end) else return notify(m, l, o) end end vim.keymap.set('n', 'n', function() local pickers = require('telescope.pickers') local finders = require('telescope.finders') local conf = require('telescope.config').values local actions = require('telescope.actions') -- local action_state = require('telescope.actions.state') -- local previewers = require('telescope.previewers') local opts = {} pickers .new(opts, { prompt_title = 'Notifications', finder = finders.new_dynamic({ fn = function() return _G.statusline_notifications_archive end, entry_maker = function(n) return { value = n, display = n.display, ordinal = n.message, } end, }), sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr, _) actions.select_default:replace(function() actions.close(prompt_bufnr) -- noop -- local sel = action_state.get_selected_entry() -- vim.notify(sel.value.message, sel.value.level, sel.value.options) end) return true end, -- previewer = previewers.new_buffer_previewer { -- define_preview = function(self, entry) -- vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, {entry.value.display}) -- end, -- }, }) :find() end, { desc = 'notifications' })