| 1 |
local M = require('lualine.component'):extend() |
| 2 |
|
| 3 |
local default_options = { |
| 4 |
maxcount = 999, |
| 5 |
timeout = 500, |
| 6 |
} |
| 7 |
|
| 8 |
-- Initializer |
| 9 |
function M:init(options) |
| 10 |
-- Run super() |
| 11 |
M.super.init(self, options) |
| 12 |
-- Apply default options |
| 13 |
self.options = vim.tbl_extend('keep', self.options or {}, default_options) |
| 14 |
end |
| 15 |
|
| 16 |
-- Function that runs every time statusline is updated |
| 17 |
function M:update_status() |
| 18 |
if vim.v.hlsearch == 0 then |
| 19 |
return '' |
| 20 |
end |
| 21 |
|
| 22 |
local ok, result = pcall(vim.fn.searchcount, { maxcount = self.options.maxcount, timeout = self.options.timeout }) |
| 23 |
if not ok or next(result) == nil then |
| 24 |
return '' |
| 25 |
end |
| 26 |
|
| 27 |
local denominator = math.min(result.total, result.maxcount) |
| 28 |
return string.format('[%d/%d]', result.current, denominator) |
| 29 |
end |
| 30 |
|
| 31 |
return M |