fix: more graceful handling for when a colorscheme was not recognized

dev-doc
Pocco81 3 years ago
parent 6ad271002f
commit 5914d62d8b

@ -15,13 +15,13 @@ function M.get_color_scheme(cs)
local good, color_scheme = pcall(require, "catppuccino.color_schemes." .. cs) local good, color_scheme = pcall(require, "catppuccino.color_schemes." .. cs)
if not good then if not good then
return false, "Catppuccino: the colorscheme '" .. cs .. "' was not recognized." return {status = false, msg = "Catppuccino: the colorscheme '" .. cs .. "' was not recognized. Defaulting to Catppuccino Dark."}, require("catppuccino.color_schemes.catppuccino")
end end
if not (next(remaps) == nil) then if not (next(remaps) == nil) then
return true, vim.tbl_deep_extend("force", color_scheme, remaps) return {status = true}, vim.tbl_deep_extend("force", color_scheme, remaps)
else else
return true, color_scheme return {status = true}, color_scheme
end end
end end

@ -202,10 +202,10 @@ 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
local good, color_scheme = require("catppuccino.core.cs").get_color_scheme(cs) local err, color_scheme = require("catppuccino.core.cs").get_color_scheme(cs)
if not good then if not err.status then
return false, color_scheme -- error message vim.api.nvim_err_writeln(err.msg)
end end
set_cs(color_scheme) set_cs(color_scheme)
@ -217,7 +217,7 @@ function M.apply(cs)
-- uninstantiate to avoid poluting global scope and because they are not needed anymore -- uninstantiate to avoid poluting global scope and because they are not needed anymore
_G.cpc = nil _G.cpc = nil
return true, theme return theme
end end
return M return M

@ -9,13 +9,7 @@ local function load(args)
catppuccino.before_loading() catppuccino.before_loading()
end end
local good, theme = require("catppuccino.core.mapper").apply(args) local theme = require("catppuccino.core.mapper").apply(args)
if not good then
print(theme) -- error message
return
end
utils.load(theme) utils.load(theme)
if (catppuccino.after_loading ~= nil) then if (catppuccino.after_loading ~= nil) then

@ -1,8 +1,7 @@
local good, color_scheme = require("catppuccino.core.cs").get_color_scheme(require("catppuccino.config").options["colorscheme"]) local err, color_scheme = require("catppuccino.core.cs").get_color_scheme(require("catppuccino.config").options["colorscheme"])
if not good then if not err.status then
print(color_scheme) -- error message vim.api.nvim_err_writeln(err.msg)
return
end end
local cpt = color_scheme local cpt = color_scheme

Loading…
Cancel
Save