patch 9.1.1054: Vim doesn't work well with TERM=xterm-direct
Problem: Vim doesn't work well with TERM=xterm-direct
(Andrea Pappacoda)
Solution: detect if a terminal supports true-colors and
enable termguicolors
The terminfo database for xterm-direct contains both the (non-standard)
termcap RGB capability and a number of colors == 0x1000000 so it seems
either of those two options can be used to detect a terminal capable of
displaying true colors.
So set the termguicolor option automatically, when either of the two
options is detected. (for some reasons, my debian xterm (v393) does not
respond to XTGETTCAP query attempts, so falling back to the number of
colors seems like a good compromize)
fixes: #16327
closes: #16490
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/testdir/test_termcodes.vim b/src/testdir/test_termcodes.vim
index 25034ed..098fdb3 100644
--- a/src/testdir/test_termcodes.vim
+++ b/src/testdir/test_termcodes.vim
@@ -2739,4 +2739,40 @@
call assert_notequal(-1, index(output, 'builtin_dumb'))
endfunc
+func Test_xterm_direct_enables_termguicolors()
+ " TERM=xterm-direct enables termguicolors
+ CheckNotMSWindows
+ if !CanRunVimInTerminal()
+ throw 'Skipped: cannot make screendumps'
+ endif
+ if !executable('tput')
+ throw "Skipped: tput not executable!"
+ endif
+ if has("gui_running")
+ throw "Skipped: does not work in GUI mode"
+ endif
+ call system('tput -Txterm-direct RGB 2>/dev/null')
+ if v:shell_error
+ throw "Skipped: xterm-direct $TERM has no RGB capability"
+ endif
+ let colors = systemlist('tput -Txterm-direct colors')[0]
+ defer delete('XTerm-direct.txt')
+
+ let buf = RunVimInTerminal('--cmd ":set noswapfile" --clean XTerm-direct.txt',
+ \ {'rows': 10, 'env': {'TERM': 'xterm-direct'}})
+ call TermWait(buf)
+ call term_sendkeys(buf, ":$put ='TERM: ' .. &term\<cr>")
+ " doesn't work. Vim cannot query xterm colors in the embedded terminal?
+ "call term_sendkeys(buf, ":$put ='Colors: ' .. &t_Co\<cr>")
+ call term_sendkeys(buf, ":$put ='Termguicolors: ' .. &tgc\<cr>")
+ call term_sendkeys(buf, ":wq\<cr>")
+ call TermWait(buf)
+
+ let result=readfile('XTerm-direct.txt')
+ " call assert_equal(['', 'TERM: xterm-direct', 'Colors: ' .. colors, 'Termguicolors: 1'], result)
+ call assert_equal(['', 'TERM: xterm-direct', 'Termguicolors: 1'], result)
+ " cleanup
+ bw!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab