feat: add contrast foreground config option

This commit is contained in:
Webhooked
2025-07-25 11:45:27 +02:00
parent 5ae1ef3c4f
commit 024999f6f9
7 changed files with 226 additions and 76 deletions
+64 -6
View File
@@ -25,12 +25,14 @@ M.config = {
return {}
end,
---@type { dark: string, light: string }
background = { dark = "ink", light = "pearl" },
background = { dark = "ink", light = "ink" },
theme = "ink",
---@type { dark: "default"|"contrast", light: "default"|"contrast" }|"default"|"contrast"
foreground = "default",
compile = false,
}
local function check_config(config)
local function check_config(_)
local err
return not err
end
@@ -60,6 +62,22 @@ function M.load(theme)
vim.g.colors_name = "kanso"
vim.o.termguicolors = true
-- Setup autocommand to reload theme when background changes
if not M._autocmd_created then
M._autocmd_created = true
vim.api.nvim_create_autocmd("OptionSet", {
pattern = "background",
callback = function()
if vim.g.colors_name == "kanso" then
-- Clear cached modules to force reload
package.loaded["kanso.colors"] = nil
package.loaded["kanso.themes"] = nil
M.load()
end
end,
})
end
if M.config.compile then
if utils.load_compiled(theme) then
return
@@ -68,7 +86,11 @@ function M.load(theme)
M.compile()
utils.load_compiled(theme)
else
local colors = require("kanso.colors").setup({ theme = theme, colors = M.config.colors })
local foreground_setting = type(M.config.foreground) == "table" and M.config.foreground[vim.o.background]
or M.config.foreground
---@cast foreground_setting "default"|"contrast"
local colors =
require("kanso.colors").setup({ theme = theme, colors = M.config.colors, foreground = foreground_setting })
local highlights = require("kanso.highlights").setup(colors, M.config)
require("kanso.highlights").highlight(highlights, M.config.terminalColors and colors.theme.term or {})
end
@@ -76,9 +98,45 @@ end
function M.compile()
for theme, _ in pairs(require("kanso.themes")) do
local colors = require("kanso.colors").setup({ theme = theme, colors = M.config.colors })
local highlights = require("kanso.highlights").setup(colors, M.config)
require("kanso.utils").compile(theme, highlights, M.config.terminalColors and colors.theme.term or {})
-- Compile both foreground variants if foreground is a table
if type(M.config.foreground) == "table" then
-- Compile for dark mode
local colors_dark = require("kanso.colors").setup({
theme = theme,
colors = M.config.colors,
foreground = M.config.foreground.dark,
})
local highlights_dark = require("kanso.highlights").setup(colors_dark, M.config)
require("kanso.utils").compile(
theme .. "_dark_" .. M.config.foreground.dark,
highlights_dark,
M.config.terminalColors and colors_dark.theme.term or {}
)
-- Compile for light mode
local colors_light = require("kanso.colors").setup({
theme = theme,
colors = M.config.colors,
foreground = M.config.foreground.light,
})
local highlights_light = require("kanso.highlights").setup(colors_light, M.config)
require("kanso.utils").compile(
theme .. "_light_" .. M.config.foreground.light,
highlights_light,
M.config.terminalColors and colors_light.theme.term or {}
)
else
-- Fallback for backward compatibility
local foreground_str = M.config.foreground
---@cast foreground_str "default"|"contrast"
local colors = require("kanso.colors").setup({
theme = theme,
colors = M.config.colors,
foreground = foreground_str,
})
local highlights = require("kanso.highlights").setup(colors, M.config)
require("kanso.utils").compile(theme, highlights, M.config.terminalColors and colors.theme.term or {})
end
end
end