Skip to content

Commit

Permalink
fix(mapper): use environments instead of modifying _G
Browse files Browse the repository at this point in the history
  • Loading branch information
LordMZTE committed Jul 1, 2023
1 parent 1289437 commit dc9d1ef
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 deletions lua/catppuccin/lib/mapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,46 @@ end

function M.apply(flavour)
flavour = flavour or require("catppuccin").flavour
-- Borrowing global var
_G._O = O
_G._C = C
_G._U = U

_G.O = require("catppuccin").options
_G.C = require("catppuccin.palettes").get_palette(flavour)
_G.U = require "catppuccin.utils.colors"
local env = {
O = require("catppuccin").options,
C = require("catppuccin.palattes").get_palette(flavour),
U = require "catppuccin.utils.colors",
}

C.none = "NONE"
setmetatable(env, { __index = _G })

local dim_percentage = O.dim_inactive.percentage
C.dim = O.dim_inactive.shade == "dark"
local function theme_with_env()
C.none = "NONE"

local dim_percentage = O.dim_inactive.percentage
C.dim = O.dim_inactive.shade == "dark"
and U.vary_color(
{ latte = U.darken(C.base, dim_percentage, C.mantle) },
U.darken(C.base, dim_percentage, C.mantle)
)
or U.vary_color(
{ latte = U.lighten("#FBFCFD", dim_percentage, C.base) },
U.lighten(C.surface0, dim_percentage, C.base)
)
or U.vary_color(
{ latte = U.lighten("#FBFCFD", dim_percentage, C.base) },
U.lighten(C.surface0, dim_percentage, C.base)
)

local theme = {}
theme.syntax = require("catppuccin.groups.syntax").get()
theme.editor = require("catppuccin.groups.editor").get()
theme.integrations = get_integrations() -- plugins
theme.terminal = require("catppuccin.groups.terminal").get() -- terminal colors
local user_highlights = require("catppuccin").options.highlight_overrides
if type(user_highlights[flavour]) == "function" then user_highlights[flavour] = user_highlights[flavour](C) end
theme.custom_highlights = vim.tbl_deep_extend(
"keep",
user_highlights[flavour] or {},
type(user_highlights.all) == "function" and user_highlights.all(C) or user_highlights.all or {}
)
local theme = {}
theme.syntax = require("catppuccin.groups.syntax").get()
theme.editor = require("catppuccin.groups.editor").get()
theme.integrations = get_integrations() -- plugins
theme.terminal = require("catppuccin.groups.terminal").get() -- terminal colors
local user_highlights = require("catppuccin").options.highlight_overrides
if type(user_highlights[flavour]) == "function" then user_highlights[flavour] = user_highlights[flavour](C) end
theme.custom_highlights = vim.tbl_deep_extend(
"keep",
user_highlights[flavour] or {},
type(user_highlights.all) == "function" and user_highlights.all(C) or user_highlights.all or {}
)

-- Returning global var
_G.O = _G._O
_G.C = _G._C
_G.U = _G._U
return theme
end

return theme
return setfenv(theme_with_env, env)()
end

return M

0 comments on commit dc9d1ef

Please sign in to comment.