lualine.nvim icon indicating copy to clipboard operation
lualine.nvim copied to clipboard

Feat: Custom refresh rate per component

Open Z3rio opened this issue 1 year ago • 4 comments

Requested feature

It would be nice to either have a custom refresh rate for specifically defined components Or, have a way to disable refreshing for a component and require manually calling the lualine refresh function

Motivation

Some tasks are more intensive then others, and therefore might not want to be ran as often as everything else

Z3rio avatar Jan 20 '24 21:01 Z3rio

To anyone looking for a stop-gap, it's possible to control when the component updates

See https://github.com/nvim-lualine/lualine.nvim/blob/0a5a66803c7407767b799067986b4dc3036e1983/lua/lualine/components/buffers/init.lua#L205-L219

You can't control the refresh rate, maybe, but you can tell the component to reuse a previous computation and only compute in limited situations. e.g. something like

function M:draw()
  if not self._needs_refresh then
    return self.status
  end

  local status = self:update_status()
  self._needs_refresh = false

  if status then
    status = " " .. status .. " "
  end

  self.status = status

  return self.status
end

self._needs_refresh would need to be controlled elsewhere. You could probably use a vim.uv.timer() to hijack the refresh rate to call self:update_status at a slower-than-normal speed.

Ideally though I'd like a directly tell lualine to refresh from within the component so that lualine updates immediately. As it is, my code is ready immediately but there's still a delay from when the code runs self:update_status and the user sees the change on-screen.

ColinKennedy avatar May 09 '24 05:05 ColinKennedy

Actually I think you can refresh lualine with require("lualine").refresh() and it updates immediately!

ColinKennedy avatar May 09 '24 05:05 ColinKennedy

Hiya @ColinKennedy thank you for your comment. I'm a bit unsure if we both mean the same thing though.

The issue atm is that the same refresh rate is used for all components. Whereas it would be nice to be able to define specific refresh rates for specific components.

I know you can manually cache the draw response, which is something I've done. But its still not really ideal. Modifying the core lualine plugin isn't really ideal either (without PRing it), as most plugin managers would overwrite those changes unless you actually create your own fork and so on.

I am also indeed aware that the refresh function exists, but afaik that would not in any way shape, or form resolve this. As a matter a fact it would just make the issue even worse as it would update even more frequently if you use that.

Please feel free to correct me if I'm incorrect, as I haven't used this plugin since the post of this issue.

Z3rio avatar May 09 '24 11:05 Z3rio

My suggestions weren't in direct response to your question about altering the refresh rate, just some strategies in case others looking for similar things can do without. That's why I called it it a stop-gap.

FWIW if your needs is to refresh slower than normal then you could use a uv timer + custom draw to achieve. Buf if you need faster than normal refreshing I'm not sure how that'd be achievable.

ColinKennedy avatar May 09 '24 15:05 ColinKennedy