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

Investigate light-on-light syntax highlight in default boot of Neovim #4

Open
2 tasks
cognivore opened this issue Feb 2, 2025 · 7 comments
Open
2 tasks

Comments

@cognivore
Copy link

Why?

Some people use light colour themes, for instance, with stylix / base16.
Hardcoded light syntax highlight for terms makes it unusable.
Note that when one presses ub, tokio themes override system theme.

Image
The pkgs is always light grey, even if the system theme is light. Here it's readable because the I switched the theme to dark

What?

  • Check that it's indeed hardcoded
  • Respect system theme in all the colour theme elements
@niksingh710
Copy link
Owner

If I understand correctly, <leader>ub toggles the light theme but overrides the current theme and switches back to the Tokyo theme, rather than the theme set by the user (e.g., Stylix overrides).

<leader>ub uses the Snacks API to toggle between light and dark modes. I believe Snacks.nvim switches to a light theme if the current theme has a light variant. However, if the current theme does not have a light variant, it falls back to a theme that does. When toggling back to dark mode, it switches to the dark variant of the fallback theme.

Could you test the following to confirm?

  1. Run :colorscheme habamax.
  2. Toggle light mode with <leader>ub.
  3. Toggle dark mode with <leader>ub again.

Does it stay on habamax, or does it switch to another theme?

I suspect this behavior occurs because I have set tokyodark as the default theme, which lacks a light variant. If this is confirmed, I'll switch the default theme to one that includes both dark and light variants.

For system theme respect, Stylix overrides need to be set by the user, which can be done via:

nvix = inputs.nvix.packages.${pkgs.system}.<type>.extend {
  config = {
    colorschemes = {
      base16 = {
        enable = true; # Enable for any color scheme that is not base16
        colorscheme = {
          inherit (config.lib.stylix.colors.withHashtag)
            base00 base01 base02 base03 base04 base05 base06 base07
            base08 base09 base0A base0B base0C base0D base0E base0F;
        };
      };
    };
    highlight = let
      transparent = {
        bg = "none";
        ctermbg = "none";
      };
    in {
      Normal = transparent;
      NonText = transparent;
      SignColumn = transparent;
    };
  };
};

Note: To have a light variant, the Stylix theme must also include a light variant. Only then will Snacks be able to toggle it correctly.

@cognivore
Copy link
Author

Wow, thank you for a detailed response!

When I set habmax (cool theme btw!), <leader>ub stays on habmax.

tokyodark, however switches between two themes.

Just to be clear about how it works for me:

  1. When I boot nvix, it respects stylix colours by default, except it has—to my knowledge—just one hard-coded colour (the light grey I have reported in this issue).
  2. When I press ub, it switches to what I presume is tokio light if current preference is dark and to tokio dark otherwise.
  3. When I press ub again, it keeps toggling between tokio and kioto (sorry for a geographic pun, what I mean is that it toggles between light and dark versions of the same colour scheme).

FWIW, I may be some days behind main though.

@cognivore
Copy link
Author

P.S.

I may have missed this stylix instruction, but it would be banger if this instruction was discoverable.

@niksingh710
Copy link
Owner

niksingh710 commented Feb 4, 2025

Yeah, it seems that for Stylix, you need to have a light variant; only then will the Snacks API be able to toggle between the light and dark variants.

I guess a request can be made for the Snacks API to remember the last dark theme if that theme doesn’t have a light variant.

@ahfriedman
Copy link

ahfriedman commented Feb 4, 2025

I think something else is still missing here to get full stylix support. My experience has been:

  • nvix defaults to tokiodark whenever started
  • <leader>ub switches you to a "default" theme where snacks is then able to take over for the light/dark theme toggling
  • This default theme is not the same theme that you would get via :colorscheme default it appears to use custom colors (though I could be mistaken about that last part)
  • This colorscheme is not the same as the the one provided by stylix
    • This is evidenced by using a pre-defined base16 colorscheme with Stylix and comparing it to :colorscheme base16-<scheme> in nvix.
    • Removing nvix and replacing it with neovim reveals that stylix correctly applies the base16 theme to nvim—thus, the problem must be somewhere between nixvim and nvix.
  • Returning to nvix, running echo base16_gui00, echo base16_gui01, etc. reveals that the base16-nvim plugin is receiving the correct theme information from stylix.
  • AFAIK, base16-nvim does not have a way to re-apply a custom theme once one has been set with :colorscheme.
  • Adding colorscheme = lib.mkForce null; to the extended nvix config for stylix posted above will prevent tokiodark from being loaded as the default theme and will mostly allow the Stylix theme to load correctly; however, I have seen some issues with the theming of the terminal background when doing this.
  • <leader>ub in this mode will cause the theme to change back to default instead of the custom stylix theme.

@niksingh710
Copy link
Owner

nvix is a standalone NixVim adaptation, so to get Stylix working on nvix, you need to extend nvix to include the Stylix color scheme manually.

Stylix NixVim Module

In this comment, I’ve mentioned how extend can be utilized.

I will switch to tokyonight as the default since tokyo dark doesn’t have a light variant.

For Stylix, I’ll update the README with easier-to-understand instructions after I complete my ndots rewrite, where I’ll be using the Stylix theme too XD. So, you’ll have to wait until then.

In the meantime, if someone can create both light and dark variants of the Stylix theme via extend, a PR is welcome!

@ahfriedman
Copy link

nvix is a standalone NixVim adaptation, so to get Stylix working on nvix, you need to extend nvix to include the Stylix color scheme manually.

Stylix NixVim Module

In this comment, I’ve mentioned how extend can be utilized.

I will switch to tokyonight as the default since tokyo dark doesn’t have a light variant.

For Stylix, I’ll update the README with easier-to-understand instructions after I complete my ndots rewrite, where I’ll be using the Stylix theme too XD. So, you’ll have to wait until then.

In the meantime, if someone can create both light and dark variants of the Stylix theme via extend, a PR is welcome!

The behavior I described occurred while using the changes described in your comment and while having the nixvim stylix target enabled

niksingh710 added a commit that referenced this issue Feb 9, 2025
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

No branches or pull requests

3 participants