Skip to content

Commit

Permalink
feat: allow overrides to be function(colors)
Browse files Browse the repository at this point in the history
This patch checks for table and function in `config.overrides` and
extracts overriden groups appropriate way. Also README.md is updated
to reflect this change.
  • Loading branch information
h3xOo committed Sep 8, 2024
1 parent 7a1b23e commit 65bc5fe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,27 @@ require("gruvbox").setup({
vim.cmd("colorscheme gruvbox")
```

`overrides` can also be a `function(colors)` which returns table of overriden groups

```lua
require("gruvbox").setup({
overrides = function(colors)
return {
Title = { link = "GruvboxYellowBold" },
["@comment"] = { fg = colors.gray, italic = true, bold = false },
}
end
})
vim.cmd("colorscheme gruvbox")
```

`colors` has those fields:
* `bg0`, `bg1`, `bg2`, `bg3`, `bg4`,
* `fg0`, `fg1`, `fg2`, `fg3`, `fg4`,
* `red`, `green`, `yellow`, `blue`, `purple`, `aqua`, `orange`, `gray`,
* `neutral_red`, `neutral_green`, `neutral_yellow`, `neutral_blue`, `neutral_purple`, `neutral_aqua`,
* `dark_red`, `dark_green`, `dark_aqua`.

Please note that the override values must follow the attributes from the highlight group map, such as:

- **fg** - foreground color
Expand Down
13 changes: 11 additions & 2 deletions lua/gruvbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ local Gruvbox = {}
---@field invert_tabline boolean?
---@field invert_intend_guides boolean?
---@field inverse boolean?
---@field overrides table<string, HighlightDefinition>?
---@field overrides [table<string, HighlightDefinition> | fun(colors: table<string, string>): table<string, HighlightDefinition>]
---@field palette_overrides table<string, string>?
Gruvbox.config = {
terminal_colors = true,
Expand Down Expand Up @@ -1205,7 +1205,16 @@ local function get_groups()
["@lsp.type.variable"] = { link = "@variable" },
}

for group, hl in pairs(config.overrides) do
local overrides = {}
if config.overrides ~= nil then
if type(config.overrides) == "table" then
overrides = config.overrides
elseif type(config.overrides) == "function" then
overrides = config.overrides(colors)
end
end

for group, hl in pairs(overrides) do
if groups[group] then
-- "link" should not mix with other configs (:h hi-link)
groups[group].link = nil
Expand Down

0 comments on commit 65bc5fe

Please sign in to comment.