Add config field to disable bold styles across the whole theme

This commit is contained in:
Kacper Hemperek
2025-05-21 09:18:51 +02:00
parent f7080992e7
commit aaa72b68b6
6 changed files with 624 additions and 550 deletions
+40 -13
View File
@@ -11,9 +11,9 @@ function M.setup(colors, config)
-- ColorColumn Used for the columns set with 'colorcolumn'. -- ColorColumn Used for the columns set with 'colorcolumn'.
ColorColumn = { bg = theme.ui.bg_p1 }, ColorColumn = { bg = theme.ui.bg_p1 },
-- Conceal Placeholder characters substituted for concealed text (see 'conceallevel'). -- Conceal Placeholder characters substituted for concealed text (see 'conceallevel').
Conceal = { fg = theme.ui.special, bold = true }, Conceal = { fg = theme.ui.special, bold = config.bold },
-- CurSearch Used for highlighting a search pattern under the cursor (see 'hlsearch'). -- CurSearch Used for highlighting a search pattern under the cursor (see 'hlsearch').
CurSearch = { fg = theme.ui.fg, bg = theme.ui.bg_search, bold = true }, CurSearch = { fg = theme.ui.fg, bg = theme.ui.bg_search, bold = config.bold },
-- Cursor Character under the cursor. -- Cursor Character under the cursor.
Cursor = { fg = theme.ui.cursor_fg, bg = theme.ui.cursor_bg }, Cursor = { fg = theme.ui.cursor_fg, bg = theme.ui.cursor_bg },
-- lCursor Character under the cursor when |language-mapping| is used (see 'guicursor'). -- lCursor Character under the cursor when |language-mapping| is used (see 'guicursor').
@@ -62,11 +62,11 @@ function M.setup(colors, config)
-- CursorLineFold Like FoldColumn when 'cursorline' is set for the cursor line. -- CursorLineFold Like FoldColumn when 'cursorline' is set for the cursor line.
-- CursorLineSign Like SignColumn when 'cursorline' is set for the cursor line. -- CursorLineSign Like SignColumn when 'cursorline' is set for the cursor line.
-- MatchParen Character under the cursor or just before it, if it is a paired bracket, and its match. |pi_paren.txt| -- MatchParen Character under the cursor or just before it, if it is a paired bracket, and its match. |pi_paren.txt|
MatchParen = { fg = theme.diag.warning, bold = true }, MatchParen = { fg = theme.diag.warning, bold = config.bold },
-- ModeMsg 'showmode' message (e.g., "-- INSERT --"). -- ModeMsg 'showmode' message (e.g., "-- INSERT --").
ModeMsg = { fg = theme.diag.warning, bold = true }, ModeMsg = { fg = theme.diag.warning, bold = config.bold },
-- MsgArea Area for messages and cmdline. -- MsgArea Area for messages and cmdline.
MsgArea = vim.o.cmdheight == 0 and { link = 'StatusLine' } or { fg = theme.ui.fg_dim }, MsgArea = vim.o.cmdheight == 0 and { link = "StatusLine" } or { fg = theme.ui.fg_dim },
-- MsgSeparator Separator for scrolled messages |msgsep|. -- MsgSeparator Separator for scrolled messages |msgsep|.
MsgSeparator = { bg = vim.o.cmdheight == 0 and theme.ui.bg or theme.ui.bg_m3 }, MsgSeparator = { bg = vim.o.cmdheight == 0 and theme.ui.bg or theme.ui.bg_m3 },
-- MoreMsg |more-prompt| -- MoreMsg |more-prompt|
@@ -78,9 +78,16 @@ function M.setup(colors, config)
-- NormalFloat Normal text in floating windows. -- NormalFloat Normal text in floating windows.
NormalFloat = { fg = theme.ui.float.fg, bg = config.transparent and theme.ui.none or theme.ui.float.bg }, NormalFloat = { fg = theme.ui.float.fg, bg = config.transparent and theme.ui.none or theme.ui.float.bg },
-- FloatBorder Border of floating windows. -- FloatBorder Border of floating windows.
FloatBorder = { fg = theme.ui.float.fg_border, bg = config.transparent and theme.ui.none or theme.ui.float.bg_border }, FloatBorder = {
fg = theme.ui.float.fg_border,
bg = config.transparent and theme.ui.none or theme.ui.float.bg_border,
},
-- FloatTitle Title of floating windows. -- FloatTitle Title of floating windows.
FloatTitle = { fg = theme.ui.special, bg = config.transparent and theme.ui.none or theme.ui.float.bg_border, bold = true }, FloatTitle = {
fg = theme.ui.special,
bg = config.transparent and theme.ui.none or theme.ui.float.bg_border,
bold = config.bold,
},
-- FloatFooter Footer of floating windows. -- FloatFooter Footer of floating windows.
FloatFooter = { fg = theme.ui.nontext, bg = config.transparent and theme.ui.none or theme.ui.float.bg_border }, FloatFooter = { fg = theme.ui.nontext, bg = config.transparent and theme.ui.none or theme.ui.float.bg_border },
-- NormalNC Normal text in non-current windows. -- NormalNC Normal text in non-current windows.
@@ -126,9 +133,13 @@ function M.setup(colors, config)
-- TabLineFill Tab pages line, where there are no labels. -- TabLineFill Tab pages line, where there are no labels.
TabLineFill = { bg = theme.ui.none }, TabLineFill = { bg = theme.ui.none },
-- TabLineSel Tab pages line, active tab page label. -- TabLineSel Tab pages line, active tab page label.
TabLineSel = { fg = theme.ui.fg_dim, bg = not config.transparent and theme.ui.bg_p1 or theme.ui.none, bold = true }, TabLineSel = {
fg = theme.ui.fg_dim,
bg = not config.transparent and theme.ui.bg_p1 or theme.ui.none,
bold = config.bold,
},
-- Title Titles for output from ":set all", ":autocmd" etc. -- Title Titles for output from ":set all", ":autocmd" etc.
Title = { fg = theme.syn.fun, bold = true }, Title = { fg = theme.syn.fun, bold = config.bold },
-- Visual Visual mode selection. -- Visual Visual mode selection.
Visual = { bg = theme.ui.bg_visual }, Visual = { bg = theme.ui.bg_visual },
-- VisualNOS Visual mode selection when vim is "Not Owning the Selection". -- VisualNOS Visual mode selection when vim is "Not Owning the Selection".
@@ -177,10 +188,26 @@ function M.setup(colors, config)
DiagnosticVirtualTextInfo = { link = "DiagnosticInfo" }, DiagnosticVirtualTextInfo = { link = "DiagnosticInfo" },
DiagnosticVirtualTextHint = { link = "DiagnosticHint" }, DiagnosticVirtualTextHint = { link = "DiagnosticHint" },
DiagnosticUnderlineError = { undercurl = config.undercurl, underline = not config.undercurl, sp = theme.diag.error }, DiagnosticUnderlineError = {
DiagnosticUnderlineWarn = { undercurl = config.undercurl, underline = not config.undercurl, sp = theme.diag.warning }, undercurl = config.undercurl,
DiagnosticUnderlineInfo = { undercurl = config.undercurl, underline = not config.undercurl, sp = theme.diag.info }, underline = not config.undercurl,
DiagnosticUnderlineHint = { undercurl = config.undercurl, underline = not config.undercurl, sp = theme.diag.hint }, sp = theme.diag.error,
},
DiagnosticUnderlineWarn = {
undercurl = config.undercurl,
underline = not config.undercurl,
sp = theme.diag.warning,
},
DiagnosticUnderlineInfo = {
undercurl = config.undercurl,
underline = not config.undercurl,
sp = theme.diag.info,
},
DiagnosticUnderlineHint = {
undercurl = config.undercurl,
underline = not config.undercurl,
sp = theme.diag.hint,
},
LspSignatureActiveParameter = { fg = theme.diag.warning }, LspSignatureActiveParameter = { fg = theme.diag.warning },
LspCodeLens = { fg = theme.syn.comment }, LspCodeLens = { fg = theme.syn.comment },
+4 -4
View File
@@ -12,15 +12,15 @@ function M.setup(colors, config)
-- ["@lsp.type.function"] = { link = "Function" }, -- ["@lsp.type.function"] = { link = "Function" },
-- ["@lsp.type.interface"] = { link = "Structure" }, -- ["@lsp.type.interface"] = { link = "Structure" },
["@lsp.type.macro"] = { link = "Macro" }, ["@lsp.type.macro"] = { link = "Macro" },
["@lsp.type.method"] = { link = "@function.method" }, -- Function ["@lsp.type.method"] = { link = "@function.method" }, -- Function
["@lsp.type.namespace"] = { link = "@module" }, -- Structure ["@lsp.type.namespace"] = { link = "@module" }, -- Structure
["@lsp.type.parameter"] = { link = "@variable.parameter" }, -- Identifier ["@lsp.type.parameter"] = { link = "@variable.parameter" }, -- Identifier
-- ["@lsp.type.property"] = { link = "Identifier" }, -- ["@lsp.type.property"] = { link = "Identifier" },
-- ["@lsp.type.struct"] = { link = "Structure" }, -- ["@lsp.type.struct"] = { link = "Structure" },
-- ["@lsp.type.type"] = { link = "Type" }, -- ["@lsp.type.type"] = { link = "Type" },
-- ["@lsp.type.typeParameter"] = { link = "TypeDef" }, -- ["@lsp.type.typeParameter"] = { link = "TypeDef" },
["@lsp.type.variable"] = { fg = "none" }, -- Identifier ["@lsp.type.variable"] = { fg = "none" }, -- Identifier
["@lsp.type.comment"] = { link = "Comment" }, -- Comment ["@lsp.type.comment"] = { link = "Comment" }, -- Comment
["@lsp.type.const"] = { link = "Constant" }, ["@lsp.type.const"] = { link = "Constant" },
["@lsp.type.comparison"] = { link = "Operator" }, ["@lsp.type.comparison"] = { link = "Operator" },
@@ -52,7 +52,7 @@ function M.setup(colors, config)
["@lsp.typemod.variable.injected"] = { link = "@variable" }, ["@lsp.typemod.variable.injected"] = { link = "@variable" },
["@lsp.typemod.function.readonly"] = { fg = theme.syn.fun, bold = true }, ["@lsp.typemod.function.readonly"] = { fg = theme.syn.fun, bold = config.bold },
} }
end end
File diff suppressed because it is too large Load Diff
+12 -6
View File
@@ -9,8 +9,11 @@ function M.setup(colors, config)
return { return {
-- *Comment any comment -- *Comment any comment
Comment = vim.tbl_extend("force", { fg = theme.syn.comment }, config.disableItalics and {} or config Comment = vim.tbl_extend(
.commentStyle), "force",
{ fg = theme.syn.comment },
config.disableItalics and {} or config.commentStyle
),
-- *Constant any constant -- *Constant any constant
Constant = { fg = theme.syn.constant }, Constant = { fg = theme.syn.constant },
@@ -38,8 +41,11 @@ function M.setup(colors, config)
-- Operator "sizeof", "+", "*", etc. -- Operator "sizeof", "+", "*", etc.
Operator = { fg = theme.syn.operator }, Operator = { fg = theme.syn.operator },
-- Keyword any other keyword -- Keyword any other keyword
Keyword = vim.tbl_extend("force", { fg = theme.syn.keyword }, config.disableItalics and {} or config Keyword = vim.tbl_extend(
.keywordStyle), "force",
{ fg = theme.syn.keyword },
config.disableItalics and {} or config.keywordStyle
),
-- Exception try, catch, throw -- Exception try, catch, throw
Exception = { fg = theme.syn.special2 }, Exception = { fg = theme.syn.special2 },
@@ -67,7 +73,7 @@ function M.setup(colors, config)
-- *Underlined text that stands out, HTML links -- *Underlined text that stands out, HTML links
Underlined = { fg = theme.syn.special1, underline = true }, Underlined = { fg = theme.syn.special1, underline = true },
Bold = { bold = true }, Bold = { bold = config.bold },
Italic = { italic = not config.disableItalics }, Italic = { italic = not config.disableItalics },
-- *Ignore left blank, hidden |hl-Ignore| -- *Ignore left blank, hidden |hl-Ignore|
@@ -77,7 +83,7 @@ function M.setup(colors, config)
Error = { fg = theme.diag.error }, Error = { fg = theme.diag.error },
-- *Todo anything that needs extra attention; mostly the keywords TODO FIXME WARNING and XXX -- *Todo anything that needs extra attention; mostly the keywords TODO FIXME WARNING and XXX
Todo = { fg = theme.ui.fg_reverse, bg = theme.diag.info, bold = true }, Todo = { fg = theme.ui.fg_reverse, bg = theme.diag.info, bold = config.bold },
qfLineNr = { link = "lineNr" }, qfLineNr = { link = "lineNr" },
qfFileName = { link = "Directory" }, qfFileName = { link = "Directory" },
+9 -6
View File
@@ -77,8 +77,11 @@ function M.setup(colors, config)
-- @keyword.modifier keywords defining type modifiers (e.g. `const`, `static`, `public`) -- @keyword.modifier keywords defining type modifiers (e.g. `const`, `static`, `public`)
-- @keyword.repeat keywords related to loops (e.g. `for`, `while`) -- @keyword.repeat keywords related to loops (e.g. `for`, `while`)
-- @keyword.return keywords like `return` and `yield` -- @keyword.return keywords like `return` and `yield`
["@keyword.return"] = vim.tbl_extend("force", { fg = theme.syn.special3 }, ["@keyword.return"] = vim.tbl_extend(
config.disableItalics and {} or config.keywordStyle), "force",
{ fg = theme.syn.special3 },
config.disableItalics and {} or config.keywordStyle
),
-- @keyword.debug keywords related to debugging -- @keyword.debug keywords related to debugging
-- @keyword.exception keywords related to exceptions (e.g. `throw`, `catch`) -- @keyword.exception keywords related to exceptions (e.g. `throw`, `catch`)
["@keyword.exception"] = vim.tbl_extend("force", { fg = theme.syn.special3 }, config.statementStyle), ["@keyword.exception"] = vim.tbl_extend("force", { fg = theme.syn.special3 }, config.statementStyle),
@@ -102,15 +105,15 @@ function M.setup(colors, config)
-- @comment.documentation comments documenting code -- @comment.documentation comments documenting code
-- --
-- @comment.error error-type comments (e.g. `ERROR`, `FIXME`, `DEPRECATED`) -- @comment.error error-type comments (e.g. `ERROR`, `FIXME`, `DEPRECATED`)
["@comment.error"] = { fg = theme.ui.fg, bg = theme.diag.error, bold = true }, ["@comment.error"] = { fg = theme.ui.fg, bg = theme.diag.error, bold = config.bold },
-- @comment.warning warning-type comments (e.g. `WARNING`, `FIX`, `HACK`) -- @comment.warning warning-type comments (e.g. `WARNING`, `FIX`, `HACK`)
["@comment.warning"] = { fg = theme.ui.fg_reverse, bg = theme.diag.warning, bold = true }, ["@comment.warning"] = { fg = theme.ui.fg_reverse, bg = theme.diag.warning, bold = config.bold },
-- @comment.todo todo-type comments (e.g. `TODO`, `WIP`) -- @comment.todo todo-type comments (e.g. `TODO`, `WIP`)
-- @comment.note note-type comments (e.g. `NOTE`, `INFO`, `XXX`) -- @comment.note note-type comments (e.g. `NOTE`, `INFO`, `XXX`)
["@comment.note"] = { fg = theme.ui.fg_reverse, bg = theme.diag.hint, bold = true }, ["@comment.note"] = { fg = theme.ui.fg_reverse, bg = theme.diag.hint, bold = config.bold },
-- --
-- @markup.strong bold text -- @markup.strong bold text
["@markup.strong"] = { bold = true }, ["@markup.strong"] = { bold = config.bold },
-- @markup.italic italic text -- @markup.italic italic text
["@markup.italic"] = { italic = true }, ["@markup.italic"] = { italic = true },
-- @markup.strikethrough struck-through text -- @markup.strikethrough struck-through text
+60 -59
View File
@@ -8,89 +8,90 @@ local M = {}
--- default config --- default config
---@class KansoConfig ---@class KansoConfig
M.config = { M.config = {
undercurl = true, bold = true,
commentStyle = { italic = true }, undercurl = true,
functionStyle = {}, commentStyle = { italic = true },
keywordStyle = { italic = true }, functionStyle = {},
statementStyle = {}, keywordStyle = { italic = true },
typeStyle = {}, statementStyle = {},
transparent = false, typeStyle = {},
dimInactive = false, transparent = false,
terminalColors = true, dimInactive = false,
disableItalics = false, terminalColors = true,
colors = { theme = { zen = {}, pearl = {}, ink = {}, all = {} }, palette = {} }, disableItalics = false,
---@type fun(colors: KansoColorsSpec): table<string, table> colors = { theme = { zen = {}, pearl = {}, ink = {}, all = {} }, palette = {} },
overrides = function() ---@type fun(colors: KansoColorsSpec): table<string, table>
return {} overrides = function()
end, return {}
---@type { dark: string, light: string } end,
background = { dark = "ink", light = "pearl" }, ---@type { dark: string, light: string }
theme = "ink", background = { dark = "ink", light = "pearl" },
compile = false, theme = "ink",
compile = false,
} }
local function check_config(config) local function check_config(config)
local err local err
return not err return not err
end end
--- update global configuration with user settings --- update global configuration with user settings
---@param config? KansoConfig user configuration ---@param config? KansoConfig user configuration
function M.setup(config) function M.setup(config)
if check_config(config) then if check_config(config) then
M.config = vim.tbl_deep_extend("force", M.config, config or {}) M.config = vim.tbl_deep_extend("force", M.config, config or {})
else else
vim.notify("Kanso: Errors found while loading user config. Using default config.", vim.log.levels.ERROR) vim.notify("Kanso: Errors found while loading user config. Using default config.", vim.log.levels.ERROR)
end end
end end
--- load the colorscheme --- load the colorscheme
---@param theme? string ---@param theme? string
function M.load(theme) function M.load(theme)
local utils = require("kanso.utils") local utils = require("kanso.utils")
theme = theme or M.config.background[vim.o.background] or M.config.theme theme = theme or M.config.background[vim.o.background] or M.config.theme
M._CURRENT_THEME = theme M._CURRENT_THEME = theme
if vim.g.colors_name then if vim.g.colors_name then
vim.cmd("hi clear") vim.cmd("hi clear")
end end
vim.g.colors_name = "kanso" vim.g.colors_name = "kanso"
vim.o.termguicolors = true vim.o.termguicolors = true
if M.config.compile then if M.config.compile then
if utils.load_compiled(theme) then if utils.load_compiled(theme) then
return return
end end
M.compile() M.compile()
utils.load_compiled(theme) utils.load_compiled(theme)
else else
local colors = require("kanso.colors").setup({ theme = theme, colors = M.config.colors }) local colors = require("kanso.colors").setup({ theme = theme, colors = M.config.colors })
local highlights = require("kanso.highlights").setup(colors, M.config) local highlights = require("kanso.highlights").setup(colors, M.config)
require("kanso.highlights").highlight(highlights, M.config.terminalColors and colors.theme.term or {}) require("kanso.highlights").highlight(highlights, M.config.terminalColors and colors.theme.term or {})
end end
end end
function M.compile() function M.compile()
for theme, _ in pairs(require("kanso.themes")) do for theme, _ in pairs(require("kanso.themes")) do
local colors = require("kanso.colors").setup({ theme = theme, colors = M.config.colors }) local colors = require("kanso.colors").setup({ theme = theme, colors = M.config.colors })
local highlights = require("kanso.highlights").setup(colors, M.config) local highlights = require("kanso.highlights").setup(colors, M.config)
require("kanso.utils").compile(theme, highlights, M.config.terminalColors and colors.theme.term or {}) require("kanso.utils").compile(theme, highlights, M.config.terminalColors and colors.theme.term or {})
end end
end end
vim.api.nvim_create_user_command("KansoCompile", function() vim.api.nvim_create_user_command("KansoCompile", function()
for mod, _ in pairs(package.loaded) do for mod, _ in pairs(package.loaded) do
if mod:match("^kanso%.") then if mod:match("^kanso%.") then
package.loaded[mod] = nil package.loaded[mod] = nil
end end
end end
M.compile() M.compile()
vim.notify("Kanso: compiled successfully!", vim.log.levels.INFO) vim.notify("Kanso: compiled successfully!", vim.log.levels.INFO)
M.load(M._CURRENT_THEME) M.load(M._CURRENT_THEME)
vim.api.nvim_exec_autocmds("ColorScheme", { modeline = false }) vim.api.nvim_exec_autocmds("ColorScheme", { modeline = false })
end, {}) end, {})
return M return M