Skip to content

Commit

Permalink
feat(utils): auto-refresh builtin palette on ColorScheme (#831)
Browse files Browse the repository at this point in the history
* feat(utils): auto-refresh builtin palette on `ColorScheme`

* fixup! feat(utils): auto-refresh builtin palette on `ColorScheme`
  • Loading branch information
Jint-lzxy authored Jul 2, 2023
1 parent 0af8f4b commit 54b7c3f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lua/modules/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,29 @@ local M = {}
---@field crust string
---@field none "NONE"

---@type palette
---@type nil|palette
local palette = nil

-- Indicates if autocmd for refreshing the builtin palette has already been registered
---@type boolean
local _has_autocmd = false

---Initialize the palette
---@return palette
local function init_palette()
-- Reinitialize the palette on event `ColorScheme`
if not _has_autocmd then
_has_autocmd = true
vim.api.nvim_create_autocmd("ColorScheme", {
group = vim.api.nvim_create_augroup("__builtin_palette", { clear = true }),
pattern = "*",
callback = function()
palette = nil
init_palette()
end,
})
end

if not palette then
palette = vim.g.colors_name:find("catppuccin") and require("catppuccin.palettes").get_palette()
or {
Expand Down

0 comments on commit 54b7c3f

Please sign in to comment.