]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1666: no support for terminal primary device attributes v9.1.1666
authorFoxe Chen <chen.foxe@gmail.com>
Sat, 23 Aug 2025 09:56:40 +0000 (05:56 -0400)
committerChristian Brabandt <cb@256bit.org>
Sat, 23 Aug 2025 10:00:23 +0000 (06:00 -0400)
Problem:  no support for terminal primary device attributes
Solution: Add support for detecting the DA1 response from the terminal,
          add the v:termda1 variable and the 't_Ms' option for the
          OSC 52 command format (Foxe Chen)

closes: #18033

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/eval.txt
runtime/doc/tags
runtime/doc/term.txt
runtime/doc/version9.txt
runtime/syntax/vim.vim
src/evalvars.c
src/term.c
src/testdir/test_termcodes.vim
src/version.c
src/vim.h

index 254372db66bba0cf45613cd27f8cfbccddd72ac1..01ab14203e7883ac34a8ab8dbc373dbaaa785171 100644 (file)
@@ -1,4 +1,4 @@
-*eval.txt*     For Vim version 9.1.  Last change: 2025 Aug 20
+*eval.txt*     For Vim version 9.1.  Last change: 2025 Aug 23
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -2911,6 +2911,12 @@ v:termu7resp     The escape sequence returned by the terminal for the |t_u7|
                this option is set, the TermResponseAll autocommand event is
                fired, with <amatch> set to "ambiguouswidth".
 
+                                               *v:termda1*
+v:termda1      The escape sequence returned by a primary device attributes
+               (DA1) query from the terminal.  When this option is set, the
+               TermResponseAll autocommand event is fired, with <amatch> set
+               to "da1".  Can be used to detect OSC 52 support in a terminal.
+
                                        *v:testing* *testing-variable*
 v:testing      Must be set before using `test_garbagecollect_now()`.
                Also, when set certain error messages won't be shown for 2
index fa3382f288beb768a1631f4a8990c55b2405cf68..d42cac486adaeb0ba6651ae0e027337ecb35fc85 100644 (file)
@@ -1102,6 +1102,7 @@ $quote    eval.txt        /*$quote*
 't_KJ' term.txt        /*'t_KJ'*
 't_KK' term.txt        /*'t_KK'*
 't_KL' term.txt        /*'t_KL'*
+'t_Ms' term.txt        /*'t_Ms'*
 't_PE' term.txt        /*'t_PE'*
 't_PS' term.txt        /*'t_PS'*
 't_RB' term.txt        /*'t_RB'*
@@ -10587,6 +10588,7 @@ t_KI    term.txt        /*t_KI*
 t_KJ   term.txt        /*t_KJ*
 t_KK   term.txt        /*t_KK*
 t_KL   term.txt        /*t_KL*
+t_Ms   term.txt        /*t_Ms*
 t_PE   term.txt        /*t_PE*
 t_PS   term.txt        /*t_PS*
 t_RB   term.txt        /*t_RB*
@@ -11257,6 +11259,7 @@ v:t_string      eval.txt        /*v:t_string*
 v:t_tuple      eval.txt        /*v:t_tuple*
 v:t_typealias  eval.txt        /*v:t_typealias*
 v:termblinkresp        eval.txt        /*v:termblinkresp*
+v:termda1      eval.txt        /*v:termda1*
 v:termrbgresp  eval.txt        /*v:termrbgresp*
 v:termresponse eval.txt        /*v:termresponse*
 v:termrfgresp  eval.txt        /*v:termrfgresp*
index 6cf37aef99db0b7a8c2add375fa51a6b6da26fa9..176d9195844b34e2c9dc5871b49d172810447085 100644 (file)
@@ -1,4 +1,4 @@
-*term.txt*      For Vim version 9.1.  Last change: 2025 Aug 06
+*term.txt*      For Vim version 9.1.  Last change: 2025 Aug 23
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -644,6 +644,9 @@ Note: Use the <> form if possible
                <FocusGained>   Vim window got focus (internal only)
                <FocusLost>     Vim window lost focus (internal only)
 
+       t_Ms                    OSC 52 command format (empty    *t_Ms* *'t_Ms'*
+                               if terminal doesn't support it)
+
 Note about t_so and t_mr: When the termcap entry "so" is not present the
 entry for "mr" is used.  And vice versa.  The same is done for "se" and "me".
 If your terminal supports both inversion and standout mode, you can see two
index 30501b59796172f90f37771bc1503489c3920d9b..745cf7242db7615d0711b7af2d37d0e450238a47 100644 (file)
@@ -1,4 +1,4 @@
-*version9.txt*  For Vim version 9.1.  Last change: 2025 Aug 22
+*version9.txt*  For Vim version 9.1.  Last change: 2025 Aug 23
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -41851,12 +41851,17 @@ Options: ~
 'tabpanelopt'          Optional settings for the |tabpanel|
 't_xo'                 Terminal uses XON/XOFF handshaking (e.g. vt420)
 't_CF'                 Support for alternate font highlighting terminal code
+'t_Ms'                 OSC 52 command format
 'winfixbuf'            Keep buffer focused in a window
 'wlseat'               Specify Wayland seat to use for the |wayland| feature
 'wlsteal'              Steal focus to access the |wayland| clipboard
 'wltimeout'            Specify the connection timeout for the |wayland|
                        compositor
 
+Vim Variables: ~
+|v:termda1|            The escape sequence returned for the primary device
+                       attribute query (DA1).
+
 Vim Arguments: ~
 |-Y|                   Do not connect to the |wayland| compositor.
 |--clientserver|       Specify backend for clientserver functionality.
index eab86d27e6bc0fd5b9b73a05856cea4698880667..dd9f78b838100adeb2963d9765ebf5f80fdef4fd 100644 (file)
@@ -2,7 +2,7 @@
 " Language:       Vim script
 " Maintainer:     Hirohito Higashi <h.east.727 ATMARK gmail.com>
 "         Doug Kearns <dougkearns@gmail.com>
-" Last Change:    2025 Aug 18
+" Last Change:    2025 Aug 23
 " Former Maintainer: Charles E. Campbell
 
 " DO NOT CHANGE DIRECTLY.
@@ -165,7 +165,7 @@ syn keyword vimFuncName contained win_getid win_gettype win_gotoid win_id2tabwin
 " Predefined variable names {{{2
 " GEN_SYN_VIM: vimVarName, START_STR='syn keyword vimVimVarName contained', END_STR=''
 syn keyword vimVimVarName contained count count1 prevcount errmsg warningmsg statusmsg shell_error this_session version lnum termresponse fname lang lc_time ctype charconvert_from charconvert_to fname_in fname_out fname_new fname_diff cmdarg foldstart foldend folddashes foldlevel progname servername dying exception throwpoint register cmdbang insertmode val key profiling fcs_reason fcs_choice beval_bufnr beval_winnr beval_winid beval_lnum beval_col beval_text scrollstart swapname swapchoice swapcommand char mouse_win mouse_winid mouse_lnum mouse_col operator searchforward hlsearch oldfiles windowid progpath completed_item option_new option_old option_oldlocal option_oldglobal option_command option_type errors false true none null numbermax numbermin numbersize
-syn keyword vimVimVarName contained vim_did_enter testing t_number t_string t_func t_list t_dict t_float t_bool t_none t_job t_channel t_blob t_class t_object termrfgresp termrbgresp termu7resp termstyleresp termblinkresp event versionlong echospace argv collate exiting colornames sizeofint sizeoflong sizeofpointer maxcol python3_version t_typealias t_enum t_enumvalue stacktrace t_tuple wayland_display clipmethod
+syn keyword vimVimVarName contained vim_did_enter testing t_number t_string t_func t_list t_dict t_float t_bool t_none t_job t_channel t_blob t_class t_object termrfgresp termrbgresp termu7resp termstyleresp termblinkresp event versionlong echospace argv collate exiting colornames sizeofint sizeoflong sizeofpointer maxcol python3_version t_typealias t_enum t_enumvalue stacktrace t_tuple wayland_display clipmethod termda1
 
 "--- syntax here and above generated by runtime/syntax/generator/gen_syntax_vim.vim ---
 
index 37e2f373aa6799b56f8d7954b833c742343a6af4..78d8a1755f68e3e7c665f64510b0ddd825c605fd 100644 (file)
@@ -164,7 +164,8 @@ static struct vimvar
     {VV_NAME("stacktrace",      VAR_LIST), &t_list_dict_any, VV_RO},
     {VV_NAME("t_tuple",                 VAR_NUMBER), NULL, VV_RO},
     {VV_NAME("wayland_display",  VAR_STRING), NULL, VV_RO},
-    {VV_NAME("clipmethod",  VAR_STRING), NULL, VV_RO},
+    {VV_NAME("clipmethod",      VAR_STRING), NULL, VV_RO},
+    {VV_NAME("termda1",                 VAR_STRING), NULL, VV_RO},
 };
 
 // shorthand
index d3435ee1f7bdd4f2bd9e883f131268ac4325f795..2800535f504afe7d61ce7b2d36f32bbf6001ba96 100644 (file)
@@ -1719,7 +1719,7 @@ static char *(key_names[]) =
     "k7", "k8", "k9", "k;", "F1", "F2",
     "%1", "&8", "kb", "kI", "kD", "kh",
     "@7", "kP", "kN", "K1", "K3", "K4", "K5", "kB",
-    "PS", "PE",
+    "PS", "PE", "Ms",
     NULL
 };
 #endif
@@ -5495,6 +5495,8 @@ handle_csi_function_key(
  *     {lead}[ABCDEFHPQRS]
  *     {lead}1;{modifier}[ABCDEFHPQRS]
  *
+ * - DA1 query response: {lead}?...;c
+ *
  * Return 0 for no match, -1 for partial match, > 0 for full match.
  */
     static int
