2023-03-30 05:30:15 +00:00
|
|
|
local M = require('lualine.component'):extend()
|
|
|
|
|
|
|
|
local default_options = {
|
|
|
|
maxcount = 999,
|
|
|
|
timeout = 500,
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Initializer
|
|
|
|
function M:init(options)
|
|
|
|
-- Run super()
|
|
|
|
M.super.init(self, options)
|
|
|
|
-- Apply default options
|
|
|
|
self.options = vim.tbl_extend('keep', self.options or {}, default_options)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Function that runs every time statusline is updated
|
|
|
|
function M:update_status()
|
2022-10-19 09:06:45 +00:00
|
|
|
if vim.v.hlsearch == 0 then
|
2022-10-19 09:07:21 +00:00
|
|
|
return ''
|
2022-10-19 09:06:45 +00:00
|
|
|
end
|
|
|
|
|
2023-03-30 05:30:15 +00:00
|
|
|
local result = vim.fn.searchcount { maxcount = self.options.maxcount, timeout = self.options.timeout }
|
2023-04-03 10:41:41 +00:00
|
|
|
if next(result) == nil then
|
|
|
|
return ''
|
|
|
|
end
|
|
|
|
|
2022-10-19 09:06:45 +00:00
|
|
|
local denominator = math.min(result.total, result.maxcount)
|
2022-10-19 09:07:21 +00:00
|
|
|
return string.format('[%d/%d]', result.current, denominator)
|
2022-10-19 09:06:45 +00:00
|
|
|
end
|
|
|
|
|
2023-03-30 05:30:15 +00:00
|
|
|
return M
|