Skip to content

Commit 802bfb1

Browse files
committed
patch 8.0.1720: when a timer is running a terminal window may not close
Problem: When a timer is running a terminal window may not close after a shell has exited. Solution: Call job_status() more often.
1 parent e1a3231 commit 802bfb1

File tree

2 files changed

+57
-28
lines changed

2 files changed

+57
-28
lines changed

src/terminal.c

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,18 @@
4040
* TODO:
4141
* - Win32: Make terminal used for :!cmd in the GUI work better. Allow for
4242
* redirection. Probably in call to channel_set_pipes().
43+
* - Win32: Redirecting output does not work, Test_terminal_redir_file()
44+
* is disabled.
4345
* - Copy text in the vterm to the Vim buffer once in a while, so that
4446
* completion works.
47+
* - When starting terminal window with shell in terminal, then using :gui to
48+
* switch to GUI, shell stops working. Scrollback seems wrong, command
49+
* running in shell is still running.
4550
* - in GUI vertical split causes problems. Cursor is flickering. (Hirohito
4651
* Higashi, 2017 Sep 19)
4752
* - after resizing windows overlap. (Boris Staletic, #2164)
48-
* - Redirecting output does not work on MS-Windows, Test_terminal_redir_file()
49-
* is disabled.
5053
* - cursor blinks in terminal on widows with a timer. (xtal8, #2142)
5154
* - Termdebug does not work when Vim build with mzscheme. gdb hangs.
52-
* - MS-Windows GUI: WinBar has tearoff item
53-
* - MS-Windows GUI: still need to type a key after shell exits? #1924
5455
* - After executing a shell command the status line isn't redraw.
5556
* - add test for giving error for invalid 'termsize' value.
5657
* - support minimal size when 'termsize' is "rows*cols".
@@ -59,7 +60,7 @@
5960
* - Redrawing is slow with Athena and Motif. Also other GUI? (Ramel Eshed)
6061
* - For the GUI fill termios with default values, perhaps like pangoterm:
6162
* http://bazaar.launchpad.net/~leonerd/pangoterm/trunk/view/head:/main.c#L134
62-
* - when 'encoding' is not utf-8, or the job is using another encoding, setup
63+
* - When 'encoding' is not utf-8, or the job is using another encoding, setup
6364
* conversions.
6465
*/
6566

@@ -1223,17 +1224,32 @@ term_convert_key(term_T *term, int c, char *buf)
12231224

12241225
/*
12251226
* Return TRUE if the job for "term" is still running.
1227+
* If "check_job_status" is TRUE update the job status.
12261228
*/
1227-
int
1228-
term_job_running(term_T *term)
1229+
static int
1230+
term_job_running_check(term_T *term, int check_job_status)
12291231
{
12301232
/* Also consider the job finished when the channel is closed, to avoid a
12311233
* race condition when updating the title. */
1232-
return term != NULL
1234+
if (term != NULL
12331235
&& term->tl_job != NULL
1234-
&& channel_is_open(term->tl_job->jv_channel)
1235-
&& (term->tl_job->jv_status == JOB_STARTED
1236+
&& channel_is_open(term->tl_job->jv_channel))
1237+
{
1238+
if (check_job_status)
1239+
job_status(term->tl_job);
1240+
return (term->tl_job->jv_status == JOB_STARTED
12361241
|| term->tl_job->jv_channel->ch_keep_open);
1242+
}
1243+
return FALSE;
1244+
}
1245+
1246+
/*
1247+
* Return TRUE if the job for "term" is still running.
1248+
*/
1249+
int
1250+
term_job_running(term_T *term)
1251+
{
1252+
return term_job_running_check(term, FALSE);
12371253
}
12381254

12391255
/*
@@ -1891,6 +1907,32 @@ prepare_restore_cursor_props(void)
18911907
may_output_cursor_props();
18921908
}
18931909

1910+
/*
1911+
* Returns TRUE if the current window contains a terminal and we are sending
1912+
* keys to the job.
1913+
* If "check_job_status" is TRUE update the job status.
1914+
*/
1915+
static int
1916+
term_use_loop_check(int check_job_status)
1917+
{
1918+
term_T *term = curbuf->b_term;
1919+
1920+
return term != NULL
1921+
&& !term->tl_normal_mode
1922+
&& term->tl_vterm != NULL
1923+
&& term_job_running_check(term, check_job_status);
1924+
}
1925+
1926+
/*
1927+
* Returns TRUE if the current window contains a terminal and we are sending
1928+
* keys to the job.
1929+
*/
1930+
int
1931+
term_use_loop(void)
1932+
{
1933+
return term_use_loop_check(FALSE);
1934+
}
1935+
18941936
/*
18951937
* Called when entering a window with the mouse. If this is a terminal window
18961938
* we may want to change state.
@@ -1902,7 +1944,7 @@ term_win_entered()
19021944

19031945
if (term != NULL)
19041946
{
1905-
if (term_use_loop())
1947+
if (term_use_loop_check(TRUE))
19061948
{
19071949
reset_VIsual_and_resel();
19081950
if (State & INSERT)
@@ -1914,21 +1956,6 @@ term_win_entered()
19141956
}
19151957
}
19161958

1917-
/*
1918-
* Returns TRUE if the current window contains a terminal and we are sending
1919-
* keys to the job.
1920-
*/
1921-
int
1922-
term_use_loop(void)
1923-
{
1924-
term_T *term = curbuf->b_term;
1925-
1926-
return term != NULL
1927-
&& !term->tl_normal_mode
1928-
&& term->tl_vterm != NULL
1929-
&& term_job_running(term);
1930-
}
1931-
19321959
/*
19331960
* Wait for input and send it to the job.
19341961
* When "blocking" is TRUE wait for a character to be typed. Otherwise return
@@ -1976,7 +2003,7 @@ terminal_loop(int blocking)
19762003
restore_cursor = TRUE;
19772004

19782005
c = term_vgetc();
1979-
if (!term_use_loop())
2006+
if (!term_use_loop_check(TRUE))
19802007
{
19812008
/* Job finished while waiting for a character. Push back the
19822009
* received character. */
@@ -2027,7 +2054,7 @@ terminal_loop(int blocking)
20272054
#ifdef FEAT_CMDL_INFO
20282055
clear_showcmd();
20292056
#endif
2030-
if (!term_use_loop())
2057+
if (!term_use_loop_check(TRUE))
20312058
/* job finished while waiting for a character */
20322059
break;
20332060

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,8 @@ static char *(features[]) =
762762

763763
static int included_patches[] =
764764
{ /* Add new patch number below this line */
765+
/**/
766+
1720,
765767
/**/
766768
1719,
767769
/**/

0 commit comments

Comments
 (0)