|
|
|
@ -277,6 +277,8 @@ M.ansi_colors = {
|
|
|
|
|
-- clear = "\x1b[0m",
|
|
|
|
|
clear = "[0m",
|
|
|
|
|
bold = "[1m",
|
|
|
|
|
italic = "[3m",
|
|
|
|
|
underline = "[4m",
|
|
|
|
|
black = "[0;30m",
|
|
|
|
|
red = "[0;31m",
|
|
|
|
|
green = "[0;32m",
|
|
|
|
@ -284,9 +286,9 @@ M.ansi_colors = {
|
|
|
|
|
blue = "[0;34m",
|
|
|
|
|
magenta = "[0;35m",
|
|
|
|
|
cyan = "[0;36m",
|
|
|
|
|
white = "[0;37m",
|
|
|
|
|
grey = "[0;90m",
|
|
|
|
|
dark_grey = "[0;97m",
|
|
|
|
|
white = "[0;98m",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
M.add_ansi_code = function(name, escseq)
|
|
|
|
@ -311,7 +313,7 @@ local function synIDattr(hl, w)
|
|
|
|
|
return vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID(hl)), w)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M.ansi_from_hl(hl, s)
|
|
|
|
|
function M.ansi_from_hl(hl, s, colormap)
|
|
|
|
|
if vim.fn.hlexists(hl) == 1 then
|
|
|
|
|
-- https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797#rgb-colors
|
|
|
|
|
-- Set foreground color as RGB: 'ESC[38;2;{r};{g};{b}m'
|
|
|
|
@ -327,20 +329,33 @@ function M.ansi_from_hl(hl, s)
|
|
|
|
|
['strikethrough'] = { code = 9 },
|
|
|
|
|
}
|
|
|
|
|
for w, p in pairs(what) do
|
|
|
|
|
local escseq = nil
|
|
|
|
|
if p.rgb then
|
|
|
|
|
local hexcol = synIDattr(hl, w)
|
|
|
|
|
if hexcol and not hexcol:match("^#") and colormap then
|
|
|
|
|
-- try to acquire the color from the map
|
|
|
|
|
-- some schemes don't capitalize first letter?
|
|
|
|
|
local col = colormap[hexcol:sub(1,1):upper()..hexcol:sub(2)]
|
|
|
|
|
if col then
|
|
|
|
|
-- format as 6 digit hex for hex2rgb()
|
|
|
|
|
hexcol = ("#%06x"):format(col)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
local r, g, b = hex2rgb(hexcol)
|
|
|
|
|
if r and g and b then
|
|
|
|
|
local escseq = ('[%d;2;%d;%d;%dm'):format(p.code, r, g, b)
|
|
|
|
|
s = ("%s%s%s"):format(escseq, s, M.ansi_colors.clear)
|
|
|
|
|
escseq = ('[%d;2;%d;%d;%dm'):format(p.code, r, g, b)
|
|
|
|
|
-- elseif #hexcol>0 then
|
|
|
|
|
-- print("unresolved", hl, w, hexcol, colormap[synIDattr(hl, w)])
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
local value = synIDattr(hl, w)
|
|
|
|
|
if value and tonumber(value)==1 then
|
|
|
|
|
local escseq = ('[%dm'):format(p.code)
|
|
|
|
|
s = ("%s%s%s"):format(escseq, s, M.ansi_colors.clear)
|
|
|
|
|
escseq = ('[%dm'):format(p.code)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if escseq then
|
|
|
|
|
s = ("%s%s%s"):format(escseq, s, M.ansi_colors.clear)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return s
|
|
|
|
|