Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Custom refresh rate per component #1184

Open
Z3rio opened this issue Jan 20, 2024 · 4 comments
Open

Feat: Custom refresh rate per component #1184

Z3rio opened this issue Jan 20, 2024 · 4 comments
Labels
new feature New feature or feature request

Comments

@Z3rio
Copy link

Z3rio commented Jan 20, 2024

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 Z3rio added the new feature New feature or feature request label Jan 20, 2024
@ColinKennedy
Copy link

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

See

function M:draw()
self.status = ''
self.applied_separator = ''
if self.options.cond ~= nil and self.options.cond() ~= true then
return self.status
end
local status = self:update_status()
if type(status) == 'string' and #status > 0 then
self.status = status
self:apply_section_separators()
self:apply_separator()
end
return self.status
end

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
Copy link

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

@Z3rio
Copy link
Author

Z3rio commented May 9, 2024

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
Copy link

ColinKennedy commented May 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or feature request
Projects
None yet
Development

No branches or pull requests

2 participants