Skip to content

Commit 0fcbe14

Browse files
committed
Check that colorscheme has true color support
Unfortunately neovim has no support for hlget() yet [0], so this got a little bit more complicated there. Also what the hell is wrong with Lua to overcomplicate basic things such as getting the name of the colorscheme. Apparently we have to use the generic vimscript command interface [1] just for this. It's kind of funny how the Lua API now has `api.nvim_cmd()`, `api.nvim_exec()` and `api.nvim_exec2()` similar to how libc has evolved to have 1000 alternatives to strcpy() and every year they release a new version that is apparently safer. So when will we get `api.nvim_exec3()`? ;) [0] neovim/neovim#16270 [1] neovim/neovim#18201
1 parent 457c0d5 commit 0fcbe14

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

autoload/tpipeline/debug.vim

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ func tpipeline#debug#info()
2121
let tmux = systemlist("tmux -V")[-1]
2222
let jobstate = tpipeline#job_state()
2323
let os = tpipeline#debug#os()
24-
let result = #{left: left, right: right, tmux: tmux, plugin_version: tpipeline#version#string(), job_state: jobstate, job_errors: s:stderr, os: os}
24+
let bad_colors = len(tpipeline#debug#get_bad_hl_groups())
25+
let result = #{left: left, right: right, tmux: tmux, plugin_version: tpipeline#version#string(), job_state: jobstate, job_errors: s:stderr, os: os, bad_colors: bad_colors}
2526

2627
if has('nvim')
2728
let stl = g:tpipeline_statusline
@@ -50,4 +51,24 @@ func tpipeline#debug#log_err(line)
5051
call add(s:stderr, a:line)
5152
endfunc
5253

54+
func tpipeline#debug#is_truecolor(s)
55+
return empty(a:s) || a:s == 'fg' || a:s== 'bg' || a:s == '#NONE' || a:s =~ '#\x\{6}'
56+
endfunc
57+
58+
func tpipeline#debug#is_truecolor_group(id)
59+
let syn = synIDtrans(a:id)
60+
let fg = tolower(synIDattr(syn, 'fg'))
61+
let bg = tolower(synIDattr(syn, 'bg'))
62+
return tpipeline#debug#is_truecolor(fg) && tpipeline#debug#is_truecolor(bg)
63+
endfunc
64+
65+
func tpipeline#debug#get_bad_hl_groups()
66+
if has('nvim')
67+
let hls = luaeval('vim.tbl_keys(vim.api.nvim_get_hl(0, {}))')->map({_, v -> #{id: hlID(v), name: v}})
68+
else
69+
let hls = hlget()
70+
endif
71+
return hls->filter({_, v -> !tpipeline#debug#is_truecolor_group(v.id)})->map({_, v -> v.name})
72+
endfunc
73+
5374
call tpipeline#debug#init()

lua/tpipeline/health.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ M.check = function()
44
vim.health.report_start("tpipeline report")
55
local info = vim.fn['tpipeline#debug#info']()
66

7-
ver = vim.version()
7+
local ver = vim.version()
88
if vim.version.lt(ver, {0, 6, 0}) then
99
vim.health.report_error(string.format("Neovim version %d.%d is not supported, use 0.6 or higher", ver.major, ver.minor))
1010
else
@@ -22,6 +22,14 @@ M.check = function()
2222
else
2323
vim.health.report_warn("Job reported errors", info.job_errors)
2424
end
25+
26+
if info.bad_colors > 0 then
27+
local groups = vim.fn['tpipeline#debug#get_bad_hl_groups']()
28+
local colorscheme = vim.api.nvim_exec2("colorscheme", {output = true}).output
29+
vim.health.report_warn(string.format("The colorscheme %s contains %d highlight groups that don't properly support truecolor. These colors might not render correctly in tmux.\nBad highlight groups are: %s", colorscheme, info.bad_colors, vim.inspect(groups)))
30+
else
31+
vim.health.report_ok("Colorscheme has true color support")
32+
end
2533
end
2634

2735
return M

0 commit comments

Comments
 (0)