diff --git a/README.md b/README.md index a5caa1c..026913d 100644 --- a/README.md +++ b/README.md @@ -322,6 +322,18 @@ local colors = require'catppuccin.api.colors'.get_colors() -- fetch colors with catppuccin.remap({ Comment = { fg = colors.flamingo }, }) ``` +#### Overwriting colors + +Colors can be overwritten using `vim.g.catppucin_override_colors`: + +```lua +vim.g.catppuccin_override_colors = { + base = "#ff0000", + mantle = "#242424", + crust = "#474747", +} +``` + #### Hooks Use them to execute code at certain events. These are the ones available: diff --git a/lua/catppuccin/config.lua b/lua/catppuccin/config.lua index 5c2bdb1..6b35cc1 100644 --- a/lua/catppuccin/config.lua +++ b/lua/catppuccin/config.lua @@ -77,6 +77,7 @@ config.options = { telekasten = true, symbols_outline = true, }, + color_overrides = {} custom_highlights = {}, } diff --git a/lua/catppuccin/core/palettes/init.lua b/lua/catppuccin/core/palettes/init.lua index fc01b70..ee4e36c 100644 --- a/lua/catppuccin/core/palettes/init.lua +++ b/lua/catppuccin/core/palettes/init.lua @@ -1,12 +1,34 @@ local M = {} +local cnf = require("catppuccin.config").options + function M.get_palette() local flvr = vim.g.catppuccin_flavour + local palette = require("catppuccin.core.palettes.mocha") if flvr == "mocha" or flvr == "latte" or flvr == "macchiato" or flvr == "frappe" then - return require("catppuccin.core.palettes." .. flvr) + palette = require("catppuccin.core.palettes." .. flvr) + end + + if type(cnf.color_overrides) == "table" then + for _, pal in pairs({"all", flvr}) do + if cnf.color_overrides[pal] ~= nil then + for k, v in pairs(cnf.color_overrides[pal]) do + if palette[k] then + palette[k] = v + else + vim.api.nvim_echo( + { { 'Warning: "' .. k .. '" is not a valid catppucin palette color.', "WarningMsg" } }, + true, + {} + ) + end + end + end + end end - return require("catppuccin.core.palettes.mocha") + + return palette end return M