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
|
|
|
|
2021-10-12 14:04:47 +00:00
|
|
|
---append new notice
|
|
|
|
---@param notice string|table table is a list of strings
|
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-10-12 14:04:47 +00:00
|
|
|
---appends persistent notice. These don't get cleared on setup
|
|
|
|
---@param notice string|table table is a list of strings
|
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-10-12 14:04:47 +00:00
|
|
|
---show setup :LuaLineNotices and show notification about error when there
|
|
|
|
---are notices available
|
2021-08-09 07:53:42 +00:00
|
|
|
function M.notice_message_startup()
|
2022-03-07 12:10:32 +00:00
|
|
|
if #notices > 0 or #persistent_notices > 0 then
|
2022-01-02 11:38:39 +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
|
|
|
|
|
2021-10-12 14:04:47 +00:00
|
|
|
---create notice view
|
2021-08-09 07:53:42 +00:00
|
|
|
function M.show_notices()
|
2022-01-02 11:38:39 +00:00
|
|
|
vim.cmd('silent! keepalt split')
|
2021-09-27 12:04:54 +00:00
|
|
|
|
2022-01-04 01:22:52 +00:00
|
|
|
local winid = vim.api.nvim_get_current_win()
|
2021-09-27 12:04:54 +00:00
|
|
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
|
|
|
vim.api.nvim_win_set_buf(winid, bufnr)
|
|
|
|
|
2021-09-27 12:06:25 +00:00
|
|
|
vim.wo[winid].winfixheight = true
|
|
|
|
vim.wo[winid].winfixwidth = true
|
|
|
|
vim.wo[winid].number = false
|
|
|
|
vim.wo[winid].foldcolumn = '0'
|
2021-09-27 12:04:54 +00:00
|
|
|
vim.wo[winid].relativenumber = false
|
2021-09-27 12:06:25 +00:00
|
|
|
vim.wo[winid].signcolumn = 'no'
|
|
|
|
vim.bo[bufnr].filetype = 'markdown'
|
2021-09-27 12:04:54 +00:00
|
|
|
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'q', '<Cmd>bd<CR>', { noremap = true, silent = true })
|
|
|
|
|
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-10-12 14:04:47 +00:00
|
|
|
vim.notify('Lualine Notices is already open in another buffer', vim.log.levels.ERROR, {})
|
2022-01-02 11:38:39 +00:00
|
|
|
vim.cmd('normal q')
|
2021-09-03 18:28:20 +00:00
|
|
|
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-09-27 12:04:54 +00:00
|
|
|
vim.fn.appendbufline(bufnr, 0, notice)
|
|
|
|
|
2022-01-02 11:38:39 +00:00
|
|
|
vim.fn.deletebufline(bufnr, #notice, vim.fn.line('$'))
|
2021-09-27 12:04:54 +00:00
|
|
|
vim.api.nvim_win_set_cursor(winid, { 1, 0 })
|
2021-09-27 12:06:25 +00:00
|
|
|
vim.bo[bufnr].modified = false
|
|
|
|
vim.bo[bufnr].modifiable = false
|
2021-08-09 07:53:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.clear_notices()
|
|
|
|
notices = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|