@@ -5607,6 +5609,22 @@ handle_csi(
        *slen = csi_len;
     }
 
+    // Primary device attributes (DA1) response
+    else if (first == '?' && trail == 'c')
+    {
+       LOG_TRN("Received DA1 response: %s", tp);
+
+       *slen = csi_len;
+#ifdef FEAT_EVAL
+       set_vim_var_string(VV_TERMDA1, tp, *slen);
+#endif
+       apply_autocmds(EVENT_TERMRESPONSEALL,
+                                       (char_u *)"da1", NULL, FALSE, curbuf);
+
+       key_name[0] = (int)KS_EXTRA;
+       key_name[1] = (int)KE_IGNORE;
+    }
+
     // Version string: Eat it when there is at least one digit and
     // it ends in 'c'
     else if (*T_CRV != NUL && ap > argp + 1 && trail == 'c')
index 1f2ea7de59431fb5cbfa039c7d4df57f394bcdb3..52a34df6f4f533412287db0514f83500760ac7c3 100644 (file)
@@ -2803,4 +2803,9 @@ func Test_xterm_direct_no_termguicolors()
   close
 endfunc
 
+func Test_da1_handling()
+  call feedkeys("\<Esc>[?62,52;c", 'Lx!')
+  call assert_equal("\<Esc>[?62,52;c", v:termda1)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index eedc6fd6df9065a23b205b08a6b06b2d70bc28cb..8e19f05c63d618ced11f721517c7db02a60e60c7 100644 (file)
@@ -724,6 +724,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1666,
 /**/
     1665,
 /**/
index 26d3fc339f6bc7b6cb212a1b83dd1603b86281e6..4a4a9b255c6ecdd0689833a8f4f18c8597d991df 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -2239,7 +2239,8 @@ typedef int sock_T;
 #define VV_TYPE_TUPLE  111
 #define VV_WAYLAND_DISPLAY 112
 #define VV_CLIPMETHOD 113
-#define VV_LEN         114     // number of v: vars
+#define VV_TERMDA1 114
+#define VV_LEN         115     // number of v: vars
 
 // used for v_number in VAR_BOOL and VAR_SPECIAL
 #define VVAL_FALSE     0L      // VAR_BOOL