Mercurial > vim
comparison src/terminal.c @ 13476:d130044d4f1f v8.0.1612
patch 8.0.1612: need to close terminal after shell stopped
commit https://github.com/vim/vim/commit/1dd98334d6daee8abefcd640291d4b777d9f0f96
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Mar 16 22:54:53 2018 +0100
patch 8.0.1612: need to close terminal after shell stopped
Problem: Need to close terminal after shell stopped.
Solution: Make :terminal without argument close the window by default.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 16 Mar 2018 23:00:07 +0100 |
parents | 8a8daeb057d1 |
children | f7ef5d579758 |
comparison
equal
deleted
inserted
replaced
13475:15d3e684a78e | 13476:d130044d4f1f |
---|---|
36 * that buffer, attributes come from the scrollback buffer tl_scrollback. | 36 * that buffer, attributes come from the scrollback buffer tl_scrollback. |
37 * When the buffer is changed it is turned into a normal buffer, the attributes | 37 * When the buffer is changed it is turned into a normal buffer, the attributes |
38 * in tl_scrollback are no longer used. | 38 * in tl_scrollback are no longer used. |
39 * | 39 * |
40 * TODO: | 40 * TODO: |
41 * - Make terminal close by default when started without a command. Add | |
42 * ++noclose argument. | |
43 * - Win32: In the GUI use a terminal emulator for :!cmd. | 41 * - Win32: In the GUI use a terminal emulator for :!cmd. |
44 * - Add a way to set the 16 ANSI colors, to be used for 'termguicolors' and in | 42 * - Add a way to set the 16 ANSI colors, to be used for 'termguicolors' and in |
45 * the GUI. | 43 * the GUI. |
46 * - Some way for the job running in the terminal to send a :drop command back | 44 * - Some way for the job running in the terminal to send a :drop command back |
47 * to the Vim running the terminal. Should be usable by a simple shell or | 45 * to the Vim running the terminal. Should be usable by a simple shell or |
121 char_u *tl_tty_in; | 119 char_u *tl_tty_in; |
122 char_u *tl_tty_out; | 120 char_u *tl_tty_out; |
123 | 121 |
124 int tl_normal_mode; /* TRUE: Terminal-Normal mode */ | 122 int tl_normal_mode; /* TRUE: Terminal-Normal mode */ |
125 int tl_channel_closed; | 123 int tl_channel_closed; |
126 int tl_finish; /* 'c' for ++close, 'o' for ++open */ | 124 int tl_finish; |
125 #define TL_FINISH_UNSET NUL | |
126 #define TL_FINISH_CLOSE 'c' /* ++close or :terminal without argument */ | |
127 #define TL_FINISH_NOCLOSE 'n' /* ++noclose */ | |
128 #define TL_FINISH_OPEN 'o' /* ++open */ | |
127 char_u *tl_opencmd; | 129 char_u *tl_opencmd; |
128 char_u *tl_eof_chars; | 130 char_u *tl_eof_chars; |
129 | 131 |
130 #ifdef WIN3264 | 132 #ifdef WIN3264 |
131 void *tl_winpty_config; | 133 void *tl_winpty_config; |
641 if (ep != NULL && ep < p) | 643 if (ep != NULL && ep < p) |
642 p = ep; | 644 p = ep; |
643 | 645 |
644 if ((int)(p - cmd) == 5 && STRNICMP(cmd, "close", 5) == 0) | 646 if ((int)(p - cmd) == 5 && STRNICMP(cmd, "close", 5) == 0) |
645 opt.jo_term_finish = 'c'; | 647 opt.jo_term_finish = 'c'; |
648 else if ((int)(p - cmd) == 7 && STRNICMP(cmd, "noclose", 7) == 0) | |
649 opt.jo_term_finish = 'n'; | |
646 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "open", 4) == 0) | 650 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "open", 4) == 0) |
647 opt.jo_term_finish = 'o'; | 651 opt.jo_term_finish = 'o'; |
648 else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "curwin", 6) == 0) | 652 else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "curwin", 6) == 0) |
649 opt.jo_curwin = 1; | 653 opt.jo_curwin = 1; |
650 else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "hidden", 6) == 0) | 654 else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "hidden", 6) == 0) |
694 goto theend; | 698 goto theend; |
695 } | 699 } |
696 cmd = skipwhite(p); | 700 cmd = skipwhite(p); |
697 } | 701 } |
698 if (*cmd == NUL) | 702 if (*cmd == NUL) |
703 { | |
699 /* Make a copy of 'shell', an autocommand may change the option. */ | 704 /* Make a copy of 'shell', an autocommand may change the option. */ |
700 tofree = cmd = vim_strsave(p_sh); | 705 tofree = cmd = vim_strsave(p_sh); |
706 | |
707 /* default to close when the shell exits */ | |
708 if (opt.jo_term_finish == NUL) | |
709 opt.jo_term_finish = 'c'; | |
710 } | |
701 | 711 |
702 if (eap->addr_count > 0) | 712 if (eap->addr_count > 0) |
703 { | 713 { |
704 /* Write lines from current buffer to the job. */ | 714 /* Write lines from current buffer to the job. */ |
705 opt.jo_set |= JO_IN_IO | JO_IN_BUF | JO_IN_TOP | JO_IN_BOT; | 715 opt.jo_set |= JO_IN_IO | JO_IN_BUF | JO_IN_TOP | JO_IN_BOT; |
1533 * Move the vterm contents into the scrollback buffer and free the vterm. | 1543 * Move the vterm contents into the scrollback buffer and free the vterm. |
1534 */ | 1544 */ |
1535 static void | 1545 static void |
1536 cleanup_vterm(term_T *term) | 1546 cleanup_vterm(term_T *term) |
1537 { | 1547 { |
1538 if (term->tl_finish != 'c') | 1548 if (term->tl_finish != TL_FINISH_CLOSE) |
1539 move_terminal_to_buffer(term); | 1549 move_terminal_to_buffer(term); |
1540 term_free_vterm(term); | 1550 term_free_vterm(term); |
1541 set_terminal_mode(term, FALSE); | 1551 set_terminal_mode(term, FALSE); |
1542 } | 1552 } |
1543 | 1553 |
2601 { | 2611 { |
2602 int fnum = term->tl_buffer->b_fnum; | 2612 int fnum = term->tl_buffer->b_fnum; |
2603 | 2613 |
2604 cleanup_vterm(term); | 2614 cleanup_vterm(term); |
2605 | 2615 |
2606 if (term->tl_finish == 'c') | 2616 if (term->tl_finish == TL_FINISH_CLOSE) |
2607 { | 2617 { |
2608 aco_save_T aco; | 2618 aco_save_T aco; |
2609 | 2619 |
2610 /* ++close or term_finish == "close" */ | 2620 /* ++close or term_finish == "close" */ |
2611 ch_log(NULL, "terminal job finished, closing window"); | 2621 ch_log(NULL, "terminal job finished, closing window"); |
2612 aucmd_prepbuf(&aco, term->tl_buffer); | 2622 aucmd_prepbuf(&aco, term->tl_buffer); |
2613 do_bufdel(DOBUF_WIPE, (char_u *)"", 1, fnum, fnum, FALSE); | 2623 do_bufdel(DOBUF_WIPE, (char_u *)"", 1, fnum, fnum, FALSE); |
2614 aucmd_restbuf(&aco); | 2624 aucmd_restbuf(&aco); |
2615 break; | 2625 break; |
2616 } | 2626 } |
2617 if (term->tl_finish == 'o' && term->tl_buffer->b_nwindows == 0) | 2627 if (term->tl_finish == TL_FINISH_OPEN |
2628 && term->tl_buffer->b_nwindows == 0) | |
2618 { | 2629 { |
2619 char buf[50]; | 2630 char buf[50]; |
2620 | 2631 |
2621 /* TODO: use term_opencmd */ | 2632 /* TODO: use term_opencmd */ |
2622 ch_log(NULL, "terminal job finished, opening window"); | 2633 ch_log(NULL, "terminal job finished, opening window"); |