diff --git a/README.md b/README.md
index b4d79625..1bfe01d8 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
-A port of [gruvbox community](https://github.com/gruvbox-community/gruvbox) theme to lua with [treesitter](https://github.com/nvim-treesitter/nvim-treesitter) support!
+A port of [gruvbox community](https://github.com/gruvbox-community/gruvbox) theme to lua with [treesitter](https://github.com/nvim-treesitter/nvim-treesitter) and [semantic highlights](https://neovim.io/doc/user/lsp.html#lsp-semantic-highlight) support!
@@ -18,16 +18,16 @@ Neovim 0.8.0+
# Installing
-Using `packer`
+## Using `packer`
```lua
use { "ellisonleao/gruvbox.nvim" }
```
-Using `lazy.nvim`
+## Using `lazy.nvim`
```lua
-{ "ellisonleao/gruvbox.nvim", priority = 1000 }
+{ "ellisonleao/gruvbox.nvim", priority = 1000 , setup = true, opts = ...}
```
# Basic Usage
@@ -51,7 +51,6 @@ vim.cmd([[colorscheme gruvbox]])
Additional settings for gruvbox are:
```lua
--- setup must be called before loading the colorscheme
-- Default options:
require("gruvbox").setup({
terminal_colors = true, -- add neovim terminal colors
@@ -80,6 +79,8 @@ require("gruvbox").setup({
vim.cmd("colorscheme gruvbox")
```
+**VERY IMPORTANT**: Make sure to call setup() **BEFORE** calling the colorscheme command, to use your custom configs
+
## Overriding
### Palette
@@ -95,8 +96,6 @@ require("gruvbox").setup({
vim.cmd("colorscheme gruvbox")
```
-More colors in the [palette.lua](lua/gruvbox/palette.lua) file
-
### Highlight groups
If you don't enjoy the current color for a specific highlight group, now you can just override it in the setup. For
@@ -111,6 +110,18 @@ require("gruvbox").setup({
vim.cmd("colorscheme gruvbox")
```
+It also works with treesitter groups and lsp semantic highlight tokens
+
+```lua
+require("gruvbox").setup({
+ overrides = {
+ ["@lsp.type.method"] = { bg = "#ff9900" },
+ ["@comment.lua"] = { bg = "#000000" },
+ }
+})
+vim.cmd("colorscheme gruvbox")
+```
+
Please note that the override values must follow the attributes from the highlight group map, such as:
- **fg** - foreground color
@@ -118,4 +129,4 @@ Please note that the override values must follow the attributes from the highlig
- **bold** - true or false for bold font
- **italic** - true or false for italic font
-Other values can be seen in `:h synIDattr`
+Other values can be seen in [`synIDattr`]()
diff --git a/lua/gruvbox/groups.lua b/lua/gruvbox.lua
similarity index 85%
rename from lua/gruvbox/groups.lua
rename to lua/gruvbox.lua
index 9a2c55ab..c35e6ba4 100644
--- a/lua/gruvbox/groups.lua
+++ b/lua/gruvbox.lua
@@ -1,9 +1,218 @@
-local M = {}
+---@class Gruvbox
+---@field config GruvboxConfig
+---@field palette GruvboxPalette
+local Gruvbox = {}
--- setup Gruvbox groups
----@param config GruvboxConfig
-M.setup = function(config)
- local colors = require("gruvbox.palette").get_base_colors(config.palette_overrides, vim.o.background, config.contrast)
+---@alias Contrast "hard" | "soft" | ""
+
+---@class ItalicConfig
+---@field strings boolean
+---@field comments boolean
+---@field operators boolean
+---@field folds boolean
+---@field emphasis boolean
+
+---@class HighlightDefinition
+---@field fg string?
+---@field bg string?
+---@field sp string?
+---@field blend integer?
+---@field bold boolean?
+---@field standout boolean?
+---@field underline boolean?
+---@field undercurl boolean?
+---@field underdouble boolean?
+---@field underdotted boolean?
+---@field strikethrough boolean?
+---@field italic boolean?
+---@field reverse boolean?
+---@field nocombine boolean?
+
+---@class GruvboxConfig
+---@field terminal_colors boolean?
+---@field undercurl boolean?
+---@field underline boolean?
+---@field bold boolean?
+---@field italic ItalicConfig?
+---@field strikethrough boolean?
+---@field contrast Contrast?
+---@field invert_selection boolean?
+---@field invert_signs boolean?
+---@field invert_tabline boolean?
+---@field invert_intend_guides boolean?
+---@field inverse boolean?
+---@field overrides table?
+---@field palette_overrides table?
+Gruvbox.config = {
+ terminal_colors = true,
+ undercurl = true,
+ underline = true,
+ bold = true,
+ italic = {
+ strings = true,
+ emphasis = true,
+ comments = true,
+ operators = false,
+ folds = true,
+ },
+ strikethrough = true,
+ invert_selection = false,
+ invert_signs = false,
+ invert_tabline = false,
+ invert_intend_guides = false,
+ inverse = true,
+ contrast = "",
+ palette_overrides = {},
+ overrides = {},
+ dim_inactive = false,
+ transparent_mode = false,
+}
+
+-- main gruvbox color palette
+---@class GruvboxPalette
+Gruvbox.palette = {
+ dark0_hard = "#1d2021",
+ dark0 = "#282828",
+ dark0_soft = "#32302f",
+ dark1 = "#3c3836",
+ dark2 = "#504945",
+ dark3 = "#665c54",
+ dark4 = "#7c6f64",
+ light0_hard = "#f9f5d7",
+ light0 = "#fbf1c7",
+ light0_soft = "#f2e5bc",
+ light1 = "#ebdbb2",
+ light2 = "#d5c4a1",
+ light3 = "#bdae93",
+ light4 = "#a89984",
+ bright_red = "#fb4934",
+ bright_green = "#b8bb26",
+ bright_yellow = "#fabd2f",
+ bright_blue = "#83a598",
+ bright_purple = "#d3869b",
+ bright_aqua = "#8ec07c",
+ bright_orange = "#fe8019",
+ neutral_red = "#cc241d",
+ neutral_green = "#98971a",
+ neutral_yellow = "#d79921",
+ neutral_blue = "#458588",
+ neutral_purple = "#b16286",
+ neutral_aqua = "#689d6a",
+ neutral_orange = "#d65d0e",
+ faded_red = "#9d0006",
+ faded_green = "#79740e",
+ faded_yellow = "#b57614",
+ faded_blue = "#076678",
+ faded_purple = "#8f3f71",
+ faded_aqua = "#427b58",
+ faded_orange = "#af3a03",
+ dark_red_hard = "#792329",
+ dark_red = "#722529",
+ dark_red_soft = "#7b2c2f",
+ light_red_hard = "#fc9690",
+ light_red = "#fc9487",
+ light_red_soft = "#f78b7f",
+ dark_green_hard = "#5a633a",
+ dark_green = "#62693e",
+ dark_green_soft = "#686d43",
+ light_green_hard = "#d3d6a5",
+ light_green = "#d5d39b",
+ light_green_soft = "#cecb94",
+ dark_aqua_hard = "#3e4934",
+ dark_aqua = "#49503b",
+ dark_aqua_soft = "#525742",
+ light_aqua_hard = "#e6e9c1",
+ light_aqua = "#e8e5b5",
+ light_aqua_soft = "#e1dbac",
+ gray = "#928374",
+}
+
+-- get a hex list of gruvbox colors based on current bg and constrast config
+local function get_colors()
+ local p = Gruvbox.palette
+ local config = Gruvbox.config
+
+ for color, hex in pairs(config.palette_overrides) do
+ p[color] = hex
+ end
+
+ local bg = vim.o.background
+ local contrast = config.contrast
+
+ local color_groups = {
+ dark = {
+ bg0 = p.dark0,
+ bg1 = p.dark1,
+ bg2 = p.dark2,
+ bg3 = p.dark3,
+ bg4 = p.dark4,
+ fg0 = p.light0,
+ fg1 = p.light1,
+ fg2 = p.light2,
+ fg3 = p.light3,
+ fg4 = p.light4,
+ red = p.bright_red,
+ green = p.bright_green,
+ yellow = p.bright_yellow,
+ blue = p.bright_blue,
+ purple = p.bright_purple,
+ aqua = p.bright_aqua,
+ orange = p.bright_orange,
+ neutral_red = p.neutral_red,
+ neutral_green = p.neutral_green,
+ neutral_yellow = p.neutral_yellow,
+ neutral_blue = p.neutral_blue,
+ neutral_purple = p.neutral_purple,
+ neutral_aqua = p.neutral_aqua,
+ dark_red = p.dark_red,
+ dark_green = p.dark_green,
+ dark_aqua = p.dark_aqua,
+ gray = p.gray,
+ },
+ light = {
+ bg0 = p.light0,
+ bg1 = p.light1,
+ bg2 = p.light2,
+ bg3 = p.light3,
+ bg4 = p.light4,
+ fg0 = p.dark0,
+ fg1 = p.dark1,
+ fg2 = p.dark2,
+ fg3 = p.dark3,
+ fg4 = p.dark4,
+ red = p.faded_red,
+ green = p.faded_green,
+ yellow = p.faded_yellow,
+ blue = p.faded_blue,
+ purple = p.faded_purple,
+ aqua = p.faded_aqua,
+ orange = p.faded_orange,
+ neutral_red = p.neutral_red,
+ neutral_green = p.neutral_green,
+ neutral_yellow = p.neutral_yellow,
+ neutral_blue = p.neutral_blue,
+ neutral_purple = p.neutral_purple,
+ neutral_aqua = p.neutral_aqua,
+ dark_red = p.light_red,
+ dark_green = p.light_green,
+ dark_aqua = p.light_aqua,
+ gray = p.gray,
+ },
+ }
+
+ if contrast ~= nil and contrast ~= "" then
+ color_groups[bg].bg0 = p[bg .. "0_" .. contrast]
+ color_groups[bg].dark_red = p[bg .. "_red_" .. contrast]
+ color_groups[bg].dark_green = p[bg .. "_green_" .. contrast]
+ color_groups[bg].dark_aqua = p[bg .. "_aqua_" .. contrast]
+ end
+
+ return color_groups[bg]
+end
+
+local function get_groups()
+ local colors = get_colors()
+ local config = Gruvbox.config
if config.terminal_colors then
local term_colors = {
@@ -151,10 +360,10 @@ M.setup = function(config)
PmenuSel = { fg = colors.bg2, bg = colors.blue, bold = config.bold },
PmenuSbar = { bg = colors.bg2 },
PmenuThumb = { bg = colors.bg4 },
- DiffDelete = { fg = colors.red, bg = colors.bg0, reverse = config.inverse },
- DiffAdd = { fg = colors.green, bg = colors.bg0, reverse = config.inverse },
- DiffChange = { fg = colors.aqua, bg = colors.bg0, reverse = config.inverse },
- DiffText = { fg = colors.yellow, bg = colors.bg0, reverse = config.inverse },
+ DiffDelete = { bg = colors.dark_red },
+ DiffAdd = { bg = colors.dark_green },
+ DiffChange = { bg = colors.dark_aqua },
+ DiffText = { bg = colors.yellow },
SpellCap = { link = "GruvboxBlueUnderline" },
SpellBad = { link = "GruvboxRedUnderline" },
SpellLocal = { link = "GruvboxAquaUnderline" },
@@ -180,6 +389,7 @@ M.setup = function(config)
DiagnosticVirtualTextWarn = { link = "GruvboxYellow" },
DiagnosticVirtualTextInfo = { link = "GruvboxBlue" },
DiagnosticVirtualTextHint = { link = "GruvboxAqua" },
+ DiagnosticOk = { link = "GruvboxGreenSign" },
LspReferenceRead = { link = "GruvboxYellowBold" },
LspReferenceText = { link = "GruvboxYellowBold" },
LspReferenceWrite = { link = "GruvboxOrangeBold" },
@@ -302,9 +512,9 @@ M.setup = function(config)
CmpItemKindConstant = { link = "GruvboxOrange" },
CmpItemKindStruct = { link = "GruvboxYellow" },
CmpItemKindTypeParameter = { link = "GruvboxYellow" },
- diffAdded = { link = "GruvboxGreen" },
- diffRemoved = { link = "GruvboxRed" },
- diffChanged = { link = "GruvboxAqua" },
+ diffAdded = { link = "DiffAdd" },
+ diffRemoved = { link = "DiffDelete" },
+ diffChanged = { link = "DiffChange" },
diffFile = { link = "GruvboxOrange" },
diffNewFile = { link = "GruvboxYellow" },
diffOldFile = { link = "GruvboxOrange" },
@@ -729,6 +939,13 @@ M.setup = function(config)
DapUIWatchesError = { link = "GruvboxRed" },
DapUIWatchesValue = { link = "GruvboxYellow" },
DapUIWinSelect = { link = "GruvboxYellow" },
+ NeogitDiffDelete = { link = "DiffDelete" },
+ NeogitDiffAdd = { link = "DiffAdd" },
+ NeogitHunkHeader = { link = "WinBar" },
+ NeogitHunkHeaderHighlight = { link = "WinBarNC" },
+ DiffviewStatusModified = { link = "GruvboxGreenBold" },
+ DiffviewFilePanelInsertions = { link = "GruvboxGreenBold" },
+ DiffviewFilePanelDeletions = { link = "GruvboxRedBold" },
["@comment"] = { link = "Comment" },
["@none"] = { bg = "NONE", fg = "NONE" },
["@preproc"] = { link = "PreProc" },
@@ -835,4 +1052,31 @@ M.setup = function(config)
return groups
end
-return M
+---@param config GruvboxConfig?
+Gruvbox.setup = function(config)
+ Gruvbox.config = vim.tbl_deep_extend("force", Gruvbox.config, config or {})
+end
+
+--- main load function
+Gruvbox.load = function()
+ if vim.version().minor < 8 then
+ vim.notify_once("gruvbox.nvim: you must use neovim 0.8 or higher")
+ return
+ end
+
+ -- reset colors
+ if vim.g.colors_name then
+ vim.cmd.hi("clear")
+ end
+ vim.g.colors_name = "gruvbox"
+ vim.o.termguicolors = true
+
+ local groups = get_groups()
+
+ -- add highlights
+ for group, settings in pairs(groups) do
+ vim.api.nvim_set_hl(0, group, settings)
+ end
+end
+
+return Gruvbox
diff --git a/lua/gruvbox/init.lua b/lua/gruvbox/init.lua
deleted file mode 100644
index e3aef5e9..00000000
--- a/lua/gruvbox/init.lua
+++ /dev/null
@@ -1,97 +0,0 @@
----@class Gruvbox
----@field config GruvboxConfig
-local Gruvbox = {}
-
----@alias Contrast "hard" | "soft" | ""
-
----@class ItalicConfig
----@field strings boolean
----@field comments boolean
----@field operators boolean
----@field folds boolean
----@field emphasis boolean
-
----@class HighlightDefinition
----@field fg string?
----@field bg string?
----@field sp string?
----@field blend integer?
----@field bold boolean?
----@field standout boolean?
----@field underline boolean?
----@field undercurl boolean?
----@field underdouble boolean?
----@field underdotted boolean?
----@field strikethrough boolean?
----@field italic boolean?
----@field reverse boolean?
----@field nocombine boolean?
-
----@class GruvboxConfig
----@field terminal_colors boolean?
----@field undercurl boolean?
----@field underline boolean?
----@field bold boolean?
----@field italic ItalicConfig?
----@field strikethrough boolean?
----@field contrast Contrast?
----@field invert_selection boolean?
----@field invert_signs boolean?
----@field invert_tabline boolean?
----@field invert_intend_guides boolean?
----@field inverse boolean?
----@field overrides table?
----@field palette_overrides table?
-Gruvbox.config = {
- terminal_colors = true,
- undercurl = true,
- underline = true,
- bold = true,
- italic = {
- strings = true,
- emphasis = true,
- comments = true,
- operators = false,
- folds = true,
- },
- strikethrough = true,
- invert_selection = false,
- invert_signs = false,
- invert_tabline = false,
- invert_intend_guides = false,
- inverse = true,
- contrast = "",
- palette_overrides = {},
- overrides = {},
- dim_inactive = false,
- transparent_mode = false,
-}
-
----@param config GruvboxConfig?
-function Gruvbox.setup(config)
- Gruvbox.config = vim.tbl_deep_extend("force", Gruvbox.config, config or {})
-end
-
---- main load function
-Gruvbox.load = function()
- if vim.version().minor < 8 then
- vim.notify_once("gruvbox.nvim: you must use neovim 0.8 or higher")
- return
- end
-
- -- reset colors
- if vim.g.colors_name then
- vim.cmd.hi("clear")
- end
- vim.g.colors_name = "gruvbox"
- vim.o.termguicolors = true
-
- local groups = require("gruvbox.groups").setup(Gruvbox.config)
-
- -- add highlights
- for group, settings in pairs(groups) do
- vim.api.nvim_set_hl(0, group, settings)
- end
-end
-
-return Gruvbox
diff --git a/lua/gruvbox/palette.lua b/lua/gruvbox/palette.lua
deleted file mode 100644
index 8270c0f7..00000000
--- a/lua/gruvbox/palette.lua
+++ /dev/null
@@ -1,121 +0,0 @@
-local M = {}
-
--- main gruvbox colors
----@class GruvboxColors
-local colors = {
- dark0_hard = "#1d2021",
- dark0 = "#282828",
- dark0_soft = "#32302f",
- dark1 = "#3c3836",
- dark2 = "#504945",
- dark3 = "#665c54",
- dark4 = "#7c6f64",
- light0_hard = "#f9f5d7",
- light0 = "#fbf1c7",
- light0_soft = "#f2e5bc",
- light1 = "#ebdbb2",
- light2 = "#d5c4a1",
- light3 = "#bdae93",
- light4 = "#a89984",
- bright_red = "#fb4934",
- bright_green = "#b8bb26",
- bright_yellow = "#fabd2f",
- bright_blue = "#83a598",
- bright_purple = "#d3869b",
- bright_aqua = "#8ec07c",
- bright_orange = "#fe8019",
- neutral_red = "#cc241d",
- neutral_green = "#98971a",
- neutral_yellow = "#d79921",
- neutral_blue = "#458588",
- neutral_purple = "#b16286",
- neutral_aqua = "#689d6a",
- neutral_orange = "#d65d0e",
- faded_red = "#9d0006",
- faded_green = "#79740e",
- faded_yellow = "#b57614",
- faded_blue = "#076678",
- faded_purple = "#8f3f71",
- faded_aqua = "#427b58",
- faded_orange = "#af3a03",
- gray = "#928374",
-}
-
--- get a hex list of gruvbox colors based on config, bg and contrast
----@param color_overrides GruvboxColors
----@param bg? string
----@param contrast Contrast
-M.get_base_colors = function(color_overrides, bg, contrast)
- local p = colors
-
- for color, hex in pairs(color_overrides) do
- p[color] = hex
- end
-
- if bg == nil then
- bg = vim.o.background
- end
-
- local color_groups = {
- dark = {
- bg0 = p.dark0,
- bg1 = p.dark1,
- bg2 = p.dark2,
- bg3 = p.dark3,
- bg4 = p.dark4,
- fg0 = p.light0,
- fg1 = p.light1,
- fg2 = p.light2,
- fg3 = p.light3,
- fg4 = p.light4,
- red = p.bright_red,
- green = p.bright_green,
- yellow = p.bright_yellow,
- blue = p.bright_blue,
- purple = p.bright_purple,
- aqua = p.bright_aqua,
- orange = p.bright_orange,
- neutral_red = p.neutral_red,
- neutral_green = p.neutral_green,
- neutral_yellow = p.neutral_yellow,
- neutral_blue = p.neutral_blue,
- neutral_purple = p.neutral_purple,
- neutral_aqua = p.neutral_aqua,
- gray = p.gray,
- },
- light = {
- bg0 = p.light0,
- bg1 = p.light1,
- bg2 = p.light2,
- bg3 = p.light3,
- bg4 = p.light4,
- fg0 = p.dark0,
- fg1 = p.dark1,
- fg2 = p.dark2,
- fg3 = p.dark3,
- fg4 = p.dark4,
- red = p.faded_red,
- green = p.faded_green,
- yellow = p.faded_yellow,
- blue = p.faded_blue,
- purple = p.faded_purple,
- aqua = p.faded_aqua,
- orange = p.faded_orange,
- neutral_red = p.neutral_red,
- neutral_green = p.neutral_green,
- neutral_yellow = p.neutral_yellow,
- neutral_blue = p.neutral_blue,
- neutral_purple = p.neutral_purple,
- neutral_aqua = p.neutral_aqua,
- gray = p.gray,
- },
- }
-
- if contrast ~= nil and contrast ~= "" then
- color_groups[bg].bg0 = p[bg .. string.format("0_%s", contrast)]
- end
-
- return color_groups[bg]
-end
-
-return M
diff --git a/tests/gruvbox/gruvbox_spec.lua b/tests/gruvbox/gruvbox_spec.lua
index 387a034f..e4db89f9 100644
--- a/tests/gruvbox/gruvbox_spec.lua
+++ b/tests/gruvbox/gruvbox_spec.lua
@@ -137,10 +137,8 @@ describe("tests", function()
it("does not set terminal colors when terminal_colors is false", function()
clear_term_colors()
- print("vim.g color before =>", vim.g.terminal_color_0, type(vim.g.terminal_color_0))
gruvbox.setup({ terminal_colors = false })
gruvbox.load()
- print("vim.g color after =>", vim.g.terminal_color_0, type(vim.g.terminal_color_0))
assert.is_nil(vim.g.terminal_color_0)
end)
@@ -148,7 +146,16 @@ describe("tests", function()
clear_term_colors()
gruvbox.setup({ terminal_colors = true })
gruvbox.load()
- local colors = require("gruvbox.palette").get_base_colors({}, "dark", "")
- assert.are.same(vim.g.terminal_color_0, colors.bg0)
+
+ -- dark bg
+ local colors = require("gruvbox").palette
+ vim.opt.background = "dark"
+ assert.are.same(vim.g.terminal_color_0, colors.dark0)
+
+ -- light bg
+ clear_term_colors()
+ gruvbox.load()
+ vim.opt.background = "light"
+ assert.are.same(vim.g.terminal_color_0, colors.light0)
end)
end)