Skip to content

Commit

Permalink
feat: add transparent bg option
Browse files Browse the repository at this point in the history
fix: add comment explaining lazyvim var
  • Loading branch information
ficcdaf committed Jan 5, 2025
1 parent e53f2c6 commit 32ae5c1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ require("ashen").setup({
vim.cmd("colorscheme ashen")
```

The following default settings are provided. Any settings not self-explanatory will be expanded on below. Any provided settings will be merged with the defaults.
The following default settings are provided. User provided settings will be merged with the defaults. For settings that are not self-explanatory, please see below.

```Lua
{
Expand All @@ -124,6 +124,8 @@ The following default settings are provided. Any settings not self-explanatory w
---@type HighlightMap
merge_override = {},
},
-- use transparent background
transparent = false,
-- force clear other highlights
-- even if no other theme is set
-- (useful for debugging)
Expand Down
5 changes: 5 additions & 0 deletions lua/ashen/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
local M = {}

-- highlight on yank needs to be set
-- differently using lazyvim so we
-- have to track whether the user is running it
M.lazyvim = false

-- default settings
Expand All @@ -17,6 +20,8 @@ M.opts = {
---@type HighlightMap
merge_override = {},
},
-- use transparent background
transparent = false,
-- force clear other highlights
force_hi_clear = false,
-- enable termguicolors on load
Expand Down
12 changes: 12 additions & 0 deletions lua/ashen/theme.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,23 @@ M.map = {
String = { c.red_glowing, nil },
}

---@type string[]
M.transparent_bg = {
"Normal",
"SignColumn",
"LineNr",
}

---override HL groups
---@param opts Options
M.setup = function(opts)
-- TODO: Let users provide palette color names instead of Hex codes
-- and check for it automatically
if opts.transparent then
for _, name in ipairs(M.transparent_bg) do
M.map[name] = util.remove_bg(M.map[name])
end
end
for k, v in pairs(opts.hl.merge_override or {}) do
M.map[k] = vim.tbl_deep_extend("force", M.map[k], v)
end
Expand Down
27 changes: 27 additions & 0 deletions lua/ashen/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ M.hl = function(name, spec)
if not M.is_norm(spec) then
spec = M.normalize_hl(spec)
end
-- check if transparency is enabled
-- this is too costly to do on each hl, though
if require("ashen.theme").transparent_bg[name] then
spec.bg = nil
end
-- -- Debugging output to verify the structure
-- for k, v in pairs(spec) do
-- if type(k) ~= "string" then
Expand All @@ -55,6 +60,28 @@ M.hl = function(name, spec)
return true
end

---@param spec HighlightNormalized
---@return HighlightSpec
local function denormalize(spec)
local fg = spec.fg
spec.fg = nil
local bg = spec.bg
spec.bg = nil
return { fg, bg, spec }
end

---@param spec HighlightSpec|HighlightNormalized
M.remove_bg = function(spec)
if not M.is_norm(spec) then
local norm = M.normalize_hl(spec)
norm.bg = nil
return denormalize(norm)
else
spec.bg = nil
return spec
end
end

function M.link_lang(table, lang)
for hl, input in pairs(table) do
local l = input .. "." .. lang
Expand Down

0 comments on commit 32ae5c1

Please sign in to comment.