From 8c041b6b95f49f7383cf00e2036cf009b326fa8d Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 14 Apr 2018 18:14:06 +0200 Subject: patch 8.0.1712: terminal scrollback is not limited Problem: Terminal scrollback is not limited. Solution: Add the 'terminalscroll' option. --- src/option.c | 9 +++++++++ src/option.h | 3 +++ src/terminal.c | 24 +++++++++++++++++++++--- src/version.c | 2 ++ 4 files changed, 35 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/option.c b/src/option.c index 5ef346c8d..9ebc51183 100644 --- a/src/option.c +++ b/src/option.c @@ -2748,6 +2748,15 @@ static struct vimoption options[] = #else (char_u*)NULL, PV_NONE, {(char_u *)FALSE, (char_u *)FALSE} +#endif + SCRIPTID_INIT}, + {"terminalscroll", "tlsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF, +#ifdef FEAT_TERMINAL + (char_u *)&p_tlsl, PV_NONE, + {(char_u *)10000L, (char_u *)10000L} +#else + (char_u *)NULL, PV_NONE, + {(char_u *)NULL, (char_u *)0L} #endif SCRIPTID_INIT}, {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF, diff --git a/src/option.h b/src/option.h index d2ee54534..45f1a36bc 100644 --- a/src/option.h +++ b/src/option.h @@ -849,6 +849,9 @@ EXTERN char_u *p_tcldll; /* 'tcldll' */ #ifdef FEAT_ARABIC EXTERN int p_tbidi; /* 'termbidi' */ #endif +#ifdef FEAT_TERMINAL +EXTERN long p_tlsl; /* 'terminalscroll' */ +#endif #ifdef FEAT_MBYTE EXTERN char_u *p_tenc; /* 'termencoding' */ #endif diff --git a/src/terminal.c b/src/terminal.c index 09d48872d..7162d684c 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -40,8 +40,6 @@ * TODO: * - Win32: Make terminal used for :!cmd in the GUI work better. Allow for * redirection. Probably in call to channel_set_pipes(). - * - add an optional limit for the scrollback size. When reaching it remove - * 10% at the start. * - Copy text in the vterm to the Vim buffer once in a while, so that * completion works. * - in GUI vertical split causes problems. Cursor is flickering. (Hirohito @@ -2518,7 +2516,27 @@ handle_pushline(int cols, const VTermScreenCell *cells, void *user) { term_T *term = (term_T *)user; - /* TODO: Limit the number of lines that are stored. */ + /* If the number of lines that are stored goes over 'termscrollback' then + * delete the first 10%. */ + if (term->tl_scrollback.ga_len > p_tlsl) + { + int todo = p_tlsl / 10; + int i; + + curbuf = term->tl_buffer; + for (i = 0; i < todo; ++i) + { + vim_free(((sb_line_T *)term->tl_scrollback.ga_data + i)->sb_cells); + ml_delete(1, FALSE); + } + curbuf = curwin->w_buffer; + + term->tl_scrollback.ga_len -= todo; + mch_memmove(term->tl_scrollback.ga_data, + (sb_line_T *)term->tl_scrollback.ga_data + todo, + sizeof(sb_line_T) * term->tl_scrollback.ga_len); + } + if (ga_grow(&term->tl_scrollback, 1) == OK) { cellattr_T *p = NULL; diff --git a/src/version.c b/src/version.c index 255e24bd9..41b9721ca 100644 --- a/src/version.c +++ b/src/version.c @@ -762,6 +762,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1712, /**/ 1711, /**/ -- cgit v1.2.3