nvim-lualine / lualine.nvim

A blazing fast and easy to configure neovim statusline plugin written in pure lua.
MIT License
5.72k stars 455 forks source link

Feat: Custom refresh rate per component #1184

Open Z3rio opened 5 months ago

Z3rio commented 5 months ago

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

ColinKennedy commented 2 months ago

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 commented 2 months ago

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

Z3rio commented 2 months ago

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.

ColinKennedy commented 2 months ago

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.