Skip to content

Conversation

misumisumi
Copy link
Collaborator

Due to the change in a631be2, an error will now occur if a color scheme other than catppuccin is used.
Previously, when using another color scheme, it seemed to fall back to the defined palette.
This change supports retrieval of user-defined color palettes, allowing you to use a wider range of color schemes.

  • error message
    image

@ayamir
Copy link
Owner

ayamir commented Nov 29, 2024

My fault, I didn't test the case when colorscheme is not catppuccin.
But the current impl doesn't seem to solve the problem:
image
And the introduction of get_palette_func seems to be duplicated with palette_overwrite?

@ayamir
Copy link
Owner

ayamir commented Nov 29, 2024

This impl is enough for addressing the current bug:

---Initialize the palette
---@return table
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()
				-- Also refresh hard-coded hl groups
				M.gen_alpha_hl()
				M.gen_lspkind_hl()
				pcall(vim.cmd.AlphaRedraw)
			end,
		})
	end

	local fallback_palette = {
		rosewater = "#DC8A78",
		flamingo = "#DD7878",
		mauve = "#CBA6F7",
		pink = "#F5C2E7",
		red = "#E95678",
		maroon = "#B33076",
		peach = "#FF8700",
		yellow = "#F7BB3B",
		green = "#AFD700",
		sapphire = "#36D0E0",
		blue = "#61AFEF",
		sky = "#04A5E5",
		teal = "#B5E8E0",
		lavender = "#7287FD",

		text = "#F2F2BF",
		subtext1 = "#BAC2DE",
		subtext0 = "#A6ADC8",
		overlay2 = "#C3BAC6",
		overlay1 = "#988BA2",
		overlay0 = "#6E6B6B",
		surface2 = "#6E6C7E",
		surface1 = "#575268",
		surface0 = "#302D41",

		base = "#1D1536",
		mantle = "#1C1C19",
		crust = "#161320",
	}

	if not palette then
		if vim.g.colors_name == nil or (vim.g.colors_name ~= nil and not vim.g.colors_name:find("catppuccin")) then
			palette = fallback_palette
		else
			palette = require("catppuccin.palettes").get_palette()
		end

		palette = vim.tbl_extend("force", { none = "NONE" }, palette, require("core.settings").palette_overwrite)
	end

	return palette
end

image

image

@misumisumi
Copy link
Collaborator Author

misumisumi commented Nov 29, 2024

Oh, I overlooked palette_overwrite.
I removed duplicate settings and changed code.

Copy link
Owner

@ayamir ayamir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ayamir ayamir merged commit c8df406 into ayamir:main Nov 29, 2024
2 checks passed
Deg2v pushed a commit to Deg2v/nvimdots that referenced this pull request Jan 16, 2025
@misumisumi misumisumi deleted the fix/module-init branch June 10, 2025 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants