local M = {} function M.reset(theme) vim.opt.background = (theme.variant == "light") and "light" or "dark" vim.g.colors_name = theme.name end local function list_integrations(theme_name) local path = vim.fn.stdpath("config") .. "/lua/themes/" .. theme_name .. "/groups/integrations/" local files = {} for name, type in vim.fs.dir(path) do if type == "file" then local mod_name = vim.fn.fnamemodify(name, ":r") table.insert(files, mod_name) end end return files end function M.apply(theme) local base = "themes." .. theme.name local P = require(base .. ".palette").get() local C = require(base .. ".colors").get(P) local modules = { require(base .. ".groups.editor"), require(base .. ".groups.syntax"), require(base .. ".groups.terminal"), } local exclude = theme.exclude_integrations or {} local function should_load(name) return not vim.tbl_contains(exclude, name) end -- auto-discover integrations for _, plugin in ipairs(list_integrations(theme.name)) do if should_load(plugin) then local ok_mod, mod = pcall(require, base .. ".groups.integrations." .. plugin) if ok_mod then table.insert(modules, mod) end end end -- Apply highlights for _, mod in ipairs(modules) do local groups = mod.get(C) or {} for group, opts in pairs(groups) do if type(opts) ~= "table" then print("Non-table opts detected in group:", group, "value:", vim.inspect(opts)) end local hl = {} -- ALT: Use both scenarios -- if type(v) == "number" then -- hl.ctermfg = v -- else -- hl.fg = v -- end for k, v in pairs(opts) do if k == "fg" then hl.ctermfg = v elseif k == "bg" then hl.ctermbg = v else hl[k] = v -- bold, italic, underline, sp, etc. end end vim.api.nvim_set_hl(0, group, hl) end end end return M