34 lines
776 B
Lua
34 lines
776 B
Lua
local M = require("lualine.component"):extend()
|
|
|
|
function M:init(options)
|
|
M.super.init(
|
|
self,
|
|
vim.tbl_extend("keep", options or {}, {
|
|
maxcount = 999,
|
|
timeout = 250,
|
|
cond = function() return vim.v.hlsearch == 1 end,
|
|
})
|
|
)
|
|
end
|
|
|
|
local denominator = function(tbl)
|
|
if tbl.total > tbl.maxcount then return "" end
|
|
return string.format("%d", tbl.total)
|
|
end
|
|
|
|
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,
|
|
})
|
|
end
|
|
|
|
return M
|