patch 8.0.0854: no redraw after terminal was closed

Problem:    No redraw after terminal was closed.
Solution:   Set typebuf_was_filled. (Yasuhiro Matsumoto, closes #1925, closes
            #1924)  Add function to check for messages even when input is
            available.
diff --git a/src/terminal.c b/src/terminal.c
index b06feff..9c16533 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -1305,6 +1305,7 @@
 
 	/* Need to break out of vgetc(). */
 	ins_char_typebuf(K_IGNORE);
+	typebuf_was_filled = TRUE;
 
 	term = curbuf->b_term;
 	if (term != NULL)
@@ -2140,31 +2141,36 @@
 	ch_log(NULL, "term_wait(): invalid argument");
 	return;
     }
+    if (buf->b_term->tl_job == NULL)
+    {
+	ch_log(NULL, "term_wait(): no job to wait for");
+	return;
+    }
 
     /* Get the job status, this will detect a job that finished. */
-    if (buf->b_term->tl_job == NULL
-	    || STRCMP(job_status(buf->b_term->tl_job), "dead") == 0)
+    if (STRCMP(job_status(buf->b_term->tl_job), "dead") == 0)
     {
 	/* The job is dead, keep reading channel I/O until the channel is
 	 * closed. */
+	ch_log(NULL, "term_wait(): waiting for channel to close");
 	while (buf->b_term != NULL && !buf->b_term->tl_channel_closed)
 	{
-	    mch_char_avail();
+	    mch_check_messages();
 	    parse_queued_messages();
 	    ui_delay(10L, FALSE);
 	}
-	mch_char_avail();
+	mch_check_messages();
 	parse_queued_messages();
     }
     else
     {
-	mch_char_avail();
+	mch_check_messages();
 	parse_queued_messages();
 
 	/* Wait for 10 msec for any channel I/O. */
 	/* TODO: use delay from optional argument */
 	ui_delay(10L, TRUE);
-	mch_char_avail();
+	mch_check_messages();
 
 	/* Flushing messages on channels is hopefully sufficient.
 	 * TODO: is there a better way? */