To: vim_dev@googlegroups.com Subject: Patch 8.2.0286 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0286 Problem: Cannot use popup_close() for a terminal popup. Solution: Allow using popup_close(). (closes #5666) Files: src/popupwin.c, runtime/doc/popup.txt, src/testdir/test_terminal.vim, src/testdir/dumps/Test_terminal_popup_5.dump, src/testdir/dumps/Test_terminal_popup_6.dump *** ../vim-8.2.0285/src/popupwin.c 2020-02-05 21:07:00.110961395 +0100 --- src/popupwin.c 2020-02-20 19:54:53.690744704 +0100 *************** *** 2360,2366 **** int id = (int)tv_get_number(argvars); win_T *wp; ! if (ERROR_IF_ANY_POPUP_WINDOW) return; wp = find_popup_win(id); --- 2360,2371 ---- int id = (int)tv_get_number(argvars); win_T *wp; ! if ( ! # ifdef FEAT_TERMINAL ! // if the popup contains a terminal it will become hidden ! curbuf->b_term == NULL && ! # endif ! ERROR_IF_ANY_POPUP_WINDOW) return; wp = find_popup_win(id); *** ../vim-8.2.0285/runtime/doc/popup.txt 2019-12-12 12:49:06.000000000 +0100 --- runtime/doc/popup.txt 2020-02-20 20:02:01.396878339 +0100 *************** *** 11,16 **** --- 11,17 ---- Window position and size |popup-position| Closing the popup window |popup-close| Popup buffer and window |popup-buffer| + Terminal in popup window |popup-terminal| 2. Functions |popup-functions| Details |popup-function-details| 3. Usage |popup-usage| *************** *** 140,145 **** --- 141,164 ---- You can also use `win_execute()` with a ":setlocal" command. + TERMINAL IN POPUP WINDOW *popup-terminal* + + A special case is running a terminal in a popup window. Many rules are then + different: *E863* + - The popup window always has focus, it is not possible to switch to another + window. + - When the job ends, the popup window closes. + - The popup window can be closed with `popup_close()`, the terminal buffer + then becomes hidden. + - The default Pmenu color is only used for the border and padding. To change + the color of the terminal itself set 'wincolor'. + + To run a terminal in a popup window, first create the terminal hidden. Then + pass the buffer number to popup_create(). Example: > + let buf = term_start(['picker', 'Something'], #{hidden: 1, term_finish: 'close'}) + let winid = popup_create(buf, #{minwidth: 50, minheight: 20}) + set wincolor=Search + ============================================================================== 2. Functions *popup-functions* *************** *** 385,390 **** --- 404,410 ---- hidden. If window {id} does not exist nothing happens. If window {id} exists but is not a popup window an error is given. *E993* + If popup window {id} contains a terminal an error is given. Can also be used as a |method|: > GetPopup()->popup_hide() *** ../vim-8.2.0285/src/testdir/test_terminal.vim 2020-02-16 17:04:04.934149377 +0100 --- src/testdir/test_terminal.vim 2020-02-20 20:07:50.691389724 +0100 *************** *** 2337,2344 **** \ 'call setline(1, range(20))', \ 'hi PopTerm ctermbg=grey', \ 'func OpenTerm(setColor)', ! \ " let buf = term_start('" .. cmd .. " Xtext', #{hidden: 1, term_finish: 'close'})", ! \ ' let s:winid = popup_create(buf, #{minwidth: 45, minheight: 7, border: [], drag: 1, resize: 1})', \ ' if a:setColor', \ ' call win_execute(s:winid, "set wincolor=PopTerm")', \ ' endif', --- 2337,2344 ---- \ 'call setline(1, range(20))', \ 'hi PopTerm ctermbg=grey', \ 'func OpenTerm(setColor)', ! \ " let s:buf = term_start('" .. cmd .. " Xtext', #{hidden: 1, term_finish: 'close'})", ! \ ' let s:winid = popup_create(s:buf, #{minwidth: 45, minheight: 7, border: [], drag: 1, resize: 1})', \ ' if a:setColor', \ ' call win_execute(s:winid, "set wincolor=PopTerm")', \ ' endif', *************** *** 2347,2352 **** --- 2347,2358 ---- \ 'func HidePopup()', \ ' call popup_hide(s:winid)', \ 'endfunc', + \ 'func ClosePopup()', + \ ' call popup_close(s:winid)', + \ 'endfunc', + \ 'func ReopenPopup()', + \ ' call popup_create(s:buf, #{minwidth: 40, minheight: 6, border: []})', + \ 'endfunc', \ 'sleep 10m', \ 'redraw', \ 'echo getwinvar(s:winid, "&buftype") win_gettype(s:winid)', *************** *** 2370,2375 **** --- 2376,2388 ---- call term_sendkeys(buf, "\") call term_wait(buf, 100) + call term_sendkeys(buf, "\:call ClosePopup()\") + call VerifyScreenDump(buf, 'Test_terminal_popup_5', {}) + + call term_sendkeys(buf, "\:call ReopenPopup()\") + call VerifyScreenDump(buf, 'Test_terminal_popup_6', {}) + call term_wait(buf, 100) + call term_sendkeys(buf, ":q\") call term_wait(buf, 100) " wait for terminal to vanish *** ../vim-8.2.0285/src/testdir/dumps/Test_terminal_popup_5.dump 2020-02-20 20:11:21.394499724 +0100 --- src/testdir/dumps/Test_terminal_popup_5.dump 2020-02-20 20:08:14.923287133 +0100 *************** *** 0 **** --- 1,15 ---- + >0+0&#ffffff0| @73 + |1| @73 + |2| @73 + |3| @73 + |4| @73 + |5| @73 + |6| @73 + |7| @73 + |8| @73 + |9| @73 + |1|0| @72 + |1@1| @72 + |1|2| @72 + |1|3| @72 + |:|c|a|l@1| |C|l|o|s|e|P|o|p|u|p|(|)| @38|1|,|1| @10|T|o|p| *** ../vim-8.2.0285/src/testdir/dumps/Test_terminal_popup_6.dump 2020-02-20 20:11:21.398499705 +0100 --- src/testdir/dumps/Test_terminal_popup_6.dump 2020-02-20 20:08:15.983282647 +0100 *************** *** 0 **** --- 1,15 ---- + |0+0&#ffffff0| @73 + |1| @73 + |2| @73 + |3| @12|╔+0#0000001#ffd7ff255|═@44|╗| +0#0000000#ffffff0@13 + |4| @12|║+0#0000001#ffd7ff255|s+0#0000000#ffffff0|o|m|e| |t|e|x|t| @35|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13 + |5| @12|║+0#0000001#ffd7ff255|t+0#0000000#ffffff0|o| >e+0&#ffff4012|d|i|t| +0&#ffffff0@37|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13 + |6| @12|║+0#0000001#ffd7ff255|i+0#0000000#ffffff0|n| |a| |p|o|p|u|p| |w|i|n|d|o|w| @27|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13 + |7| @12|║+0#0000001#ffd7ff255|~+0#4040ff13#ffffff0| @43|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13 + |8| @12|║+0#0000001#ffd7ff255|~+0#4040ff13#ffffff0| @43|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13 + |9| @12|║+0#0000001#ffd7ff255|~+0#4040ff13#ffffff0| @43|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13 + |1|0| @11|║+0#0000001#ffd7ff255|/+0#0000000#ffffff0|e|d|i|t| @21|2|,|4| @10|A|l@1| |║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13 + |1@1| @11|╚+0#0000001#ffd7ff255|═@44|╝| +0#0000000#ffffff0@13 + |1|2| @72 + |1|3| @72 + @57|1|,|1| @10|A|l@1| *** ../vim-8.2.0285/src/version.c 2020-02-19 22:31:44.886288858 +0100 --- src/version.c 2020-02-20 20:08:57.399107448 +0100 *************** *** 740,741 **** --- 740,743 ---- { /* Add new patch number below this line */ + /**/ + 286, /**/ -- There's no place like $(HOME)! /// 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 ///