diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-04-15 17:28:13 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-04-15 17:28:13 +0200 |
commit | 802bfb14636b24d86d0ca8e0947d808b9b7c941e (patch) | |
tree | 71797a10ea75ce5b3ab6de8b949de40517f92be1 /src/terminal.c | |
parent | e1a32310d5e9684608b893ab8295191d63178b4e (diff) | |
download | vim-git-802bfb14636b24d86d0ca8e0947d808b9b7c941e.tar.gz |
patch 8.0.1720: when a timer is running a terminal window may not closev8.0.1720
Problem: When a timer is running a terminal window may not close after a
shell has exited.
Solution: Call job_status() more often.
Diffstat (limited to 'src/terminal.c')
-rw-r--r-- | src/terminal.c | 83 |
1 files changed, 55 insertions, 28 deletions
diff --git a/src/terminal.c b/src/terminal.c index 93b6f9286..0d2dab8ab 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -40,17 +40,18 @@ * TODO: * - Win32: Make terminal used for :!cmd in the GUI work better. Allow for * redirection. Probably in call to channel_set_pipes(). + * - Win32: Redirecting output does not work, Test_terminal_redir_file() + * is disabled. * - Copy text in the vterm to the Vim buffer once in a while, so that * completion works. + * - When starting terminal window with shell in terminal, then using :gui to + * switch to GUI, shell stops working. Scrollback seems wrong, command + * running in shell is still running. * - in GUI vertical split causes problems. Cursor is flickering. (Hirohito * Higashi, 2017 Sep 19) * - after resizing windows overlap. (Boris Staletic, #2164) - * - Redirecting output does not work on MS-Windows, Test_terminal_redir_file() - * is disabled. * - cursor blinks in terminal on widows with a timer. (xtal8, #2142) * - Termdebug does not work when Vim build with mzscheme. gdb hangs. - * - MS-Windows GUI: WinBar has tearoff item - * - MS-Windows GUI: still need to type a key after shell exits? #1924 * - After executing a shell command the status line isn't redraw. * - add test for giving error for invalid 'termsize' value. * - support minimal size when 'termsize' is "rows*cols". @@ -59,7 +60,7 @@ * - Redrawing is slow with Athena and Motif. Also other GUI? (Ramel Eshed) * - For the GUI fill termios with default values, perhaps like pangoterm: * http://bazaar.launchpad.net/~leonerd/pangoterm/trunk/view/head:/main.c#L134 - * - when 'encoding' is not utf-8, or the job is using another encoding, setup + * - When 'encoding' is not utf-8, or the job is using another encoding, setup * conversions. */ @@ -1223,17 +1224,32 @@ term_convert_key(term_T *term, int c, char *buf) /* * Return TRUE if the job for "term" is still running. + * If "check_job_status" is TRUE update the job status. */ - int -term_job_running(term_T *term) + static int +term_job_running_check(term_T *term, int check_job_status) { /* Also consider the job finished when the channel is closed, to avoid a * race condition when updating the title. */ - return term != NULL + if (term != NULL && term->tl_job != NULL - && channel_is_open(term->tl_job->jv_channel) - && (term->tl_job->jv_status == JOB_STARTED + && channel_is_open(term->tl_job->jv_channel)) + { + if (check_job_status) + job_status(term->tl_job); + return (term->tl_job->jv_status == JOB_STARTED || term->tl_job->jv_channel->ch_keep_open); + } + return FALSE; +} + +/* + * Return TRUE if the job for "term" is still running. + */ + int +term_job_running(term_T *term) +{ + return term_job_running_check(term, FALSE); } /* @@ -1892,6 +1908,32 @@ prepare_restore_cursor_props(void) } /* + * Returns TRUE if the current window contains a terminal and we are sending + * keys to the job. + * If "check_job_status" is TRUE update the job status. + */ + static int +term_use_loop_check(int check_job_status) +{ + term_T *term = curbuf->b_term; + + return term != NULL + && !term->tl_normal_mode + && term->tl_vterm != NULL + && term_job_running_check(term, check_job_status); +} + +/* + * Returns TRUE if the current window contains a terminal and we are sending + * keys to the job. + */ + int +term_use_loop(void) +{ + return term_use_loop_check(FALSE); +} + +/* * Called when entering a window with the mouse. If this is a terminal window * we may want to change state. */ @@ -1902,7 +1944,7 @@ term_win_entered() if (term != NULL) { - if (term_use_loop()) + if (term_use_loop_check(TRUE)) { reset_VIsual_and_resel(); if (State & INSERT) @@ -1915,21 +1957,6 @@ term_win_entered() } /* - * Returns TRUE if the current window contains a terminal and we are sending - * keys to the job. - */ - int -term_use_loop(void) -{ - term_T *term = curbuf->b_term; - - return term != NULL - && !term->tl_normal_mode - && term->tl_vterm != NULL - && term_job_running(term); -} - -/* * Wait for input and send it to the job. * When "blocking" is TRUE wait for a character to be typed. Otherwise return * when there is no more typahead. @@ -1976,7 +2003,7 @@ terminal_loop(int blocking) restore_cursor = TRUE; c = term_vgetc(); - if (!term_use_loop()) + if (!term_use_loop_check(TRUE)) { /* Job finished while waiting for a character. Push back the * received character. */ @@ -2027,7 +2054,7 @@ terminal_loop(int blocking) #ifdef FEAT_CMDL_INFO clear_showcmd(); #endif - if (!term_use_loop()) + if (!term_use_loop_check(TRUE)) /* job finished while waiting for a character */ break; |