ellisonleao / gruvbox.nvim

Lua port of the most famous vim colorscheme
MIT License
1.81k stars 195 forks source link

Expose palette colors #306

Open markmansur opened 8 months ago

markmansur commented 8 months ago

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")
ellisonleao commented 8 months ago

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.

darkangel-ua commented 8 months ago

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.

neevparikh commented 8 months ago

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

ellisonleao commented 8 months ago

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)

darkangel-ua commented 8 months ago

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.

neevparikh commented 8 months ago

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

neevparikh commented 7 months ago

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:

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

zjykzk commented 6 months ago

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 ;)