]> granicus.if.org Git - vim/commitdiff
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize' v8.2.1589
authorBram Moolenaar <Bram@vim.org>
Fri, 4 Sep 2020 16:34:09 +0000 (18:34 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 4 Sep 2020 16:34:09 +0000 (18:34 +0200)
Problem:    Term_start() options for size are overruled by 'termwinsize'.
            (Sergey Vlasov)
Solution:   Set 'termwinsize' to the specified size.

src/terminal.c
src/testdir/term_util.vim
src/testdir/test_terminal2.vim
src/version.c

index bd5fd41ee73b5af7ad0d6e9f265363a9ffe7e09f..7856ad586ca90f4571bdbb2411f1a861460c363b 100644 (file)
@@ -280,8 +280,11 @@ parse_termwinsize(win_T *wp, int *rows, int *cols)
  * Determine the terminal size from 'termwinsize' and the current window.
  */
     static void
-set_term_and_win_size(term_T *term)
+set_term_and_win_size(term_T *term, jobopt_T *opt)
 {
+    int rows, cols;
+    int        minsize;
+
 #ifdef FEAT_GUI
     if (term->tl_system)
     {
@@ -292,21 +295,39 @@ set_term_and_win_size(term_T *term)
        return;
     }
 #endif
-    if (parse_termwinsize(curwin, &term->tl_rows, &term->tl_cols))
-    {
-       if (term->tl_rows != 0)
-           term->tl_rows = MAX(term->tl_rows, curwin->w_height);
-       if (term->tl_cols != 0)
-           term->tl_cols = MAX(term->tl_cols, curwin->w_width);
-    }
-    if (term->tl_rows == 0)
-       term->tl_rows = curwin->w_height;
-    else
+    term->tl_rows = curwin->w_height;
+    term->tl_cols = curwin->w_width;
+
+    minsize = parse_termwinsize(curwin, &rows, &cols);
+    if (minsize)
+    {
+       if (term->tl_rows < rows)
+           term->tl_rows = rows;
+       if (term->tl_cols < cols)
+           term->tl_cols = cols;
+    }
+    if ((opt->jo_set2 & JO2_TERM_ROWS))
+       term->tl_rows = opt->jo_term_rows;
+    else if (rows != 0)
+       term->tl_rows = rows;
+    if ((opt->jo_set2 & JO2_TERM_COLS))
+       term->tl_cols = opt->jo_term_cols;
+    else if (cols != 0)
+       term->tl_cols = cols;
+
+    if (term->tl_rows != curwin->w_height)
        win_setheight_win(term->tl_rows, curwin);
-    if (term->tl_cols == 0)
-       term->tl_cols = curwin->w_width;
-    else
+    if (term->tl_cols != curwin->w_width)
        win_setwidth_win(term->tl_cols, curwin);
+
+    // Set 'winsize' now to avoid a resize at the next redraw.
+    if (!minsize && *curwin->w_p_tws != NUL)
+    {
+       char_u buf[100];
+
+       vim_snprintf((char *)buf, 100, "%dx%d", term->tl_rows, term->tl_cols);
+       set_option_value((char_u *)"termwinsize", 0L, buf, OPT_LOCAL);
+    }
 }
 
 /*
@@ -603,7 +624,7 @@ term_start(
     // the job finished.
     curbuf->b_p_ma = FALSE;
 
-    set_term_and_win_size(term);
+    set_term_and_win_size(term, opt);
 #ifdef MSWIN
     mch_memmove(orig_opt.jo_io, opt->jo_io, sizeof(orig_opt.jo_io));
 #endif
index 17f9752a99b25c9e17c289a9a722a42a2f3b748c..4a5e64989bca61c7604715bbed9aeb9f819f4fa5 100644 (file)
@@ -73,7 +73,8 @@ func RunVimInTerminal(arguments, options)
   set t_Co=256 background=light
   hi Normal ctermfg=NONE ctermbg=NONE
 
-  " Make the window 20 lines high and 75 columns, unless told otherwise.
+  " Make the window 20 lines high and 75 columns, unless told otherwise or
+  " 'termwinsize' is set.
   let rows = get(a:options, 'rows', 20)
   let cols = get(a:options, 'cols', 75)
   let statusoff = get(a:options, 'statusoff', 1)
@@ -86,11 +87,12 @@ func RunVimInTerminal(arguments, options)
 
   let cmd = GetVimCommandCleanTerm() .. reset_u7 .. a:arguments
 
-  let options = {
-       \ 'curwin': 1,
-       \ 'term_rows': rows,
-       \ 'term_cols': cols,
-       \ }
+  let options = #{curwin: 1}
+  if &termwinsize == ''
+    let options.term_rows = rows
+    let options.term_cols = cols
+  endif
+
   " Accept other options whose name starts with 'term_'.
   call extend(options, filter(copy(a:options), 'v:key =~# "^term_"'))
 
index 93ace42d827b945a96392ec0835a41bf4349c1ca..f9f221b5cff41ca520d22244408056e8d08ee4e4 100644 (file)
@@ -109,6 +109,27 @@ func Test_terminal_termwinsize_minimum()
   set termwinsize=
 endfunc
 
+func Test_terminal_termwinsize_overruled()
+  let cmd = GetDummyCmd()
+  set termwinsize=5x43
+  let buf = term_start(cmd, #{term_rows: 7, term_cols: 50})
+  call TermWait(buf)
+  call assert_equal([7, 50], term_getsize(buf))
+  exe "bwipe! " .. buf
+
+  let buf = term_start(cmd, #{term_cols: 50})
+  call TermWait(buf)
+  call assert_equal([5, 50], term_getsize(buf))
+  exe "bwipe! " .. buf
+
+  let buf = term_start(cmd, #{term_rows: 7})
+  call TermWait(buf)
+  call assert_equal([7, 43], term_getsize(buf))
+  exe "bwipe! " .. buf
+
+  set termwinsize=
+endfunc
+
 func Test_terminal_termwinkey()
   " make three tabpages, terminal in the middle
   0tabnew
@@ -397,13 +418,17 @@ func Test_terminal_does_not_truncate_last_newlines()
   call delete('Xfile')
 endfunc
 
-func Test_terminal_no_job()
+func GetDummyCmd()
   if has('win32')
-    let cmd = 'cmd /c ""'
+    return 'cmd /c ""'
   else
     CheckExecutable false
-    let cmd = 'false'
+    return 'false'
   endif
+endfunc
+
+func Test_terminal_no_job()
+  let cmd = GetDummyCmd()
   let term = term_start(cmd, {'term_finish': 'close'})
   call WaitForAssert({-> assert_equal(v:null, term_getjob(term)) })
 endfunc
index 2c6e47efc0fb289e16e2f240aa2bdc6545f67fd5..26a30c152919172e9501d521f2c6f401a7f65a37 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1589,
 /**/
     1588,
 /**/