]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0160: terminal DEC mode handling is overly complex v9.2.0160
authorFoxe Chen <chen.foxe@gmail.com>
Fri, 13 Mar 2026 21:55:16 +0000 (21:55 +0000)
committerChristian Brabandt <cb@256bit.org>
Fri, 13 Mar 2026 22:02:10 +0000 (22:02 +0000)
Problem:  terminal DEC mode handling is overly complex (after v9.2.0139)
Solution: Refactor DEC mode handling (Foxe Chen).

related: #19596
related: #19541
closes:  #19641

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/options.txt
src/main.c
src/proto/term.pro
src/term.c
src/version.c

index 3542eb345e2bf173a703f0f7f03eb5ddd57e59c8..245089a3b2aa1c99298641eae357138a18c8061f 100644 (file)
@@ -1,4 +1,4 @@
-*options.txt*  For Vim version 9.2.  Last change: 2026 Mar 12
+*options.txt*  For Vim version 9.2.  Last change: 2026 Mar 13
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -9144,10 +9144,7 @@ A jump table for the options with a short description can be found at |Q_op|.
        The specification can be found at:
        https://github.com/contour-terminal/vt-extensions/blob/master/synchronized-output.md
 
-       Vim may set this option automatically at startup time when Vim is
-       compiled with the |+termresponse| feature, by querying the terminal
-       for DEC mode 2026 support.  The terminal codes used are |t_BS| and
-       |t_ES|.
+       The terminal codes used are |t_BS| and |t_ES|.
 
                                                *'termwinkey'* *'twk'*
 'termwinkey' 'twk'     string  (default "")
index 4579690e121348ff380c6ad06e23305d9a3649dc..9f9fd1205e63bb7e86dc6809fa67f6d76e6b8646 100644 (file)
@@ -892,8 +892,6 @@ vim_main2(void)
     may_req_termresponse();
 
     may_req_bg_color();
-
-    may_req_dec_setting();
 # endif
 
     // start in insert mode
index 80f9b00e930732aa610af267e6e7e969746486a3..9653a35af3bce9fec1998e144614f303815e713a 100644 (file)
@@ -96,7 +96,6 @@ void swap_tcap(void);
 void ansi_color2rgb(int nr, char_u *r, char_u *g, char_u *b, char_u *ansi_idx);
 void cterm_color2rgb(int nr, char_u *r, char_u *g, char_u *b, char_u *ansi_idx);
 int term_replace_keycodes(char_u *ta_buf, int ta_len, int len_arg);
-void may_req_dec_setting(void);
 void term_disable_dec(void);
 void term_set_win_resize(bool state);
 void term_set_sync_output(int flags);
index 8b557ae9927cf8de98ef6681352119e4a4fd7e15..a1bb6c1b97d4948c6faa12599d8faeadd91f9b69 100644 (file)
@@ -130,14 +130,6 @@ static termrequest_T u7_status = TERMREQUEST_INIT;
 // Request xterm compatibility check:
 static termrequest_T xcc_status = TERMREQUEST_INIT;
 
-// Request synchronized output report
-static termrequest_T sync_output_status = TERMREQUEST_INIT;
-
-#ifdef UNIX
-// Request in-band window resize events report
-static termrequest_T win_resize_status = TERMREQUEST_INIT;
-#endif
-
 #ifdef FEAT_TERMRESPONSE
 # ifdef FEAT_TERMINAL
 // Request foreground color report:
@@ -173,10 +165,6 @@ static termrequest_T *all_termrequests[] = {
     &rbm_status,
     &rcs_status,
     &winpos_status,
-    &sync_output_status,
-# ifdef UNIX
-    &win_resize_status,
-# endif
     NULL
 };
 
@@ -687,6 +675,25 @@ static tcap_entry_T builtin_kitty[] = {
     {(int)KS_NAME,     NULL}  // end marker
 };
 
