cleaner global config resolver

This commit is contained in:
Michael Chris Lopez
2021-10-26 18:21:21 +08:00
parent cc76bd2e86
commit b51ca3f063
3 changed files with 39 additions and 22 deletions

View File

@@ -45,7 +45,7 @@ local function generate(p, opt)
ErrorMsg { Error }, -- error messages on the command line ErrorMsg { Error }, -- error messages on the command line
WarningMsg { fg = p.wood }, -- warning messages WarningMsg { fg = p.wood }, -- warning messages
Comment { fg = Normal.bg.li(opt.lighten_comments or 38).de(24), gui = opt.comment_gui or "italic" }, -- any comment Comment { fg = Normal.bg.li(opt.lighten_comments or 38).de(24), gui = opt.italic_comments ~= false and "italic" or "NONE" }, -- any comment
Conceal { fg = p1.fg5, gui = "bold,italic" }, -- placeholder characters substituted for concealed text (see 'conceallevel') Conceal { fg = p1.fg5, gui = "bold,italic" }, -- placeholder characters substituted for concealed text (see 'conceallevel')
Cursor { bg = p.fg.li(20), fg = p1.bg }, -- character under the cursor Cursor { bg = p.fg.li(20), fg = p1.bg }, -- character under the cursor

View File

@@ -1,12 +1,21 @@
local M = {} local M = {}
function concat_config(prefix, suffixes)
local config = {}
for i, suffix in ipairs(suffixes) do
config[suffix] = vim.g[prefix .. "_" .. suffix]
end
return config
end
function M.get_global_config(prefix, base_bg) function M.get_global_config(prefix, base_bg)
local common = { local common = concat_config(prefix, {
solid_vert_split = vim.g[prefix .. "_solid_vert_split"], "solid_vert_split",
solid_float_border = vim.g[prefix .. "_solid_float_border"], "solid_float_border",
solid_line_nr = vim.g[prefix .. "_solid_line_nr"], "solid_line_nr",
comment_gui = vim.g[prefix .. "_italic_comments"] ~= false and "italic" or "NONE", "italic_comments",
} })
if base_bg == "light" then if base_bg == "light" then
if vim.g[prefix .. "_dim_noncurrent_window"] then if vim.g[prefix .. "_dim_noncurrent_window"] then
vim.notify( vim.notify(
@@ -15,21 +24,29 @@ function M.get_global_config(prefix, base_bg)
{ title = "zenbones" } { title = "zenbones" }
) )
end end
return vim.tbl_extend("keep", { return vim.tbl_extend(
lightness = vim.g[prefix .. "_lightness"], "keep",
darken_noncurrent_window = vim.g[prefix .. "_darken_noncurrent_window"], concat_config(prefix, {
darken_comments = vim.g[prefix .. "_darken_comments"], "lightness",
darken_line_nr = vim.g[prefix .. "_darken_line_nr"], "darken_noncurrent_window",
darken_non_text = vim.g[prefix .. "_darken_non_text"], "darken_comments",
}, common) "darken_line_nr",
"darken_non_text",
}),
common
)
else else
return vim.tbl_extend("keep", { return vim.tbl_extend(
darkness = vim.g[prefix .. "_darkness"], "keep",
lighten_noncurrent_window = vim.g[prefix .. "_lighten_noncurrent_window"], concat_config(prefix, {
lighten_comments = vim.g[prefix .. "_lighten_comments"], "darkness",
lighten_line_nr = vim.g[prefix .. "_lighten_line_nr"], "lighten_noncurrent_window",
lighten_non_text = vim.g[prefix .. "_lighten_non_text"], "lighten_comments",
}, common) "lighten_line_nr",
"lighten_non_text",
}),
common
)
end end
end end

View File

@@ -45,7 +45,7 @@ local function generate(p, opt)
ErrorMsg { Error }, -- error messages on the command line ErrorMsg { Error }, -- error messages on the command line
WarningMsg { fg = p.wood }, -- warning messages WarningMsg { fg = p.wood }, -- warning messages
Comment { fg = Normal.bg.da(opt.darken_comments or 38).de(28), gui = opt.comment_gui or "italic" }, -- any comment Comment { fg = Normal.bg.da(opt.darken_comments or 38).de(28), gui = opt.italic_comments ~= false and "italic" or "NONE" }, -- any comment
Conceal { fg = p1.fg3, gui = "bold,italic" }, -- placeholder characters substituted for concealed text (see 'conceallevel') Conceal { fg = p1.fg3, gui = "bold,italic" }, -- placeholder characters substituted for concealed text (see 'conceallevel')
Cursor { bg = p.fg, fg = p1.bg }, -- character under the cursor Cursor { bg = p.fg, fg = p1.bg }, -- character under the cursor