Copy 'Fidget history' output
As the title says, how one can copy that ouput?
Unfortunately, for now, that's not supported (I just use the text copying feature from my terminal). :Fidget history (and indeed all of Fidget's usercommand system) could use a lot of work.
When using a GUI client like Neovide, I guess there's just no way around it 😕
I was also looking for a way to solve this and have resorted to writing a helper function that shows the history in a new buffer. It does not filter and doesnt do highlighting though.
local fidget = require("fidget")
local function show_fidget_history_buf()
local history_items = fidget.notification.get_history()
if not history_items or #history_items == 0 then
vim.notify("No fidget history available", vim.log.levels.WARN)
return
end
-- Create buffer
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_set_option_value("buftype", "nofile", { buf = buf })
vim.api.nvim_set_option_value("bufhidden", "wipe", { buf = buf })
vim.api.nvim_set_option_value("modifiable", false, { buf = buf })
local lines = { "=== Fidget Notification History ===", "" }
for _, item in ipairs(history_items) do
local timestamp = vim.fn.strftime("%c", item.last_updated)
local group_part = item.group_name and (" " .. item.group_name) or ""
local annote_part = item.annote and (" [" .. item.annote .. "]") or ""
table.insert(lines, timestamp .. group_part .. " |" .. annote_part)
-- Handle multiline messages
for msg_line in vim.gsplit(item.message, "\n", { plain = true, trimempty = false }) do
table.insert(lines, " " .. msg_line)
end
table.insert(lines, "")
end
vim.api.nvim_set_option_value("modifiable", true, { buf = buf })
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
vim.api.nvim_set_option_value("modifiable", false, { buf = buf })
vim.cmd("split")
vim.api.nvim_win_set_buf(0, buf)
vim.api.nvim_buf_set_name(buf, "fidget://history")
local opts = { buffer = buf, noremap = true, silent = true }
vim.keymap.set("n", "q", "<cmd>close<cr>", opts)
vim.keymap.set("n", "<esc>", "<cmd>close<cr>", opts)
end
i add highlighting and i make use render markdown for the rest the text
local fidget = require("fidget")
local function show_fidget_history_buf()
local history_items = fidget.notification.get_history()
if not history_items or #history_items == 0 then
vim.notify("No fidget history available", vim.log.levels.WARN)
return
end
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_set_option_value("buftype", "nofile", { buf = buf })
vim.api.nvim_set_option_value("bufhidden", "wipe", { buf = buf })
vim.api.nvim_set_option_value("filetype", "markdown", { buf = buf })
local lines = {
"== Fidget Notification History ==",
"",
}
local highlights = {}
for _, item in ipairs(history_items) do
local lnum = #lines
local timestamp = vim.fn.strftime("%c", item.last_updated)
local group = item.group_name or "Notifications"
local icon = item.annote or "ℹ"
local header =
"(" .. timestamp .. ") "
.. group
.. " | ["
.. icon
.. "]"
table.insert(lines, header)
-- timestamp (grey)
table.insert(highlights, {
line = lnum,
start = 0,
finish = #timestamp + 2,
group = "Comment",
})
-- group name (pink)
local group_start = header:find(group, 1, true) - 1
table.insert(highlights, {
line = lnum,
start = group_start,
finish = group_start + #group,
group = "String",
})
-- icon highlight
local icon_start = header:find("%[", 1) - 1
local icon_hl = "DiagnosticInfo"
if icon:find("") then
icon_hl = "DiagnosticWarn"
elseif icon:find("") then
icon_hl = "DiagnosticError"
end
table.insert(highlights, {
line = lnum,
start = icon_start,
finish = #header,
group = icon_hl,
})
-- message body
for msg_line in vim.gsplit(item.message, "\n", { plain = true }) do
table.insert(lines, " " .. msg_line)
end
table.insert(lines, "")
end
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
-- Apply highlights
for _, hl in ipairs(highlights) do
vim.api.nvim_buf_add_highlight(
buf,
-1,
hl.group,
hl.line,
hl.start,
hl.finish
)
end
vim.cmd("split")
vim.api.nvim_win_set_buf(0, buf)
vim.api.nvim_buf_set_name(buf, "fidget://history.md")
local opts = { buffer = buf, noremap = true, silent = true }
vim.keymap.set("n", "q", "<cmd>close<cr>", opts)
end