feat: securely call colorschemes (aka flavors)

dev-assets
Pocco81 3 years ago
parent bd12fdbab6
commit a04903c372

@ -12,10 +12,16 @@ end
function M.get_color_scheme(cs) function M.get_color_scheme(cs)
local remaps = M.get_remaps() local remaps = M.get_remaps()
local good, color_scheme = pcall(require, "catppuccino.color_schemes." .. cs)
if not good then
return false, "Catppuccino: the colorscheme '" .. cs .. "' was not recognized."
end
if not (next(remaps) == nil) then if not (next(remaps) == nil) then
return vim.tbl_deep_extend("force", require("catppuccino.color_schemes." .. cs), remaps) return true, vim.tbl_deep_extend("force", color_scheme, remaps)
else else
return require("catppuccino.color_schemes." .. cs) return true, color_scheme
end end
end end

@ -187,8 +187,14 @@ end
function M.apply(cs) function M.apply(cs)
_G.cpc = require("catppuccino.config").options _G.cpc = require("catppuccino.config").options
cs = cs or cpc.colorscheme cs = cs or cpc.colorscheme
-- _G.cpt = require("catppuccino.color_schemes." .. cs) local good, color_scheme = require("catppuccino.core.cs").get_color_scheme(cs)
_G.cpt = require("catppuccino.core.cs").get_color_scheme(cs)
if not good then
print(color_scheme) -- error message
return
end
_G.cpt = color_scheme
local theme = {} local theme = {}
theme.base = get_base() theme.base = get_base()

@ -1,4 +1,11 @@
local cpt = require("catppuccino.core.cs").get_color_scheme(require("catppuccino.config").options["cptcheme"]) local good, color_scheme = require("catppuccino.core.cs").get_color_scheme(require("catppuccino.config").options["cptcheme"])
if not good then
print(color_scheme) -- error message
return
end
local cpt = color_scheme
local catppuccino = {} local catppuccino = {}
catppuccino.normal = { catppuccino.normal = {

@ -1,4 +1,11 @@
local cpt = require("catppuccino.core.cs").get_color_scheme(require("catppuccino.config").options["colorscheme"]) local good, color_scheme = require("catppuccino.core.cs").get_color_scheme(require("catppuccino.config").options["cptcheme"])
if not good then
print(color_scheme) -- error message
return
end
local cpt = color_scheme
local catppuccino = {} local catppuccino = {}
catppuccino.normal = { catppuccino.normal = {

Loading…
Cancel
Save