131 lines
3.7 KiB
Lua
131 lines
3.7 KiB
Lua
local M = {}
|
|
|
|
---@class N8nConfig
|
|
M.config = {
|
|
transparent = false, -- enable transparent background
|
|
terminal_colors = true, -- set terminal colors
|
|
dim_inactive = false, -- dim inactive windows
|
|
styles = {
|
|
comments = { italic = true },
|
|
keywords = {},
|
|
functions = {},
|
|
strings = {},
|
|
variables = {},
|
|
},
|
|
---@type table<string, vim.api.keyset.highlight>
|
|
on_highlights = function(highlights, colors) end,
|
|
---@type fun(colors: table): table
|
|
on_colors = function(colors) return colors end,
|
|
}
|
|
|
|
---@param opts? N8nConfig
|
|
function M.setup(opts)
|
|
M.config = vim.tbl_deep_extend("force", M.config, opts or {})
|
|
end
|
|
|
|
function M.load()
|
|
if vim.g.colors_name then
|
|
vim.cmd("hi clear")
|
|
end
|
|
if vim.fn.exists("syntax_on") then
|
|
vim.cmd("syntax reset")
|
|
end
|
|
|
|
vim.o.termguicolors = true
|
|
vim.g.colors_name = "n8n"
|
|
vim.o.background = "dark"
|
|
|
|
local theme = require("n8n.theme")
|
|
local groups_mod = require("n8n.groups")
|
|
local c = theme.colors()
|
|
|
|
-- Let user modify colors
|
|
if type(M.config.on_colors) == "function" then
|
|
local custom = M.config.on_colors(c)
|
|
if custom then
|
|
c = vim.tbl_deep_extend("force", c, custom)
|
|
end
|
|
end
|
|
|
|
-- Handle transparent mode
|
|
if M.config.transparent then
|
|
c.bg = "NONE"
|
|
c.bg_sidebar = "NONE"
|
|
c.bg_float = "NONE"
|
|
end
|
|
|
|
local groups = groups_mod.setup({ colors = c })
|
|
|
|
-- Apply style overrides
|
|
if M.config.styles.comments then
|
|
groups.Comment = vim.tbl_extend("force", groups.Comment or {}, M.config.styles.comments)
|
|
groups["@comment"] = vim.tbl_extend("force", groups["@comment"] or {}, M.config.styles.comments)
|
|
end
|
|
if M.config.styles.keywords then
|
|
for _, key in ipairs({ "Keyword", "Statement", "Conditional", "Repeat", "@keyword" }) do
|
|
if groups[key] then
|
|
groups[key] = vim.tbl_extend("force", groups[key], M.config.styles.keywords)
|
|
end
|
|
end
|
|
end
|
|
if M.config.styles.functions then
|
|
for _, key in ipairs({ "Function", "@function", "@function.call" }) do
|
|
if groups[key] then
|
|
groups[key] = vim.tbl_extend("force", groups[key], M.config.styles.functions)
|
|
end
|
|
end
|
|
end
|
|
if M.config.styles.strings then
|
|
for _, key in ipairs({ "String", "@string" }) do
|
|
if groups[key] then
|
|
groups[key] = vim.tbl_extend("force", groups[key], M.config.styles.strings)
|
|
end
|
|
end
|
|
end
|
|
if M.config.styles.variables then
|
|
for _, key in ipairs({ "Identifier", "@variable" }) do
|
|
if groups[key] then
|
|
groups[key] = vim.tbl_extend("force", groups[key], M.config.styles.variables)
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Dim inactive windows
|
|
if M.config.dim_inactive then
|
|
groups.NormalNC = { fg = c.fg_dark, bg = c.bg_dark }
|
|
end
|
|
|
|
-- Let user modify highlights
|
|
if type(M.config.on_highlights) == "function" then
|
|
M.config.on_highlights(groups, c)
|
|
end
|
|
|
|
-- Apply all highlight groups
|
|
for group, hl in pairs(groups) do
|
|
vim.api.nvim_set_hl(0, group, hl)
|
|
end
|
|
|
|
-- Set terminal colors
|
|
if M.config.terminal_colors then
|
|
local t = theme.colors().terminal
|
|
vim.g.terminal_color_0 = t.black
|
|
vim.g.terminal_color_1 = t.red
|
|
vim.g.terminal_color_2 = t.green
|
|
vim.g.terminal_color_3 = t.yellow
|
|
vim.g.terminal_color_4 = t.blue
|
|
vim.g.terminal_color_5 = t.magenta
|
|
vim.g.terminal_color_6 = t.cyan
|
|
vim.g.terminal_color_7 = t.white
|
|
vim.g.terminal_color_8 = t.bright_black
|
|
vim.g.terminal_color_9 = t.bright_red
|
|
vim.g.terminal_color_10 = t.bright_green
|
|
vim.g.terminal_color_11 = t.bright_yellow
|
|
vim.g.terminal_color_12 = t.bright_blue
|
|
vim.g.terminal_color_13 = t.bright_magenta
|
|
vim.g.terminal_color_14 = t.bright_cyan
|
|
vim.g.terminal_color_15 = t.bright_white
|
|
end
|
|
end
|
|
|
|
return M
|