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

Using Highlight Groups rather than load_colors #78

Closed
mehalter opened this issue Oct 21, 2022 · 8 comments · Fixed by #157
Closed

Using Highlight Groups rather than load_colors #78

mehalter opened this issue Oct 21, 2022 · 8 comments · Fixed by #157

Comments

@mehalter
Copy link
Contributor

I have a quick question. I'm sure I must be doing something wrong... I am currently using load_colors to set up colors for Heirline and for a simple example, I am getting the fg and bg of the StatusLine and setting that as the hl variable manually with something like this:

bg = utils.get_highlight("StatusLine").bg,
fg = utils.get_highlight("StatusLine").fg,

And then setting them as the topmost level hl with hl = { fg = "fg", bg = "bg" }. This works great but I am trying to move this to using the highlight group notation with strings, but when I do hl = "StatusLine" I am getting different results. I have verified that the StatusLine highlight group I have in my theme only sets fg and bg and doesn't set anything like reverse = true or anything, but this is what I'm getting:

With hl = { fg = "fg", bg = "bg" }:

2022-10-21_09:13:48_screenshot

With hl = "StatusLine":

2022-10-21_09:14:25_screenshot

It seems to me like for some reason when I use the hlgroup notation the colors get reversed as well as bolded. I did some testing and this is what I get when I do hl = { fg = "fg", bg = "bg", reverse = true }:

2022-10-21_09:15:28_screenshot

hl = { fg = "fg", bg = "bg", reverse = true, bold = true }:

2022-10-21_09:16:34_screenshot

Is there any reason for this to be happening or something I might be doing incorrectly?

@mehalter
Copy link
Contributor Author

Hm as I opened this I am starting to think this is a problem with my surround function for some reason. I am investigating this currently

@mehalter
Copy link
Contributor Author

I guess I'm still confused why changing a global highlight group from a manual definition to the hlgroup string definition would change behavior if they should be resolving to the same set of highlights. So maybe this is something else and not my own fault 🤔

@mehalter
Copy link
Contributor Author

I think this has to do with the colors not updating when you reload the colorscheme. For example, if I do this:

hl = utils.get_highlight("StatusLine")

I get the same results as hl = "StatusLine"

but if I do

hl = function() return utils.get_highlight("StatusLine") end

it works as expected.

@rebelot
Copy link
Owner

rebelot commented Oct 21, 2022

When you use hl = "HlName" heirline calls utils.get_highlight at evaluation to be able to merge the highlight with the parent, so it will always pick up hl defined in the current theme.

When you use hl = utils.get_highlight("HlName") you are "hard coding" the returned values in the component definition, which are only valid for the current theme.

As you found out, wrapping it into a function allows re-evaluation of 'get_highlight` and updates correctly on colorscheme changes (as long as the hlgroup exists in the new theme).

The best way to ensure consistency on colorscheme changes is to never use the result of utils.get_highlight directly, instead, wrap it into a function, use hlgroups names directly, or use color name aliases defined in setup_colors with the instruction in the cookbook #theming.

Is there anything you think I could do?

@mehalter
Copy link
Contributor Author

Hm, I guess I'm wondering why it doesn't seem to work correctly when I use the hlgroup name directly. Do you have any idea why that would be?

@mehalter
Copy link
Contributor Author

The simplest example that illustrates this is

require("heirline").setup({ hl = "StatusLine", provider = "Hello, World!" })

@mehalter
Copy link
Contributor Author

This results in:

2022-10-21_13:32:14_screenshot

where if I specify the fg/bg directly or with the function calling get_highlight I get this:

require("heirline").setup({ hl = function() return utils.get_highlight("StatusLine") end, provider = "Hello, World!" })

2022-10-21_13:33:34_screenshot

@rebelot
Copy link
Owner

rebelot commented Oct 22, 2022

require("heirline").setup({ hl = "StatusLine", provider = "Hello, World!" })

gives me the expected result, unless I load heirline config before the intended colorscheme.

this is what I get with nvim --clean --cmd 'hi StatusLine'

Screenshot 2022-10-22 at 02 35 18

The strange thing is that, for some reason, bold and reverse get stuck within the component highlight logic... I will investigate

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

Successfully merging a pull request may close this issue.

2 participants