patch 9.2.0160: terminal DEC mode handling is overly complex

Commit: 
https://github.com/vim/vim/commit/13b25e2f34dfa32d44c6fa330f39bbe1c2deb273
Author: Foxe Chen <[email protected]>
Date:   Fri Mar 13 21:55:16 2026 +0000

    patch 9.2.0160: terminal DEC mode handling is overly complex
    
    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 <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 3542eb345..245089a3b 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -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 "")
diff --git a/src/main.c b/src/main.c
index 4579690e1..9f9fd1205 100644
--- a/src/main.c
+++ b/src/main.c
@@ -892,8 +892,6 @@ vim_main2(void)
     may_req_termresponse();
 
     may_req_bg_color();
-
-    may_req_dec_setting();
 # endif
 
     // start in insert mode
diff --git a/src/proto/term.pro b/src/proto/term.pro
index 80f9b00e9..9653a35af 100644
--- a/src/proto/term.pro
+++ b/src/proto/term.pro
@@ -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);
diff --git a/src/term.c b/src/term.c
index 8b557ae99..a1bb6c1b9 100644
--- a/src/term.c
+++ b/src/term.c
@@ -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,      " [?2026h"},
+    {(int)KS_ESU,      " [?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 *)" [>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 *)" [?2026h";
-    if (T_ESU == NULL || T_ESU == empty_option)
-       T_ESU = (char_u *)" [?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, " [?%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 *)" [?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 *)" [?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.
  */
diff --git a/src/version.c b/src/version.c
index a55c7a1ab..c0f5c7488 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    160,
 /**/
     159,
 /**/

-- 
-- 
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/E1w1Amd-0040yZ-CM%40256bit.org.

Raspunde prin e-mail lui