-
Notifications
You must be signed in to change notification settings - Fork 10
/
colors.lua
176 lines (150 loc) · 5.44 KB
/
colors.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
local fmt = string.format
-- Ui highlight color groups
--
-- This file contains the highlight group definitions for both:
-- - feline (statusline)
-- - tabby (tabline)
--
-- The colors are pulled from the current applied colorscheme. This requires
-- that your colorscheme defines the highlight groups queried as well as
-- neovim's vim.g.terminal_color_* (s).
--
-- There is an autocmd that regenerates the highlight group colors on
-- colorscheme change.
local M = {}
local function first_to_upper(s)
return s:sub(1, 1):upper() .. s:sub(2)
end
local function set_highlights(groups)
local lines = {}
for group, opts in pairs(groups) do
if opts.link then
table.insert(lines, fmt("highlight! link %s %s", group, opts.link))
else
table.insert(
lines,
fmt(
"highlight %s guifg=%s guibg=%s gui=%s guisp=%s",
group,
opts.fg or "NONE",
opts.bg or "NONE",
opts.style or "NONE",
opts.sp or "NONE"
)
)
end
end
vim.cmd(table.concat(lines, " | "))
end
local function get_highlight(name)
local hl = vim.api.nvim_get_hl_by_name(name, true)
if hl.link then
return get_highlight(hl.link)
end
local hex = function(n)
if n then
return string.format("#%06x", n)
end
end
local names = { "underline", "undercurl", "bold", "italic", "reverse" }
local styles = {}
for _, n in ipairs(names) do
if hl[n] then
table.insert(styles, n)
end
end
return {
fg = hex(hl.foreground),
bg = hex(hl.background),
sp = hex(hl.special),
style = #styles > 0 and table.concat(styles, ",") or "NONE",
}
end
local function generate_pallet_from_colorscheme()
-- stylua: ignore
local color_map = {
black = { index = 0, default = "#393b44" },
red = { index = 1, default = "#c94f6d" },
green = { index = 2, default = "#81b29a" },
yellow = { index = 3, default = "#dbc074" },
blue = { index = 4, default = "#719cd6" },
magenta = { index = 5, default = "#9d79d6" },
cyan = { index = 6, default = "#63cdcf" },
white = { index = 7, default = "#dfdfe0" },
}
local diagnostic_map = {
hint = { hl = "DiagnosticHint", default = color_map.green.default },
info = { hl = "DiagnosticInfo", default = color_map.blue.default },
warn = { hl = "DiagnosticWarn", default = color_map.yellow.default },
error = { hl = "DiagnosticError", default = color_map.red.default },
}
local pallet = {}
for name, value in pairs(color_map) do
local global_name = "terminal_color_" .. value.index
pallet[name] = vim.g[global_name] and vim.g[global_name] or value.default
end
for name, value in pairs(diagnostic_map) do
pallet[name] = get_highlight(value.hl).fg or value.default
end
pallet.sl = get_highlight("StatusLine")
pallet.tab = get_highlight("TabLine")
pallet.sel = get_highlight("TabLineSel")
pallet.fill = get_highlight("TabLineFill")
return pallet
end
function M.generate_user_config_highlights()
local pal = generate_pallet_from_colorscheme()
-- stylua: ignore
local sl_colors = {
Black = { fg = pal.black, bg = pal.white },
Red = { fg = pal.red, bg = pal.sl.bg },
Green = { fg = pal.green, bg = pal.sl.bg },
Yellow = { fg = pal.yellow, bg = pal.sl.bg },
Blue = { fg = pal.blue, bg = pal.sl.bg },
Magenta = { fg = pal.magenta, bg = pal.sl.bg },
Cyan = { fg = pal.cyan, bg = pal.sl.bg },
White = { fg = pal.white, bg = pal.black },
}
local colors = {}
for name, value in pairs(sl_colors) do
colors["Eden" .. name] = { fg = value.fg, bg = value.bg, style = "bold" }
colors["EdenRv" .. name] = { fg = value.bg, bg = value.fg, style = "bold" }
end
local status = vim.o.background == "dark" and { fg = pal.black, bg = pal.white } or { fg = pal.white, bg = pal.black }
local groups = {
EdenSLHint = { fg = pal.sl.bg, bg = pal.hint, style = "bold" },
EdenSLInfo = { fg = pal.sl.bg, bg = pal.info, style = "bold" },
EdenSLWarn = { fg = pal.sl.bg, bg = pal.warn, style = "bold" },
EdenSLError = { fg = pal.sl.bg, bg = pal.error, style = "bold" },
EdenSLStatus = { fg = status.fg, bg = status.bg, style = "bold" },
EdenSLFtHint = { fg = pal.sel.bg, bg = pal.hint },
EdenSLHintInfo = { fg = pal.hint, bg = pal.info },
EdenSLInfoWarn = { fg = pal.info, bg = pal.warn },
EdenSLWarnError = { fg = pal.warn, bg = pal.error },
EdenSLErrorStatus = { fg = pal.error, bg = status.bg },
EdenSLStatusBg = { fg = status.bg, bg = pal.sl.bg },
EdenSLAlt = pal.sel,
EdenSLAltSep = { fg = pal.sl.bg, bg = pal.sel.bg },
EdenSLGitBranch = { fg = pal.yellow, bg = pal.sl.bg },
-- tabline
EdenTLHead = { fg = pal.fill.bg, bg = pal.cyan },
EdenTLHeadSep = { fg = pal.cyan, bg = pal.fill.bg },
EdenTLActive = { fg = pal.sel.fg, bg = pal.sel.bg, style = "bold" },
EdenTLActiveSep = { fg = pal.sel.bg, bg = pal.fill.bg },
EdenTLBoldLine = { fg = pal.tab.fg, bg = pal.tab.bg, style = "bold" },
EdenTLLineSep = { fg = pal.tab.bg, bg = pal.fill.bg },
}
set_highlights(vim.tbl_extend("force", colors, groups))
end
M.generate_user_config_highlights()
-- Define autocmd that generates the highlight groups from the new colorscheme
-- Then reset the highlights for feline
edn.aug.EdenUiColorschemeReload = {
{
{ "SessionLoadPost", "ColorScheme" },
function()
require("eden.modules.ui.colors").generate_user_config_highlights()
end,
},
}
return M