To: vim_dev@googlegroups.com Subject: Patch 8.2.1589 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1589 Problem: Term_start() options for size are overruled by 'termwinsize'. (Sergey Vlasov) Solution: Set 'termwinsize' to the specified size. Files: src/terminal.c, src/testdir/test_terminal2.vim, src/testdir/term_util.vim *** ../vim-8.2.1588/src/terminal.c 2020-07-01 15:49:26.300450527 +0200 --- src/terminal.c 2020-09-04 17:18:04.323865150 +0200 *************** *** 280,287 **** * Determine the terminal size from 'termwinsize' and the current window. */ static void ! set_term_and_win_size(term_T *term) { #ifdef FEAT_GUI if (term->tl_system) { --- 280,290 ---- * Determine the terminal size from 'termwinsize' and the current window. */ static void ! set_term_and_win_size(term_T *term, jobopt_T *opt) { + int rows, cols; + int minsize; + #ifdef FEAT_GUI if (term->tl_system) { *************** *** 292,312 **** 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 win_setheight_win(term->tl_rows, curwin); ! if (term->tl_cols == 0) ! term->tl_cols = curwin->w_width; ! else win_setwidth_win(term->tl_cols, curwin); } /* --- 295,333 ---- return; } #endif ! 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 != 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,609 **** // the job finished. curbuf->b_p_ma = FALSE; ! set_term_and_win_size(term); #ifdef MSWIN mch_memmove(orig_opt.jo_io, opt->jo_io, sizeof(orig_opt.jo_io)); #endif --- 624,630 ---- // the job finished. curbuf->b_p_ma = FALSE; ! set_term_and_win_size(term, opt); #ifdef MSWIN mch_memmove(orig_opt.jo_io, opt->jo_io, sizeof(orig_opt.jo_io)); #endif *** ../vim-8.2.1588/src/testdir/test_terminal2.vim 2020-08-12 18:50:31.887655765 +0200 --- src/testdir/test_terminal2.vim 2020-09-04 17:55:24.762497710 +0200 *************** *** 109,114 **** --- 109,135 ---- 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,409 **** call delete('Xfile') endfunc ! func Test_terminal_no_job() if has('win32') ! let cmd = 'cmd /c ""' else CheckExecutable false ! let cmd = 'false' endif let term = term_start(cmd, {'term_finish': 'close'}) call WaitForAssert({-> assert_equal(v:null, term_getjob(term)) }) endfunc --- 418,434 ---- call delete('Xfile') endfunc ! func GetDummyCmd() if has('win32') ! return 'cmd /c ""' else CheckExecutable 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 *** ../vim-8.2.1588/src/testdir/term_util.vim 2020-07-01 21:53:33.411476027 +0200 --- src/testdir/term_util.vim 2020-09-04 17:41:55.044458335 +0200 *************** *** 73,79 **** set t_Co=256 background=light hi Normal ctermfg=NONE ctermbg=NONE ! " Make the window 20 lines high and 75 columns, unless told otherwise. let rows = get(a:options, 'rows', 20) let cols = get(a:options, 'cols', 75) let statusoff = get(a:options, 'statusoff', 1) --- 73,80 ---- set t_Co=256 background=light hi Normal ctermfg=NONE ctermbg=NONE ! " 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,96 **** let cmd = GetVimCommandCleanTerm() .. reset_u7 .. a:arguments ! let options = { ! \ 'curwin': 1, ! \ 'term_rows': rows, ! \ 'term_cols': cols, ! \ } " Accept other options whose name starts with 'term_'. call extend(options, filter(copy(a:options), 'v:key =~# "^term_"')) --- 87,98 ---- let cmd = GetVimCommandCleanTerm() .. reset_u7 .. a:arguments ! 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_"')) *** ../vim-8.2.1588/src/version.c 2020-09-04 16:35:06.425571289 +0200 --- src/version.c 2020-09-04 18:33:42.784679508 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1589, /**/ -- ARTHUR: Then who is your lord? WOMAN: We don't have a lord. ARTHUR: What? DENNIS: I told you. We're an anarcho-syndicalist commune. We take it in turns to act as a sort of executive officer for the week. The Quest for the Holy Grail (Monty Python) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///