]> granicus.if.org Git - vim/commitdiff
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal v8.2.3597
authorBram Moolenaar <Bram@vim.org>
Mon, 15 Nov 2021 17:13:11 +0000 (17:13 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 15 Nov 2021 17:13:11 +0000 (17:13 +0000)
Problem:    Vim seems to hang when writing a very long text to a terminal
            window.
Solution:   Limit the amount of text based on 'termwinscroll'. (issue #9080)

runtime/doc/options.txt
src/terminal.c
src/version.c

index cf953c115c619a221346b773a4cf6e7950371d36..7fe371b5213cc76e8c2472a8f11fb334628db476 100644 (file)
@@ -7941,6 +7941,9 @@ A jump table for the options with a short description can be found at |Q_op|.
        Number of scrollback lines to keep.  When going over this limit the
        first 10% of the scrollback lines are deleted.  This is just to reduce
        the memory usage.  See |Terminal-Normal|.
+       Also used as a limit for text sent to the terminal in one write,
+       multiplied by the number of columns times 3 (average number of bytes
+       per cell).
 
                                                *'termwinsize'* *'tws'*
 'termwinsize' 'tws'    string  (default "")
index 1adf690adefc1465e9eef6d2ac0ca93f2f1ea41f..fb8b2881fb0bad8ea732e323065d3d8ce8579387 100644 (file)
@@ -1130,10 +1130,24 @@ get_tty_part(term_T *term UNUSED)
  * Write job output "msg[len]" to the vterm.
  */
     static void
-term_write_job_output(term_T *term, char_u *msg, size_t len)
+term_write_job_output(term_T *term, char_u *msg_arg, size_t len_arg)
 {
+    char_u     *msg = msg_arg;
+    size_t     len = len_arg;
     VTerm      *vterm = term->tl_vterm;
     size_t     prevlen = vterm_output_get_buffer_current(vterm);
+    size_t     limit = term->tl_buffer->b_p_twsl * term->tl_cols * 3;
+
+    // Limit the length to 'termwinscroll' * cols * 3 bytes.  Keep the text at
+    // the end.
+    if (len > limit)
+    {
+       char_u *p = msg + len - limit;
+
+       p -= (*mb_head_off)(msg, p);
+       len -= p - msg;
+       msg = p;
+    }
 
     vterm_input_write(vterm, (char *)msg, len);
 
index 39a61c915091fbcad4da18e097ccf5a34ff085b2..9cf0ee6396c1b833085e4c23c1aa92f8eaf937b5 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3597,
 /**/
     3596,
 /**/