ellisonleao / gruvbox.nvim

Lua port of the most famous vim colorscheme

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expose palette colors

markmansur opened this issue · comments

It would be nice if the colors palette was exposed to users of this plugin.

Current State

The current state only allows us to override a highlight group with a string. See below.

require("gruvbox").setup({
    overrides = {
        SignColumn = {bg = "#ff9900"}
    }
})
vim.cmd("colorscheme gruvbox")

Requested State

I am requesting that we expose the palette so that users can do something like this

local gruvbox = require("gruvbox")
palette = gruvbox.getColors("dark")
gruvbox.setup({
    overrides = {
        SignColumn = {bg = palette.orange}
    }
})
vim.cmd("colorscheme gruvbox")

hey @markmansur you already have the full palette available in the require('gruvbox').palette table. Does that work for your use case? We had a similar thing in the past but it was too overkill for this project.

The issue with require('gruvbox').palette is that it doesn't take into account current contrast which makes it not so useful.

Current approach doesn't expose abstract colors that will be set according to background/contrast options, so you have to manually do that boilerplate work. You can't do

            SignColumn = { bg = colors.bg0 }, 

and expect that colors.bg0 will be correctly translated to dark0_hard when you set contrast = "hard" or switch to ligth scheme without tons of boilerplate code.

Hey I noticed this would be solved if we exposed the get_colors and get_groups functions publicly and I see no reason to not do that. Would a PR for this be okay? @ellisonleao

hey @neevparikh i am still thinking about that. One of the new possibilities is to have in the configs 2 new methods (on_colors, on_highlights) for custom overrides. Those functions will probably have the colors and highlights table with some predefined conditions (contrast and bg for instance)

Just throwing in the air... What if pallete will contains abstract colors like bg0 that will be a function and while processing overrides we can do something
if is function override_color.bg then new_bg = override_color.bg(config) else bg = c.bg end this way we can expose abstract colors that can be translated to desired based on current config. With proper default implementation for bg0 this

            SignColumn = { bg = colors.bg0 },

should be possible.

@ellisonleao that sounds like a fair approach! thanks for putting in the time to create this and maintain it :D

hey @neevparikh i am still thinking about that. One of the new possibilities is to have in the configs 2 new methods (on_colors, on_highlights) for custom overrides. Those functions will probably have the colors and highlights table with some predefined conditions (contrast and bg for instance)

Hey @ellisonleao I was peeking at what other themes do, and I played with catppuccin's approach and it seemed like it would be pretty great, if we could do something like that. https://github.com/catppuccin/nvim

TL;DR:

  • they expose the palette like we were discussing
  • their overrides (for highlight and colors) can be specified either for all variants or each variant invidually (light & dark and various forms of hardness in our case)
  • When having highlight overrides, the config provides a function that has the existing palette, allowing for users to just move stuff around or do whatever!
  • they allow setting a variant for dark and light. I think it'd be nice to say I want gruvbox dark hard for dark theme but medium for light or something like that.

Instead of this:

local gruvbox = require("gruvbox")
require("gruvbox").setup({
....
  contrast = "", -- can be "hard", "soft" or empty string
  palette_overrides = {},
  overrides = {},

Our config could look something like:

local gruvbox = require("gruvbox")
require("gruvbox").setup({
....
  contrast = {
    dark = {"hard"}, -- can be "hard", "soft" or empty string
    light = {""},    
  } 
  palette_overrides = {
    all = {}, -- optionally do for all 
    dark = {
      dark0 = "#aafda3",
      dark0_h = "<some color>" -- etc.
    },
    light = {
      dark0 = "#aafda3",
      light2 = gruvbox.palette.light().light1
    },
  },
  overrides = {
    all = function(all) return { -- some override for all } end,
    dark = function(dark) return {
       Spell = { fg = dark.light1, bg = dark.dark0_h } -- or whatever
    } end,
    light = function(light) return {} end
  },

If this seems like it aligns with what you were thinking, I'd be happy to help

commented

Hey I noticed this would be solved if we exposed the get_colors and get_groups functions publicly and I see no reason to not do that. Would a PR for this be okay? @ellisonleao

i need reference the groups to dump the highlight command to accelerate the startup time ;)