Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(utils): auto-refresh builtin palette on ColorScheme #831

Merged
merged 2 commits into from
Jul 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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