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.
diff --git a/src/terminal.c b/src/terminal.c
index 67972f1..60d0098 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -38,8 +38,6 @@
  * 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.
@@ -123,7 +121,11 @@
 
     int		tl_normal_mode; /* TRUE: Terminal-Normal mode */
     int		tl_channel_closed;
-    int		tl_finish;	/* 'c' for ++close, 'o' for ++open */
+    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,6 +645,8 @@
 
 	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,9 +700,15 @@
 	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,7 +1545,7 @@
     static void
 cleanup_vterm(term_T *term)
 {
-    if (term->tl_finish != 'c')
+    if (term->tl_finish != TL_FINISH_CLOSE)
 	move_terminal_to_buffer(term);
     term_free_vterm(term);
     set_terminal_mode(term, FALSE);
@@ -2603,7 +2613,7 @@
 
 		cleanup_vterm(term);
 
-		if (term->tl_finish == 'c')
+		if (term->tl_finish == TL_FINISH_CLOSE)
 		{
 		    aco_save_T	aco;
 
@@ -2614,7 +2624,8 @@
 		    aucmd_restbuf(&aco);
 		    break;
 		}
-		if (term->tl_finish == 'o' && term->tl_buffer->b_nwindows == 0)
+		if (term->tl_finish == TL_FINISH_OPEN
+					   && term->tl_buffer->b_nwindows == 0)
 		{
 		    char buf[50];
 
diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim
index 9ac0f27..58737ed 100644
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -367,6 +367,26 @@
 
   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
diff --git a/src/version.c b/src/version.c
index 6ab5963..a588344 100644
--- a/src/version.c
+++ b/src/version.c
@@ -767,6 +767,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1612,
+/**/
     1611,
 /**/
     1610,