+/*
+ * Additions for enabling/disabling synchronized output mode for terminal.
+ */
+static tcap_entry_T builtin_sync_output[] = {
+    {(int)KS_BSU,      "\033[?2026h"},
+    {(int)KS_ESU,      "\033[?2026l"},
+    {(int)KS_NAME,     NULL}  // end marker
+};
+
+/*
+ * List of DECRQM modes that Vim supports
+ */
+static int dec_modes[] = {
+    2026,   // Synchronized output
+#ifdef UNIX
+    2048    // In-band terminal resize events
+#endif
+};
+
 #ifdef FEAT_TERMGUICOLORS
 /*
  * Additions for using the RGB colors and terminal font
@@ -2202,6 +2209,8 @@ set_termname(char_u *term)
 #ifdef HAVE_TGETENT
        if (term_strings_not_set(KS_CF))
            apply_builtin_tcap(term, special_term, TRUE);
+       if (term_strings_not_set(KS_BSU) && term_strings_not_set(KS_ESU))
+           apply_builtin_tcap(term, builtin_sync_output, TRUE);
 #endif
     }
 
@@ -2222,14 +2231,6 @@ set_termname(char_u *term)
                                           && (T_CRV == NULL || *T_CRV == NUL))
        T_CRV = (char_u *)"\033[>c";
 
-    // These are the DECSET/DECRESET codes for synchronized output. iTerm
-    // supports another way, but this is the de facto standard terminal codes
-    // that are used (from what I can tell - 64bitman).
-    if (T_BSU == NULL || T_BSU == empty_option)
-       T_BSU = (char_u *)"\033[?2026h";
-    if (T_ESU == NULL || T_ESU == empty_option)
-       T_ESU = (char_u *)"\033[?2026l";
-
 #ifdef UNIX
 /*
  * Any "stty" settings override the default for t_kb from the termcap.
@@ -4048,6 +4049,13 @@ starttermcap(void)
        out_str(T_FE);
 #endif
 
+    // Request setting of relevant DEC modes via DECRQM
+    for (int i = 0; i < (int)ARRAY_LENGTH(dec_modes); i++)
+    {
+       vim_snprintf((char *)IObuff, IOSIZE, "\033[?%d$p", dec_modes[i]);
+       out_str(IObuff);
+    }
+
     out_flush();
     termcap_active = TRUE;
     screen_start();                    // don't know where cursor is now
@@ -5757,13 +5765,11 @@ handle_csi(
            {
                case 2026:
                    sync_output_setting = setting;
-                   sync_output_status.tr_progress = STATUS_GOT;
                    set_option_value_give_err((char_u *)"termsync",
                            setting == 1 || setting == 2, NULL, 0);
                    break;
 #ifdef UNIX
                case 2048:
-                   win_resize_status.tr_progress = STATUS_GOT;
                    win_resize_setting = setting;
 
                    term_set_win_resize(true);
@@ -7896,52 +7902,6 @@ term_replace_keycodes(char_u *ta_buf, int ta_len, int len_arg)
     return len;
 }
 
-#ifdef FEAT_TERMRESPONSE
-/*
- * Query the setting for the following DEC modes from the terminal:
- * - DEC mode 2026 (synchronized output)
- * - DEC mode 2048 (window resize events)
- */
-    void
-may_req_dec_setting(void)
-{
-    if (can_get_termresponse() && starting == 0)
-    {
-       bool didit = false;
-
-       if (sync_output_status.tr_progress == STATUS_GET)
-       {
-           MAY_WANT_TO_LOG_THIS;
-           LOG_TR1("Sending synchronized output request");
-
-           out_str((char_u *)"\033[?2026$p");
-           termrequest_sent(&sync_output_status);
-           didit = true;
-       }
-
-# ifdef UNIX
-       if (win_resize_status.tr_progress == STATUS_GET)
-       {
-           MAY_WANT_TO_LOG_THIS;
-           LOG_TR1("Sending in-band window resize events request");
-
-           out_str((char_u *)"\033[?2048$p");
-           termrequest_sent(&win_resize_status);
-           didit = true;
-       }
-# endif
-
-       if (didit)
-       {
-           // check for the characters now, otherwise they might be eaten by
-           // get_keystroke()
-           out_flush();
-           (void)vpeekc_nomap();
-       }
-    }
-}
-#endif
-
 /*
  * Should be called when cleaning up terminal state.
  */
index a55c7a1ab69271d2d90b6868590d79acffd9aa38..c0f5c7488a6d43021a6bde3f80e742177e5d960b 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    160,
 /**/
     159,
 /**/