To: vim_dev@googlegroups.com Subject: Patch 8.0.1612 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1612 Problem: Need to close terminal after shell stopped. Solution: Make :terminal without argument close the window by default. Files: src/terminal.c, src/testdir/test_terminal.vim, runtime/doc/terminal.txt *** ../vim-8.0.1611/src/terminal.c 2018-03-16 22:20:44.202630832 +0100 --- src/terminal.c 2018-03-16 22:40:28.744229156 +0100 *************** *** 38,45 **** * in tl_scrollback are no longer used. * * TODO: - * - Make terminal close by default when started without a command. Add - * ++noclose argument. * - Win32: In the GUI use a terminal emulator for :!cmd. * - Add a way to set the 16 ANSI colors, to be used for 'termguicolors' and in * the GUI. --- 38,43 ---- *************** *** 123,129 **** int tl_normal_mode; /* TRUE: Terminal-Normal mode */ int tl_channel_closed; ! int tl_finish; /* 'c' for ++close, 'o' for ++open */ char_u *tl_opencmd; char_u *tl_eof_chars; --- 121,131 ---- int tl_normal_mode; /* TRUE: Terminal-Normal mode */ int tl_channel_closed; ! int tl_finish; ! #define TL_FINISH_UNSET NUL ! #define TL_FINISH_CLOSE 'c' /* ++close or :terminal without argument */ ! #define TL_FINISH_NOCLOSE 'n' /* ++noclose */ ! #define TL_FINISH_OPEN 'o' /* ++open */ char_u *tl_opencmd; char_u *tl_eof_chars; *************** *** 643,648 **** --- 645,652 ---- if ((int)(p - cmd) == 5 && STRNICMP(cmd, "close", 5) == 0) opt.jo_term_finish = 'c'; + else if ((int)(p - cmd) == 7 && STRNICMP(cmd, "noclose", 7) == 0) + opt.jo_term_finish = 'n'; else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "open", 4) == 0) opt.jo_term_finish = 'o'; else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "curwin", 6) == 0) *************** *** 696,704 **** --- 700,714 ---- cmd = skipwhite(p); } if (*cmd == NUL) + { /* Make a copy of 'shell', an autocommand may change the option. */ tofree = cmd = vim_strsave(p_sh); + /* default to close when the shell exits */ + if (opt.jo_term_finish == NUL) + opt.jo_term_finish = 'c'; + } + if (eap->addr_count > 0) { /* Write lines from current buffer to the job. */ *************** *** 1535,1541 **** static void cleanup_vterm(term_T *term) { ! if (term->tl_finish != 'c') move_terminal_to_buffer(term); term_free_vterm(term); set_terminal_mode(term, FALSE); --- 1545,1551 ---- static void cleanup_vterm(term_T *term) { ! if (term->tl_finish != TL_FINISH_CLOSE) move_terminal_to_buffer(term); term_free_vterm(term); set_terminal_mode(term, FALSE); *************** *** 2603,2609 **** cleanup_vterm(term); ! if (term->tl_finish == 'c') { aco_save_T aco; --- 2613,2619 ---- cleanup_vterm(term); ! if (term->tl_finish == TL_FINISH_CLOSE) { aco_save_T aco; *************** *** 2614,2620 **** aucmd_restbuf(&aco); break; } ! if (term->tl_finish == 'o' && term->tl_buffer->b_nwindows == 0) { char buf[50]; --- 2624,2631 ---- aucmd_restbuf(&aco); break; } ! if (term->tl_finish == TL_FINISH_OPEN ! && term->tl_buffer->b_nwindows == 0) { char buf[50]; *** ../vim-8.0.1611/src/testdir/test_terminal.vim 2018-03-13 17:55:23.929643864 +0100 --- src/testdir/test_terminal.vim 2018-03-16 22:51:14.872212873 +0100 *************** *** 367,372 **** --- 367,392 ---- let [cmd, waittime] = s:get_sleep_cmd() + " shell terminal closes automatically + terminal + let buf = bufnr('%') + call assert_equal(2, winnr('$')) + " Wait for the shell to display a prompt + call WaitFor({-> term_getline(buf, 1) != ""}) + call Stop_shell_in_terminal(buf) + call WaitFor("winnr('$') == 1", waittime) + + " shell terminal that does not close automatically + terminal ++noclose + let buf = bufnr('%') + call assert_equal(2, winnr('$')) + " Wait for the shell to display a prompt + call WaitFor({-> term_getline(buf, 1) != ""}) + call Stop_shell_in_terminal(buf) + call assert_equal(2, winnr('$')) + quit + call assert_equal(1, winnr('$')) + exe 'terminal ++close ' . cmd call assert_equal(2, winnr('$')) wincmd p *** ../vim-8.0.1611/runtime/doc/terminal.txt 2018-03-10 20:27:32.075757637 +0100 --- runtime/doc/terminal.txt 2018-03-16 22:28:21.972170005 +0100 *************** *** 140,145 **** --- 145,157 ---- if [command] is NONE no job is started, the pty of the terminal can be used by a command like gdb. + If [command] is missing the default behavior is to + close the terminal when the shell exits. This can be + changed with the ++noclose argument. + If [command] is present the default behavior is to + keep the terminal open in Terminal-Normal mode. This + can be changed with the ++close argument. + A new buffer will be created, using [command] or 'shell' as the name, prefixed with a "!". If a buffer by this name already exists a number is added in *************** *** 155,163 **** --- 167,180 ---- Supported [options] are: ++close The terminal window will close automatically when the job terminates. + ++noclose The terminal window will NOT close + automatically when the job terminates. ++open When the job terminates and no window shows it, a window will be opened. Note that this can be interruptive. + The last of ++close, ++noclose and ++open + matters and rules out earlier arguments. + ++curwin Open the terminal in the current window, do not split the current window. Fails if the current buffer *** ../vim-8.0.1611/src/version.c 2018-03-16 22:20:44.202630832 +0100 --- src/version.c 2018-03-16 22:33:54.302373624 +0100 *************** *** 768,769 **** --- 768,771 ---- { /* Add new patch number below this line */ + /**/ + 1612, /**/ -- How To Keep A Healthy Level Of Insanity: 3. Every time someone asks you to do something, ask if they want fries with that. /// 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 ///