Line data Source code
1 1 : local M = {}
2 :
3 1 : function M.show()
4 4 : local output = vim.api.nvim_exec2("messages", { output = true }).output
5 4 : if not output or output == "" then
6 1 : vim.notify("No messages", vim.log.levels.INFO)
7 1 : return
8 : end
9 :
10 3 : local lines = vim.split(output, "\n")
11 3 : local buf = vim.api.nvim_create_buf(false, true)
12 3 : vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
13 6 : vim.bo[buf].modifiable = false
14 6 : vim.bo[buf].bufhidden = "wipe"
15 6 : vim.bo[buf].filetype = "messages"
16 :
17 6 : local width = math.min(120, vim.o.columns - 4)
18 6 : local height = math.min(#lines + 1, vim.o.lines - 4)
19 :
20 6 : local win = vim.api.nvim_open_win(buf, true, {
21 : relative = "editor",
22 3 : width = width,
23 3 : height = height,
24 6 : col = math.floor((vim.o.columns - width) / 2),
25 6 : row = math.floor((vim.o.lines - height) / 2),
26 : border = "rounded",
27 : title = " Messages ",
28 : title_pos = "center",
29 : })
30 :
31 6 : vim.wo[win].wrap = true
32 3 : vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = buf, desc = "Close messages" })
33 3 : vim.keymap.set("n", "<Esc>", "<cmd>close<cr>", { buffer = buf, desc = "Close messages" })
34 4 : end
35 :
36 1 : return M
|