f4z3r / gruvbox-material.nvim

Material Gruvbox colorscheme for Neovim written in Lua
MIT License
32 stars 4 forks source link

[FEATURE] Extra hard contrast #35

Closed ic-768 closed 1 month ago

ic-768 commented 1 month ago

What kind of feature is this about?

Support for additional configuration

Description

I would love it if there was an easy way to set an extra hard contrast, i.e. the background be a darker shade.

That being said, I love this theme as-is. Thank you for your work!

f4z3r commented 1 month ago

Hi @ic-768 , this should be relatively easy to achieve with the customization option. For instance:

-- get colors from the colorscheme for current background and "hard" contrast
-- assuming you use hard contrast
local colors = require("gruvbox-material.colors").get(vim.o.background, "hard")

require('gruvbox-material').setup({
  -- your config here ...
  contrast = "hard",
  customize = function(g, o)
    if o.bg == colors.bg0 then
      o.bg = "your extra dark color"
    elseif o.bg == colors.bg1 then
      -- also apply changes to other background types ...
    end
    return o
  end,
})

You can see the background color definitions for a dark hard contrast here: https://github.com/f4z3r/gruvbox-material.nvim/blob/master/lua/gruvbox-material/colors.lua#L51-L56

Which of these backgrounds gets used is dependent on stuff like floats, etc. The normal background is bg0 as can be seen here: https://github.com/f4z3r/gruvbox-material.nvim/blob/master/lua/gruvbox-material/groups.lua#L153

Let me know if this works or if I can be of any more help.

ic-768 commented 1 month ago

Thanks for the reply! I'm having an issue with lazy.nvim, I'm probably doing something wrong.

I have my colorscheme.lua file in my plugins folder, and I add these lines:

return {
  {
    'f4z3r/gruvbox-material.nvim',
    lazy = false,
    name = 'gruvbox-material',
    opts = {},
    priority = 1000, -- load this before all the other start plugins
    config = function()
      vim.cmd([[colorscheme gruvbox-material]])
      local colors = require("gruvbox-material.colors").get(vim.o.background, "hard")

      require('gruvbox-material').setup({
        contrast = "hard",
        customize = function(g, o)
          if o.bg == colors.bg0 then
            o.bg = " #090c0d"
            return o
          end,
        })
      end,
    },
  }

but i get attempt to call a nil value error when opening neovim after saving this

f4z3r commented 1 month ago

You want to change two things here.

  1. You should not call vim.cmd([[colorscheme gruvbox-material]]). This will reset the theme and is not necessary if you call the setup function.
  2. Note that in your customize function, you only return the options if you modify the color. In all other cases you don't return anything (nil), which probably is the cause for your error message. You will want to move the return statement outside the if block.

Once that is done, it should work as you would expect.

ic-768 commented 1 month ago

Works like a charm. Thanks a lot!