diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2023-01-16 13:25:11 +0000 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2023-01-16 15:30:57 +0000 |
commit | 7e24c45221b330ccf8ed3808570dab38d212ba2e (patch) | |
tree | 2a6bc1031ea28b59ad84355d3654f6b80884f3fb | |
parent | 60df0c06510cc65d68a2693722577d437264f67d (diff) | |
download | rneovim-7e24c45221b330ccf8ed3808570dab38d212ba2e.tar.gz rneovim-7e24c45221b330ccf8ed3808570dab38d212ba2e.tar.bz2 rneovim-7e24c45221b330ccf8ed3808570dab38d212ba2e.zip |
feat(health): detect tmux RGB support via `client_termfeatures`
Problem: On tmux v3.2+, the `terminal-features` option may be used to enable RGB
capabilities over `terminal-overrides`. However, `show-messages` cannot be used
to detect if RGB capabilities are enabled using `terminal-features`.
Solution: Try to use `display-message -p #{client_termfeatures}` instead.
The returned features include "RGB" if either "RGB" is set in
`terminal-features`, or if "Tc" or "RGB" is set in `terminal-overrides` (as
before).
Nothing is returned by tmux versions older than v3.2, so fallback to checking
`show-messages` in that case.
Also, un-Vimscriptify the previous logic a bit, and change the error message to
point to using the `terminal-features` option instead for newer tmux versions.
-rw-r--r-- | runtime/lua/nvim/health.lua | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/runtime/lua/nvim/health.lua b/runtime/lua/nvim/health.lua index 02e08bd381..b76106f241 100644 --- a/runtime/lua/nvim/health.lua +++ b/runtime/lua/nvim/health.lua @@ -326,17 +326,24 @@ local function check_tmux() end -- check for RGB capabilities - local info = vim.fn.system({ 'tmux', 'show-messages', '-JT' }) - local has_tc = vim.fn.stridx(info, ' Tc: (flag) true') ~= -1 - local has_rgb = vim.fn.stridx(info, ' RGB: (flag) true') ~= -1 - if not has_tc and not has_rgb then - health.report_warn( - "Neither Tc nor RGB capability set. True colors are disabled. |'termguicolors'| won't work properly.", - { - "Put this in your ~/.tmux.conf and replace XXX by your $TERM outside of tmux:\nset-option -sa terminal-overrides ',XXX:RGB'", - "For older tmux versions use this instead:\nset-option -ga terminal-overrides ',XXX:Tc'", - } - ) + local info = vim.fn.system({ 'tmux', 'display-message', '-p', '#{client_termfeatures}' }) + info = vim.split(vim.trim(info), ',', { trimempty = true }) + if not vim.tbl_contains(info, 'RGB') then + local has_rgb = false + if #info == 0 then + -- client_termfeatures may not be supported; fallback to checking show-messages + info = vim.fn.system({ 'tmux', 'show-messages', '-JT' }) + has_rgb = info:find(' Tc: (flag) true', 1, true) or info:find(' RGB: (flag) true', 1, true) + end + if not has_rgb then + health.report_warn( + "Neither Tc nor RGB capability set. True colors are disabled. |'termguicolors'| won't work properly.", + { + "Put this in your ~/.tmux.conf and replace XXX by your $TERM outside of tmux:\nset-option -sa terminal-features ',XXX:RGB'", + "For older tmux versions use this instead:\nset-option -ga terminal-overrides ',XXX:Tc'", + } + ) + end end end |