nvim: refactor lualine component for searchcount

This commit is contained in:
Fernando Schauenburg 2025-03-25 21:07:39 +01:00
parent 14a0d8e7d2
commit f55e1b6951

View file

@ -6,22 +6,29 @@ function M:init(options)
vim.tbl_extend("keep", options or {}, {
maxcount = 999,
timeout = 250,
cond = function() return vim.v.hlsearch == 1 end,
})
)
end
function M:update_status()
if vim.v.hlsearch == 0 then return "" end
local denominator = function(tbl)
if tbl.total > tbl.maxcount then return "󰛤" end
return string.format("%d", tbl.total)
end
local count = vim.fn.searchcount {
local render = function(tbl)
local status = "?"
if not vim.tbl_isempty(tbl) and vim.v.hlsearch == 1 then
status = string.format("%d/%s", tbl.current, denominator(tbl))
end
return string.format(" %s", status)
end
function M:update_status()
return render(vim.fn.searchcount {
maxcount = self.options.maxcount,
timeout = self.options.timeout,
}
if next(count) == nil then return "" end
local denominator = count.total > count.maxcount and "󰛤"
or string.format("%d", count.total)
return string.format(" %d/%s", count.current, denominator)
})
end
return M