# HG changeset patch # User Bram Moolenaar # Date 1640078104 -3600 # Node ID a77b661439f9aa5269e4bee6dbeee28f8b921349 # Parent 7e4f211e0133eb354cbc63cfb6a8f959f73042e0 patch 8.2.3864: cannot disable requesting key codes from xterm Commit: https://github.com/vim/vim/commit/6f79e614b25caebd35cf0d82b6f3b7e0733849ec Author: Bram Moolenaar Date: Tue Dec 21 09:12:23 2021 +0000 patch 8.2.3864: cannot disable requesting key codes from xterm Problem: Cannot disable requesting key codes from xterm. Solution: Add the 'xtermcodes' option, default on. diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -9206,4 +9206,16 @@ A jump table for the options with a shor screen. When non-zero, characters are sent to the terminal one by one. For debugging purposes. + *'xtermcodes'* *'noxtermcodes'* +'xtermcodes' boolean (default on) + global + When detecting xterm patchlevel 141 or higher with the termresponse + mechanism and this option is set, Vim will request the actual termimal + key codes and number of colors from the terminal. This takes care of + various configuration options of the terminal that cannot be obtained + from the termlib/terminfo entry, see |xterm-codes|. + A side effect may be that t_Co changes and Vim will redraw the + display. + + vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/runtime/doc/term.txt b/runtime/doc/term.txt --- a/runtime/doc/term.txt +++ b/runtime/doc/term.txt @@ -556,8 +556,15 @@ request the key codes directly from the adjust the various t_ codes. This avoids the problem that the xterm can produce different codes, depending on the mode it is in (8-bit, VT102, VT220, etc.). The result is that codes like are no longer needed. -Note: This is only done on startup. If the xterm options are changed after -Vim has started, the escape sequences may not be recognized anymore. + +One of the codes that can change is 't_Co', the number of colors. This will +trigger a redraw. If this is a problem, reset the 'xtermcodes' option as +early as possible: > + set noxtermcodes + +Note: Requesting the key codes is only done on startup. If the xterm options +are changed after Vim has started, the escape sequences may not be recognized +anymore. *xterm-true-color* Vim supports using true colors in the terminal (taken from |highlight-guifg| diff --git a/runtime/optwin.vim b/runtime/optwin.vim --- a/runtime/optwin.vim +++ b/runtime/optwin.vim @@ -562,14 +562,22 @@ endif call Header(gettext("terminal")) call AddOption("term", gettext("name of the used terminal")) call OptionG("term", &term) + call AddOption("ttytype", gettext("alias for 'term'")) call OptionG("tty", &tty) + call AddOption("ttybuiltin", gettext("check built-in termcaps first")) call BinOptionG("tbi", &tbi) + call AddOption("ttyfast", gettext("terminal connection is fast")) call BinOptionG("tf", &tf) + +call AddOption("xtermcodes", gettext("request terminal key codes when an xterm is detected")) +call BinOptionG("xtermcodes", &xtermcodes) + call AddOption("weirdinvert", gettext("terminal that requires extra redrawing")) call BinOptionG("wiv", &wiv) + call AddOption("esckeys", gettext("recognize keys that start with in Insert mode")) call BinOptionG("ek", &ek) call AddOption("scrolljump", gettext("minimal number of lines to scroll at a time")) diff --git a/src/option.h b/src/option.h --- a/src/option.h +++ b/src/option.h @@ -485,6 +485,7 @@ EXTERN int p_deco; // 'delcombine' #ifdef FEAT_EVAL EXTERN char_u *p_ccv; // 'charconvert' #endif +EXTERN int p_cdh; // 'cdhome' EXTERN char_u *p_cino; // 'cinoptions' #ifdef FEAT_CMDWIN EXTERN char_u *p_cedit; // 'cedit' @@ -1094,7 +1095,7 @@ EXTERN int p_write; // 'write' EXTERN int p_wa; // 'writeany' EXTERN int p_wb; // 'writebackup' EXTERN long p_wd; // 'writedelay' -EXTERN int p_cdh; // 'cdhome' +EXTERN int p_xtermcodes; // 'xtermcodes' /* * "indir" values for buffer-local options. diff --git a/src/optiondefs.h b/src/optiondefs.h --- a/src/optiondefs.h +++ b/src/optiondefs.h @@ -2941,6 +2941,9 @@ static struct vimoption options[] = {"writedelay", "wd", P_NUM|P_VI_DEF, (char_u *)&p_wd, PV_NONE, {(char_u *)0L, (char_u *)0L} SCTX_INIT}, + {"xtermcodes", NULL, P_BOOL|P_VI_DEF, + (char_u *)&p_xtermcodes, PV_NONE, + {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, // terminal output codes #define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \ diff --git a/src/term.c b/src/term.c --- a/src/term.c +++ b/src/term.c @@ -4694,7 +4694,7 @@ handle_version_response(int first, int * // If xterm version >= 141 try to get termcap codes. For other // terminals the request should be ignored. - if (version >= 141) + if (version >= 141 && p_xtermcodes) { LOG_TR(("Enable checking for XT codes")); check_for_codes = TRUE; @@ -6446,8 +6446,7 @@ got_code_from_term(char_u *code, int len if (name[0] == 'C' && name[1] == 'o') { // Color count is not a key code. - i = atoi((char *)str); - may_adjust_color_count(i); + may_adjust_color_count(atoi((char *)str)); } else { diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -750,6 +750,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3864, +/**/ 3863, /**/ 3862,