consolidated colors
This commit is contained in:
1 parent
e3b43d2274
commit
857d5d78e8
5 files changed
+493
-299
No files matched your search
@@ -0,0 +1,168 @@
|
||||
local M = {}
|
||||
|
||||
-- These anchors describe the role of each ANSI color in darcula_lush. They
|
||||
-- intentionally use only the 16-color palette so the fallback also works on
|
||||
-- a Linux console and other terminals without 256-color support.
|
||||
local ansi_anchors = {
|
||||
{index = 0, rgb = 0x101017}, -- black: editor surfaces
|
||||
{index = 1, rgb = 0x3a1e1e}, -- dark red: error/diff surfaces
|
||||
{index = 2, rgb = 0x1e3a1e}, -- dark green: added/success surfaces
|
||||
{index = 3, rgb = 0x4d3d22}, -- dark yellow: changed surfaces
|
||||
{index = 4, rgb = 0x344074}, -- dark blue: mode surfaces
|
||||
{index = 7, rgb = 0xb0abac}, -- light gray: normal text
|
||||
{index = 8, rgb = 0x5f595a}, -- dark gray: muted text/selections
|
||||
{index = 9, rgb = 0xc96b68}, -- bright red: errors
|
||||
{index = 10, rgb = 0x6a906a}, -- bright green: strings
|
||||
{index = 11, rgb = 0xc18a53}, -- bright yellow: keywords/functions
|
||||
{index = 12, rgb = 0x727faf}, -- bright blue: numbers/search
|
||||
{index = 13, rgb = 0x927b9e}, -- bright magenta: constants
|
||||
{index = 14, rgb = 0x009999}, -- bright cyan: cyan accents
|
||||
{index = 15, rgb = 0xc4c0c1} -- white: emphasized text
|
||||
}
|
||||
|
||||
-- Keep the current palette's deliberately muted colors from drifting to a
|
||||
-- similarly close hue (comments becoming green, for example). The nearest
|
||||
-- anchor remains a useful fallback when the RGB palette grows.
|
||||
local color_overrides = {
|
||||
["#004ead"] = 12,
|
||||
["#009999"] = 14,
|
||||
["#0a0a0f"] = 0,
|
||||
["#111118"] = 0,
|
||||
["#1d1b1c"] = 8,
|
||||
["#1e3a1e"] = 2,
|
||||
["#20202c"] = 0,
|
||||
["#212130"] = 0,
|
||||
["#242433"] = 0,
|
||||
["#282839"] = 8,
|
||||
["#2e2e1e"] = 3,
|
||||
["#2e2e42"] = 8,
|
||||
["#344074"] = 4,
|
||||
["#364936"] = 2,
|
||||
["#3a1e1e"] = 1,
|
||||
["#3f3f5a"] = 8,
|
||||
["#434360"] = 8,
|
||||
["#445397"] = 4,
|
||||
["#474344"] = 8,
|
||||
["#4d4d6f"] = 8,
|
||||
["#506d50"] = 2,
|
||||
["#5c5758"] = 8,
|
||||
["#4a2020"] = 1,
|
||||
["#4d3d22"] = 3,
|
||||
["#5f595a"] = 8,
|
||||
["#727faf"] = 12,
|
||||
["#6a906a"] = 10,
|
||||
["#766f71"] = 8,
|
||||
["#952d2d"] = 1,
|
||||
["#958e8f"] = 7,
|
||||
["#927b9e"] = 13,
|
||||
["#9a8065"] = 11,
|
||||
["#9c9697"] = 7,
|
||||
["#a19b9c"] = 7,
|
||||
["#ababab"] = 7,
|
||||
["#b0abac"] = 7,
|
||||
["#b5a15a"] = 11,
|
||||
["#b47a41"] = 11,
|
||||
["#bab5b6"] = 15,
|
||||
["#bfbbbc"] = 15,
|
||||
["#c18a53"] = 11,
|
||||
["#c4c0c1"] = 15,
|
||||
["#cc9e71"] = 11,
|
||||
["#c96b68"] = 9,
|
||||
["#ffffff"] = 15
|
||||
}
|
||||
|
||||
local group_overrides = {
|
||||
CocMenuSel = {ctermfg = 0, ctermbg = 7},
|
||||
ColorColumn = {ctermbg = 8},
|
||||
CursorColumn = {ctermfg = 7, ctermbg = 8},
|
||||
CursorLine = {ctermbg = 8},
|
||||
DiffAdd = {ctermfg = 15, ctermbg = 2},
|
||||
DiffChange = {ctermfg = 15, ctermbg = 3},
|
||||
DiffDelete = {ctermfg = 15, ctermbg = 1},
|
||||
DiffText = {ctermfg = 0, ctermbg = 3},
|
||||
Error = {ctermfg = 15, ctermbg = 1},
|
||||
Folded = {ctermfg = 7, ctermbg = 8},
|
||||
PmenuSel = {ctermfg = 0, ctermbg = 7},
|
||||
QuickFixLine = {ctermfg = 0, ctermbg = 7},
|
||||
StatusLine = {ctermfg = 0, ctermbg = 7},
|
||||
StatusLineNC = {ctermfg = 7, ctermbg = 8},
|
||||
TabLine = {ctermfg = 7, ctermbg = 8},
|
||||
TabLineSel = {ctermfg = 0, ctermbg = 7},
|
||||
Visual = {ctermfg = 0, ctermbg = 7}
|
||||
}
|
||||
|
||||
local function channels(rgb)
|
||||
return math.floor(rgb / 0x10000) % 0x100,
|
||||
math.floor(rgb / 0x100) % 0x100,
|
||||
rgb % 0x100
|
||||
end
|
||||
|
||||
local function nearest_ansi(color)
|
||||
local rgb
|
||||
if type(color) == "number" then
|
||||
rgb = color
|
||||
local override = color_overrides[string.format("#%06x", rgb)]
|
||||
if override then
|
||||
return override
|
||||
end
|
||||
elseif type(color) ~= "string" then
|
||||
return nil
|
||||
else
|
||||
local hex = color:match("^#(%x%x%x%x%x%x)$")
|
||||
if not hex then
|
||||
return nil
|
||||
end
|
||||
local override = color_overrides["#" .. hex:lower()]
|
||||
if override then
|
||||
return override
|
||||
end
|
||||
rgb = tonumber(hex, 16)
|
||||
end
|
||||
|
||||
local red, green, blue = channels(rgb)
|
||||
local nearest
|
||||
local nearest_distance
|
||||
|
||||
for _, anchor in ipairs(ansi_anchors) do
|
||||
local anchor_red, anchor_green, anchor_blue = channels(anchor.rgb)
|
||||
local distance = (red - anchor_red) ^ 2
|
||||
+ (green - anchor_green) ^ 2
|
||||
+ (blue - anchor_blue) ^ 2
|
||||
|
||||
if not nearest_distance or distance < nearest_distance then
|
||||
nearest = anchor.index
|
||||
nearest_distance = distance
|
||||
end
|
||||
end
|
||||
|
||||
return nearest
|
||||
end
|
||||
|
||||
function M.apply(theme)
|
||||
local compiled = require("lush").compile(theme)
|
||||
|
||||
for group, attrs in pairs(compiled) do
|
||||
if not attrs.link then
|
||||
attrs.ctermfg = nearest_ansi(attrs.fg)
|
||||
attrs.ctermbg = nearest_ansi(attrs.bg)
|
||||
|
||||
for key, value in pairs(group_overrides[group] or {}) do
|
||||
attrs[key] = value
|
||||
end
|
||||
|
||||
vim.api.nvim_set_hl(0, group, attrs)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.apply_matching(pattern)
|
||||
for group, attrs in pairs(vim.api.nvim_get_hl(0, {})) do
|
||||
if group:match(pattern) and not attrs.link then
|
||||
attrs.ctermfg = nearest_ansi(attrs.fg)
|
||||
attrs.ctermbg = nearest_ansi(attrs.bg)
|
||||
vim.api.nvim_set_hl(0, group, attrs)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in new issue
Block a user