petertriho / nvim-scrollbar

Extensible Neovim Scrollbar
MIT License
869 stars 19 forks source link

Cannot see ScrollbarHandle in terminal neovim #21

Closed j-hui closed 2 years ago

j-hui commented 2 years ago

Describe the bug I'm unable to see the scrollbar handle.

To Reproduce Steps to reproduce the behavior:

  1. Install this plugin.
  2. Setup etc.
  3. Open a long file (in terminal/non-GUI nvim).
  4. No scrollbar shown.

Expected behavior I expect to see a scrollbar.

I noticed that this plugin highlights the scrollbar using the ScrollbarHandle highlight, which is defined here: https://github.com/petertriho/nvim-scrollbar/blob/main/lua/scrollbar/utils.lua#L29

However that does not set any terminal highlighting. It also clears my highlight link.

When I replace that line with a hardcoded string.format("highlight link %s StatusLine", M.get_highlight_name("", true)), I see the scrollbar. Though I'm not sure that's the best fix.

Version Info (please complete the following information):

:version
NVIM v0.6.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by runner@fv-az32-74

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/share/nvim"

Run :checkhealth for more info

I'm happy to suggest a PR if that's helpful.

petertriho commented 2 years ago

I'll have to investigate this further. I'm not sure how to check the highlights, but doing :highlight ScrollbarHandle works fine for me for term.

I don't use the neovim terminal at all, so I would appreciate some help on this. Once strange behaviour is that it seems like the scrollbar shows after enter normal mode in the terminal, so it could just be related to a missing autocmd. I've tried adding TermOpen but that doesn't seem to work.

Could also be related to https://github.com/petertriho/nvim-scrollbar/issues/20

levouh commented 2 years ago

It also clears my highlight link

One thing to note @petertriho, not sure its related at all, is how :h hi-default works. You don't have to check if the highlight exists; Vim will do this for you and then you are sure to not override user-defined highlights.

petertriho commented 2 years ago

@levouh thanks, I've added the default arguments to the highlights

j-hui commented 2 years ago

I figured out an issue on my end: my highlight wasn't resetting the highlight when my colorscheme changed. Something like this fixes it for me:

      augroup scrollbar-highlights
        autocmd!
        autocmd Colorscheme * highlight! link ScrollbarHandle StatusLine
      augroup END

By the way, is there a reason the term highlight is cleared instead of setting it to some default value? It would be great to be able to configure this somehow, or at least have ScrollbarHandle documented somewhere.

petertriho commented 2 years ago

There isn't anything clearing the highlights but the commit above should fix issues with defining your own highlights.

I definitely need to document a lot more things, like the highlights

j-hui commented 2 years ago

I'm referring to this: https://github.com/petertriho/nvim-scrollbar/blob/a2db95e775376f0d2e809162875a9617fb32cf4e/lua/scrollbar/utils.lua#L28-L35

Isn't the cterm highlight being set to NONE here? Only GUI highlights are being set to visible values.

petertriho commented 2 years ago

Ah ok, yes you're right, cterm colors aren't being set. Maybe I'll add a cterm config, so you can set that as well

Gelio commented 2 years ago

An alternative approach would be to link to an existing highlight instead of defining new highlights with the raw colors provided to setup. This is what is currently stopping me from using this plugin, since I am using https://github.com/sainnhe/gruvbox-material which does not expose raw colors programmatically.

With other plugins, e.g. lualine (https://github.com/Gelio/ubuntu-dotfiles/blob/01d2765ff8eef4f56b3659f22b2883dc35fd8f99/install/neovim/stowed/.config/nvim/lua/plugins.lua#L148-L153) or todo-comments (https://github.com/Gelio/ubuntu-dotfiles/blob/01d2765ff8eef4f56b3659f22b2883dc35fd8f99/install/neovim/stowed/.config/nvim/lua/plugins.lua#L238-L241) I am able to pass highlight names in their config. Those plugins then link to those highlights

image

or extract the colors themselves

image

With nvim-scrollbar, I would have to get the raw color used in the highlights of my colorscheme (using nvim_get_hl_by_name) only to pass it in the config so it creates the highlights again. Passing a highlight would let me skip extracting colors from the colorscheme and would let users link to any highlight they want, cterm or gui

I can create a separate issue if you'd like

btw. adding information in the README about being able to use nvim_get_hl_by_name to extract colors from existing highlights for colorschemes that do not export their palettes would be helpful. I spent several minutes looking for the right API :smile:

petertriho commented 2 years ago

@Gelio For now, you could just link the highlights. The highlights being used are

I intend to eventually add better defaults that use the currently defined highlights, but adding a way to define highlights is something I could add in the future.

Gelio commented 2 years ago

Sounds good!

For now I am using https://github.com/Gelio/ubuntu-dotfiles/blob/5121d579ffadd4e9829d9cdd2769f35ef3fbf680/install/neovim/stowed/.config/nvim/lua/plugins.lua#L732-L751 to extract the colors from existing highlights, which works good enough for me and is just slightly inconvenient, so no worries, I figured it out fortunately

Might be worth adding similar instructions to the README so other people know how to extract colors from highlights if their theme does not expose the raw hex values

j-hui commented 2 years ago

@Gelio I didn't know how to extract colors before; thanks for the tip!

I'm actually linking the highlighting here. But it's pretty cumbersome to have to do this in an autocmd.

@petertriho would you consider linking the highlight as default behavior? Links have a lower priority than group definitions: defining a group overrides an existing link, whereas attempting to create a link in the presence of a group leads to an error (when run from the ex-command line) or silent failure (when sourced from vimscript).

(Perhaps this is what you already meant by "add better defaults that use the currently defined highlights", but I just wanted to also share that perspective)

petertriho commented 2 years ago

@j-hui I was actually thinking it might be best to add:

j-hui commented 2 years ago

I just learned about termguicolors today; turning that on made the default configuration visible. Perhaps that could be mentioned in the README?

petertriho commented 2 years ago

You're right. I didn't realise that this wasn't on by default. The theme I use enables this. I'll definitely get around to adding that to the docs + cterm and highlights this weekend