]> granicus.if.org Git - vim/commitdiff
patch 8.2.5056: the channel log only contains some of the raw terminal output v8.2.5056
authorBram Moolenaar <Bram@vim.org>
Sat, 4 Jun 2022 21:15:54 +0000 (22:15 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 4 Jun 2022 21:15:54 +0000 (22:15 +0100)
Problem:    The channel log only contains some of the raw terminal output.
Solution:   Add the "o" flag to log all terminal output.  Use it for "--log".

runtime/doc/channel.txt
runtime/doc/starting.txt
src/channel.c
src/edit.c
src/main.c
src/normal.c
src/optionstr.c
src/term.c
src/version.c
src/vim.h

index 01a9e3695dbe99dba3cce76b1497a314af47c3b5..6705c59c342341fefcdb945063d033a9ede864a9 100644 (file)
@@ -628,15 +628,18 @@ ch_logfile({fname} [, {mode}])                                    *ch_logfile()*
                Start logging channel activity to {fname}.
                When {fname} is an empty string: stop logging.
 
-               When {mode} is omitted or "a" append to the file.
-               When {mode} is "w" start with an empty file.
+               When {mode} is omitted or contains "a" or is "o" then append
+               to the file.
+               When {mode} contains "w" and not "a" start with an empty file.
+               When {mode} contains "o" then log all terminal output.
+               Otherwise only some interesting terminal output is logged.
 
                Use |ch_log()| to write log messages.  The file is flushed
                after every message, on Unix you can use "tail -f" to see what
                is going on in real time.
 
                To enable the log very early, to see what is received from a
-               terminal during startup, use |--log|: >
+               terminal during startup, use |--log| (this uses mode "ao"): >
                        vim --log logfile
 <
                This function is not available in the |sandbox|.
index f5b33a8886def16c036e9cf6036bff226ac18502..ec095a472fdc31d6205203ec41993931ea969103 100644 (file)
@@ -346,7 +346,7 @@ a slash.  Thus "-R" means recovery and "-/R" readonly.
 <
 --log {filename}                                       *--log*
                Start logging and write entries to {filename}.
-               This works like calling `ch_logfile({filename}, 'a')` very
+               This works like calling `ch_logfile({filename}, 'ao')` very
                early during startup.
                {only available with the +channel feature}
 
index e3b32eebf809793770d42ba7cce94aa80adbd8eb..abd2ce1da0f892af9b8ef6240b192b3aa74d3ea5 100644 (file)
@@ -152,7 +152,8 @@ static proftime_T log_start;
     void
 ch_logfile(char_u *fname, char_u *opt)
 {
-    FILE   *file = NULL;
+    FILE       *file = NULL;
+    char       *mode = "a";
 
     if (log_fd != NULL)
     {
@@ -163,9 +164,14 @@ ch_logfile(char_u *fname, char_u *opt)
        fclose(log_fd);
     }
 
+    // The "a" flag overrules the "w" flag.
+    if (vim_strchr(opt, 'a') == NULL && vim_strchr(opt, 'w') != NULL)
+       mode = "w";
+    ch_log_output = vim_strchr(opt, 'o') != NULL ? LOG_ALWAYS : FALSE;
+
     if (*fname != NUL)
     {
-       file = fopen((char *)fname, *opt == 'w' ? "w" : "a");
+       file = fopen((char *)fname, mode);
        if (file == NULL)
        {
            semsg(_(e_cant_open_file_str), fname);
index 443e023d5c719564bbc33b0ae8bcd33550a98579..dbfa0ae5f9929dfae8b8f7f4a529e02a713cb639 100644 (file)
@@ -319,9 +319,8 @@ edit(
 #endif
     if (!p_ek)
     {
-#ifdef FEAT_JOB_CHANNEL
-       ch_log_output = TRUE;
-#endif
+       MAY_WANT_TO_LOG_THIS;
+
        // Disable bracketed paste mode, we won't recognize the escape
        // sequences.
        out_str(T_BD);
@@ -3690,9 +3689,8 @@ ins_esc(
 #endif
     if (!p_ek)
     {
-#ifdef FEAT_JOB_CHANNEL
-       ch_log_output = TRUE;
-#endif
+       MAY_WANT_TO_LOG_THIS;
+
        // Re-enable bracketed paste mode.
        out_str(T_BE);
 
index b72c9aecfc3af9aee2d04678a3dfd9c6494d9cd6..b92be4cfefb587ce1c514ca93c99b8c88eb34525 100644 (file)
@@ -152,7 +152,7 @@ main
 # endif
 # ifdef FEAT_JOB_CHANNEL
        if (STRICMP(argv[i], "--log") == 0)
-           ch_logfile((char_u *)(argv[i + 1]), (char_u *)"a");
+           ch_logfile((char_u *)(argv[i + 1]), (char_u *)"ao");
 # endif
     }
 #endif
index f075986551454050ac862398ed78afe8bd45e4f2..fdbc5c838365531dcbedb69737e6dd5ddac08597 100644 (file)
@@ -431,9 +431,8 @@ normal_cmd_get_more_chars(
 #endif
        if ((State & MODE_INSERT) && !p_ek)
        {
-#ifdef FEAT_JOB_CHANNEL
-           ch_log_output = TRUE;
-#endif
+           MAY_WANT_TO_LOG_THIS;
+
            // Disable bracketed paste and modifyOtherKeys here, we won't
            // recognize the escape sequences with 'esckeys' off.
            out_str(T_BD);
@@ -444,9 +443,8 @@ normal_cmd_get_more_chars(
 
        if ((State & MODE_INSERT) && !p_ek)
        {
-#ifdef FEAT_JOB_CHANNEL
-           ch_log_output = TRUE;
-#endif
+           MAY_WANT_TO_LOG_THIS;
+
            // Re-enable bracketed paste mode and modifyOtherKeys
            out_str(T_BE);
            out_str(T_CTI);
index 44e178cbac3ddf74cb7a7cb43d962da49df97b7f..c26667a2bc5b8db059dca755dcc752748e5e9893 100644 (file)
@@ -1462,9 +1462,8 @@ ambw_end:
        }
        if (varp == &T_BE && termcap_active)
        {
-#ifdef FEAT_JOB_CHANNEL
-           ch_log_output = TRUE;
-#endif
+           MAY_WANT_TO_LOG_THIS;
+
            if (*T_BE == NUL)
                // When clearing t_BE we assume the user no longer wants
                // bracketed paste, thus disable it by writing t_BD.
index 7449d88c68acaed466a05ee28fdaef9ee0e125b0..96a81800a144f0ca89e76e92adbae8b11fbce8da 100644 (file)
@@ -2570,7 +2570,7 @@ out_flush(void)
        out_pos = 0;
        ui_write(out_buf, len, FALSE);
 #ifdef FEAT_JOB_CHANNEL
-       if (ch_log_output)
+       if (ch_log_output != FALSE)
        {
            out_buf[len] = NUL;
            ch_log(NULL, "raw %s output: \"%s\"",
@@ -2579,7 +2579,8 @@ out_flush(void)
 # endif
                        "terminal",
                        out_buf);
-           ch_log_output = FALSE;
+           if (ch_log_output == TRUE)
+               ch_log_output = FALSE;  // only log once
        }
 #endif
     }
@@ -3106,9 +3107,8 @@ term_ul_rgb_color(guicolor_T rgb)
     void
 term_settitle(char_u *title)
 {
-#ifdef FEAT_JOB_CHANNEL
-    ch_log_output = TRUE;
-#endif
+    MAY_WANT_TO_LOG_THIS;
+
     // t_ts takes one argument: column in status line
     OUT_STR(tgoto((char *)T_TS, 0, 0));        // set title start
     out_str_nf(title);
@@ -3610,9 +3610,8 @@ settmode(tmode_T tmode)
            if (termcap_active && tmode != TMODE_SLEEP
                                                   && cur_tmode != TMODE_SLEEP)
            {
-#ifdef FEAT_JOB_CHANNEL
-               ch_log_output = TRUE;
-#endif
+               MAY_WANT_TO_LOG_THIS;
+
                if (tmode != TMODE_RAW)
                {
                    out_str(T_BD);      // disable bracketed paste mode
@@ -3643,9 +3642,8 @@ starttermcap(void)
 {
     if (full_screen && !termcap_active)
     {
-#ifdef FEAT_JOB_CHANNEL
-       ch_log_output = TRUE;
-#endif
+       MAY_WANT_TO_LOG_THIS;
+
        out_str(T_TI);                  // start termcap mode
        out_str(T_CTI);                 // start "raw" mode
        out_str(T_KS);                  // start "keypad transmit" mode
@@ -3705,9 +3703,7 @@ stoptermcap(void)
            check_for_codes_from_term();
        }
 #endif
-#ifdef FEAT_JOB_CHANNEL
-       ch_log_output = TRUE;
-#endif
+       MAY_WANT_TO_LOG_THIS;
 
 #if defined(UNIX) || defined(VMS)
        // Disable xterm's focus reporting mode if 'esckeys' is set.
@@ -3750,9 +3746,7 @@ may_req_termresponse(void)
            && starting == 0
            && *T_CRV != NUL)
     {
-#ifdef FEAT_JOB_CHANNEL
-       ch_log_output = TRUE;
-#endif
+       MAY_WANT_TO_LOG_THIS;
        LOG_TR(("Sending CRV request"));
        out_str(T_CRV);
        termrequest_sent(&crv_status);
@@ -3791,9 +3785,7 @@ check_terminal_behavior(void)
        // width, that will be (1, 2).  This function has the side effect that
        // changes cursor position, so it must be called immediately after
        // entering termcap mode.
-#ifdef FEAT_JOB_CHANNEL
-       ch_log_output = TRUE;
-#endif
+       MAY_WANT_TO_LOG_THIS;
        LOG_TR(("Sending request for ambiwidth check"));
        // Do this in the second row.  In the first row the returned sequence
        // may be CSI 1;2R, which is the same as <S-F3>.
@@ -3822,9 +3814,7 @@ check_terminal_behavior(void)
        // sequence is ignored and the cursor does not move.  If the terminal
        // handles test sequence incorrectly, a garbage string is displayed and
        // the cursor does move.
-#ifdef FEAT_JOB_CHANNEL
-       ch_log_output = TRUE;
-#endif
+       MAY_WANT_TO_LOG_THIS;
        LOG_TR(("Sending xterm compatibility test sequence."));
        // Do this in the third row.  Second row is used by ambiguous
        // character width check.
@@ -3875,9 +3865,7 @@ may_req_bg_color(void)
        // Only request foreground if t_RF is set.
        if (rfg_status.tr_progress == STATUS_GET && *T_RFG != NUL)
        {
-#ifdef FEAT_JOB_CHANNEL
-           ch_log_output = TRUE;
-#endif
+           MAY_WANT_TO_LOG_THIS;
            LOG_TR(("Sending FG request"));
            out_str(T_RFG);
            termrequest_sent(&rfg_status);
@@ -3888,9 +3876,7 @@ may_req_bg_color(void)
        // Only request background if t_RB is set.
        if (rbg_status.tr_progress == STATUS_GET && *T_RBG != NUL)
        {
-#ifdef FEAT_JOB_CHANNEL
-           ch_log_output = TRUE;
-#endif
+           MAY_WANT_TO_LOG_THIS;
            LOG_TR(("Sending BG request"));
            out_str(T_RBG);
            termrequest_sent(&rbg_status);
@@ -3954,9 +3940,7 @@ scroll_start(void)
 {
     if (*T_VS != NUL && *T_CVS != NUL)
     {
-#ifdef FEAT_JOB_CHANNEL
-       ch_log_output = TRUE;
-#endif
+       MAY_WANT_TO_LOG_THIS;
        out_str(T_VS);
        out_str(T_CVS);
        screen_start();         // don't know where cursor is now
@@ -4866,9 +4850,7 @@ handle_version_response(int first, int *arg, int argc, char_u *tp)
                && *T_CSH != NUL
                && *T_CRS != NUL)
        {
-#ifdef FEAT_JOB_CHANNEL
-           ch_log_output = TRUE;
-#endif
+           MAY_WANT_TO_LOG_THIS;
            LOG_TR(("Sending cursor style request"));
            out_str(T_CRS);
            termrequest_sent(&rcs_status);
@@ -4883,9 +4865,7 @@ handle_version_response(int first, int *arg, int argc, char_u *tp)
                && term_props[TPR_CURSOR_BLINK].tpr_status == TPR_YES
                && *T_CRC != NUL)
        {
-#ifdef FEAT_JOB_CHANNEL
-           ch_log_output = TRUE;
-#endif
+           MAY_WANT_TO_LOG_THIS;
            LOG_TR(("Sending cursor blink mode request"));
            out_str(T_CRC);
            termrequest_sent(&rbm_status);
@@ -6455,9 +6435,7 @@ req_more_codes_from_term(void)
     {
        char *key_name = key_names[xt_index_out];
 
-#ifdef FEAT_JOB_CHANNEL
-       ch_log_output = TRUE;
-#endif
+       MAY_WANT_TO_LOG_THIS;
        LOG_TR(("Requesting XT %d: %s", xt_index_out, key_name));
        sprintf(buf, "\033P+q%02x%02x\033\\", key_name[0], key_name[1]);
        out_str_nf((char_u *)buf);
index 5e666eda3229b115c7b1fe023e81b0850bcede79..8e048b1eeab6a643fdcaa93332384da0eb96a336 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    5056,
 /**/
     5055,
 /**/
index 9a970330ca5558fa446cf05617ed75336bc995e3..636283548f4a1af651ccf204fd51a2558ed2981b 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1479,6 +1479,17 @@ typedef enum
 
 #define MAYBE  2           // sometimes used for a variant on TRUE
 
+#define LOG_ALWAYS 9       // must be different from TRUE and FALSE
+
+#ifdef FEAT_JOB_CHANNEL
+// If "--log logfile" was used or ch_logfile() was called then log some or all
+// terminal output.
+# define MAY_WANT_TO_LOG_THIS if (ch_log_output == FALSE) ch_log_output = TRUE;
+#else
+// no logging support
+# define MAY_WANT_TO_LOG_THIS
+#endif
+
 #ifndef UINT32_T
 typedef UINT32_TYPEDEF UINT32_T;
 #endif