Skip to content
This repository has been archived by the owner on Jul 5, 2022. It is now read-only.

Support show on winbar #99

Open
leaxoy opened this issue May 19, 2022 · 17 comments
Open

Support show on winbar #99

leaxoy opened this issue May 19, 2022 · 17 comments
Labels
documentation Improvements or additions to documentation

Comments

@leaxoy
Copy link

leaxoy commented May 19, 2022

neovim/neovim#17336 winbar ui has been merged into nightly, it's general to show the gps component, there is vscode example:
image
and neovim example:
image

@wookayin
Copy link
Contributor

wookayin commented May 19, 2022

You can simply configure winbar to use nvim-gps. nvim-gps is a statusline component, so how to use it for winbar, statusline, tabline, etc., is up to users or other plugins.

For example:

_G.gps_location = function()
  local gps = require "nvim-gps"
  return gps.is_available() and gps.get_location() or ""
end
vim.opt.winbar = "%{%v:lua.gps_location()%}"

Or via your favorite statusline/tabline plugin.

@rockyzhang24
Copy link

rockyzhang24 commented May 19, 2022

@wookayin Thanks for the code. However, winbar won't be updated automatically like what statusline does when we move cursor, so it seems we need to use autocmd CursorMoved * to update it.

@wookayin
Copy link
Contributor

wookayin commented May 19, 2022

However, winbar won't be updated automatically as statusline when we move cursor, so it seems we need to use autocmd CursorMoved * to update it.

@rockyzhang24 No, that's not correct and the above code works as you'd expect. Did you try them out?%{...%} expression means that the function will be called whenever needed (including after cursor update). Read the documentation::help statusline

@rockyzhang24
Copy link

rockyzhang24 commented May 19, 2022

@wookayin Yes, I know it works as expected and no bugs for statusline. I've been using this plugin for a long time.

Confirmed that this is a bug of the newly added winbar(see this neovim/neovim#17336 (comment)). I already opened an issue in the neovim repo (neovim/neovim#18645)

So far, until this winbar bug is fixed, we should use a piece of code like this:

_G.gps_location = function()
  local gps = require "nvim-gps"
  return gps.is_available() and gps.get_location() or ""
end

vim.opt.winbar = "%{%v:lua.gps_location()%}"

vim.api.nvim_create_autocmd ("CursorMoved", {
  pattern = '*',
  command = "set winbar=%{%v:lua.gps_location()%}",
})

@leaxoy
Copy link
Author

leaxoy commented May 20, 2022

Corner case, the winbar always shows even gps is not available.

Correct case
image

Wrong case
image

@rockyzhang24
Copy link

rockyzhang24 commented May 20, 2022

@leaxoy Use my code above and it works well currently. Because winbar won't be updated when you move your cursor (it's a bug and the PR solving it will be merged soon), thus you need the autocmd to refresh it. When that mentioned issue gets fixed, you can remove the autocmd part.

@emuel-vassallo
Copy link

emuel-vassallo commented May 20, 2022

@rockyzhang24 This causes Telescope to turn from looking like the first image to the second. Other than that, it works really great!
image
image

@rockyzhang24
Copy link

@emuel-vassallo Using the autocmd is just a temporary workaround to solve the winbar update issue I mentioned above and it causes this telescope side effect. Waiting for the fix (neovim/neovim#18646) to be merged, and then the autocmd will not be needed.

@rockyzhang24
Copy link

rockyzhang24 commented May 20, 2022

@emuel-vassallo Try to change the autocmd event to CursorHold to avoid it disrupting telescope windows.

@emuel-vassallo
Copy link

@emuel-vassallo Try to change the autocmd event to CursorHold to avoid it disrupting telescope windows.

@rockyzhang24 That works, thank you!

@SmiteshP
Copy link
Owner

Will add instructions in README on how to setup in winbar 👍🏽

@SmiteshP SmiteshP added the documentation Improvements or additions to documentation label May 22, 2022
@rockyzhang24
Copy link

@SmiteshP Great! You can wait until that PR fixing the update bug gets merged.

@max397574
Copy link

it's merged

@rockyzhang24
Copy link

rockyzhang24 commented May 22, 2022

Great. Then adding gps to winbar is the same with adding it to statusline. It's very handy. And this issue can be closed now.

@nghialm269

This comment was marked as off-topic.

@max397574
Copy link

perhaps open a new issue for that @nghialm269

@siduck
Copy link

siduck commented Jun 3, 2022

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

8 participants