2021-09-20 11:46:38 +00:00
|
|
|
-- Copyright (c) 2020-2021 shadmansaleh
|
|
|
|
-- MIT license, see LICENSE for more details.
|
|
|
|
|
2021-08-09 07:53:42 +00:00
|
|
|
-- To provide notices for user
|
|
|
|
local M = {}
|
|
|
|
local notices = {}
|
2021-09-14 15:14:23 +00:00
|
|
|
local persistent_notices = {}
|
2021-08-09 07:53:42 +00:00
|
|
|
|
|
|
|
function M.add_notice(notice)
|
2021-09-03 18:28:20 +00:00
|
|
|
if type(notice) == 'string' then
|
|
|
|
notice = vim.split(notice, '\n')
|
|
|
|
end
|
2021-08-09 07:53:42 +00:00
|
|
|
table.insert(notices, notice)
|
|
|
|
end
|
|
|
|
|
2021-09-14 15:14:23 +00:00
|
|
|
function M.add_persistent_notice(notice)
|
|
|
|
if type(notice) == 'string' then
|
|
|
|
notice = vim.split(notice, '\n')
|
|
|
|
end
|
|
|
|
if not vim.tbl_contains(persistent_notices, notice) then
|
|
|
|
table.insert(persistent_notices, notice)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-09 07:53:42 +00:00
|
|
|
function M.notice_message_startup()
|
2021-09-14 15:14:23 +00:00
|
|
|
if #notices > 0 or #persistent_notices then
|
2021-09-03 18:28:20 +00:00
|
|
|
vim.cmd 'command! -nargs=0 LualineNotices lua require"lualine.utils.notices".show_notices()'
|
2021-08-09 07:53:42 +00:00
|
|
|
vim.schedule(function()
|
|
|
|
vim.notify(
|
2021-09-03 18:28:20 +00:00
|
|
|
'lualine: There are some issues with your config. Run :LualineNotices for details',
|
|
|
|
vim.log.levels.WARN,
|
|
|
|
{}
|
|
|
|
)
|
2021-08-09 07:53:42 +00:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.show_notices()
|
|
|
|
vim.cmd [[
|
|
|
|
:silent! new
|
|
|
|
:silent! setl ft=markdown bt=nofile nobuflisted bh=wipe
|
|
|
|
:silent! nnoremap <silent><buffer> q <cmd>bd<cr>
|
|
|
|
:silent! normal ggdG
|
|
|
|
]]
|
2021-09-03 18:28:20 +00:00
|
|
|
local ok, _ = pcall(vim.api.nvim_buf_set_name, 0, 'Lualine Notices')
|
2021-08-09 07:53:42 +00:00
|
|
|
if not ok then
|
2021-09-03 18:28:20 +00:00
|
|
|
vim.notify('Lualine Notices is already open in another window', vim.log.levels.ERROR, {})
|
|
|
|
vim.cmd 'normal q'
|
|
|
|
return
|
2021-08-09 07:53:42 +00:00
|
|
|
end
|
2021-09-14 15:14:23 +00:00
|
|
|
local notice = vim.tbl_flatten(persistent_notices)
|
|
|
|
notice = vim.list_extend(notice, vim.tbl_flatten(notices))
|
2021-08-09 07:53:42 +00:00
|
|
|
vim.fn.append(0, notice)
|
2021-09-03 18:28:20 +00:00
|
|
|
vim.api.nvim_win_set_cursor(0, { 1, 0 })
|
2021-08-09 07:53:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.clear_notices()
|
|
|
|
notices = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|