patch 9.1.1060: Vim always enables 'termguicolors' in a terminal
Commit:
https://github.com/vim/vim/commit/d7f5854fccb70ebaf327b6f9bfcf7871506d598b
Author: Christian Brabandt <[email protected]>
Date: Fri Jan 31 16:13:14 2025 +0100
patch 9.1.1060: Vim always enables 'termguicolors' in a terminal
Problem: Vim always enables 'termguicolors' in a terminal, even
when not wanted (after v9.1.1054)
Solution: Respect `:set notermguicolors` in vimrc file
fixes: #16538
fixes: #16539
closes: #16540
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 648b18cbe..e6decee5e 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -1,4 +1,4 @@
-*options.txt* For Vim version 9.1. Last change: 2025 Jan 29
+*options.txt* For Vim version 9.1. Last change: 2025 Jan 31
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -8500,7 +8500,8 @@ A jump table for the options with a short description can
be found at |Q_op|.
< You need to do this when your system has no locale support for UTF-8.
*'termguicolors'* *'tgc'* *'notermguicolors'* *'notgc'* *E954*
-'termguicolors' 'tgc' boolean (default off)
+'termguicolors' 'tgc' boolean (default off unless Vim detects that it runs
+ in a capable terminal)
global
{not available when compiled without the
|+termguicolors| feature}
@@ -8510,7 +8511,11 @@ A jump table for the options with a short description
can be found at |Q_op|.
Will automatically be enabled, if Vim detects that it runs in a
capable terminal (when the terminal supports the RGB terminfo
capability or when the number of colors |t_Co| supported by the
- terminal is 0x1000000, e.g. with $TERM=xterm-direct).
+ terminal is 0x1000000, e.g. with $TERM=xterm-direct). Due to the async
+ nature of querying the terminal, enabling this automatically is
+ noticable. Use >
+ set notermguicolors
+< to explicitly disable.
Requires a ISO-8613-3 compatible terminal. If setting this option
does not work (produces a colorless UI) reading |xterm-true-color|
diff --git a/src/globals.h b/src/globals.h
index e3b1e27f4..3827c1a2e 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -2043,3 +2043,7 @@ EXTERN int skip_update_topline INIT(= FALSE);
// 'showcmd' buffer shared between normal.c and statusline code
#define SHOWCMD_BUFLEN (SHOWCMD_COLS + 1 + 30)
EXTERN char_u showcmd_buf[SHOWCMD_BUFLEN];
+
+#ifdef FEAT_TERMGUICOLORS
+EXTERN int p_tgc_set INIT(= FALSE);
+#endif
diff --git a/src/option.c b/src/option.c
index 653b87cae..3753c4ab1 100644
--- a/src/option.c
+++ b/src/option.c
@@ -4296,6 +4296,7 @@ did_set_termguicolors(optset_T *args UNUSED)
# endif
!has_vtp_working())
{
+ p_tgc_set = TRUE;
p_tgc = 0;
return e_24_bit_colors_are_not_supported_on_this_environment;
}
@@ -4320,6 +4321,7 @@ did_set_termguicolors(optset_T *args UNUSED)
term_update_palette_all();
term_update_wincolor_all();
# endif
+ p_tgc_set = TRUE;
return NULL;
}
diff --git a/src/term.c b/src/term.c
index 103ec965a..19913428c 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1662,8 +1662,8 @@ set_color_count(int nr)
else
*nr_colors = NUL;
#ifdef FEAT_TERMGUICOLORS
- // xterm-direct, enable termguicolors
- if (t_colors == 0x1000000 && !p_tgc)
+ // xterm-direct, enable termguicolors, when it wasn't set yet
+ if (t_colors == 0x1000000 && !p_tgc_set)
set_option_value((char_u *)"termguicolors", 1L, NULL, 0);
#endif
set_string_option_direct((char_u *)"t_Co", -1, nr_colors, OPT_FREE, 0);
@@ -7199,8 +7199,9 @@ got_code_from_term(char_u *code, int len)
else if (name[0] == 'R' && name[1] == 'G' && name[2] == 'B' &&
code[9] == '=')
{
int val = atoi((char *)str);
- // 8 bits per color channel
- if (val == 8)
+ // only enable it, if termguicolors hasn't been set yet and
+ // there are 8 bits per color channel
+ if (val == 8 && !p_tgc_set)
{
#ifdef FEAT_EVAL
ch_log(NULL, "got_code_from_term(RGB): xterm-direct colors
detected");
diff --git a/src/testdir/test_termcodes.vim b/src/testdir/test_termcodes.vim
index 098fdb3fd..db98a70b4 100644
--- a/src/testdir/test_termcodes.vim
+++ b/src/testdir/test_termcodes.vim
@@ -10,6 +10,24 @@ source mouse.vim
source view_util.vim
source term_util.vim
+func s:TermGuiColorsTest()
+ 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
+endfunc
+
+
func Test_term_mouse_left_click()
new
let save_mouse = &mouse
@@ -2740,21 +2758,8 @@ func Test_terminal_builtin_without_gui()
endfunc
func Test_xterm_direct_enables_termguicolors()
+ call s:TermGuiColorsTest()
" 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')
@@ -2773,6 +2778,33 @@ func Test_xterm_direct_enables_termguicolors()
call assert_equal(['', 'TERM: xterm-direct', 'Termguicolors: 1'], result)
" cleanup
bw!
+ close
+endfunc
+
+func Test_xterm_direct_no_termguicolors()
+ " unfortunately doesn't work with libvterm
+ call s:TermGuiColorsTest()
+
+ let lines =<< trim END
+ set notermguicolors noswapfile
+ set t_Co=16777216
+ END
+ call writefile(lines, 'XtermDirect', 'D')
+ defer delete('XTerm-direct2.txt')
+
+ let buf = RunVimInTerminal('-S XtermDirect --clean XTerm-direct2.txt',
+ \ {'rows': 10, 'env': {'TERM': 'xterm-direct'}})
+ call TermWait(buf)
+ call term_sendkeys(buf, ":$put ='TERM: ' .. &term\<cr>")
+ call term_sendkeys(buf, ":$put ='Termguicolors: ' .. &tgc\<cr>")
+ call term_sendkeys(buf, ":wq\<cr>")
+ call TermWait(buf)
+
+ let result=readfile('XTerm-direct2.txt')
+ call assert_equal(['', 'TERM: xterm-direct', 'Termguicolors: 0'], result)
+ " cleanup
+ bw!
+ close
endfunc
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 209baf1d8..1e0d3cda8 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1060,
/**/
1059,
/**/
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1tdsy3-00EGRO-Rb%40256bit.org.