#endif
static pid_t wait4pid(pid_t, waitstatus *);
-static int WaitForChar(long msec, int *interrupted);
-static int WaitForCharOrMouse(long msec, int *interrupted);
+static int WaitForChar(long msec, int *interrupted, int ignore_input);
+static int WaitForCharOrMouse(long msec, int *interrupted, int ignore_input);
#if defined(__BEOS__) || defined(VMS)
int RealWaitForChar(int, long, int *, int *interrupted);
#else
* We want to be interrupted by the winch signal
* or by an event on the monitored file descriptors.
*/
- if (WaitForChar(wait_time, &interrupted))
+ if (WaitForChar(wait_time, &interrupted, FALSE))
{
/* If input was put directly in typeahead buffer bail out here. */
if (typebuf_changed(tb_change_cnt))
int
mch_char_avail(void)
{
- return WaitForChar(0L, NULL);
+ return WaitForChar(0L, NULL, FALSE);
}
+#if defined(FEAT_TERMINAL) || defined(PROTO)
+/*
+ * Check for any pending input or messages.
+ */
+ int
+mch_check_messages(void)
+{
+ return WaitForChar(0L, NULL, TRUE);
+}
+#endif
+
#if defined(HAVE_TOTAL_MEM) || defined(PROTO)
# ifdef HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
in_mch_delay = FALSE;
}
else
- WaitForChar(msec, NULL);
+ WaitForChar(msec, NULL, FALSE);
}
#if defined(HAVE_STACK_LIMIT) \
* from inbuf[].
* "msec" == -1 will block forever.
* Invokes timer callbacks when needed.
+ * When "ignore_input" is TRUE even check for pending input when input is
+ * already available.
* "interrupted" (if not NULL) is set to TRUE when no character is available
* but something else needs to be done.
* Returns TRUE when a character is available.
* When a GUI is being used, this will never get called -- webb
*/
static int
-WaitForChar(long msec, int *interrupted)
+WaitForChar(long msec, int *interrupted, int ignore_input)
{
#ifdef FEAT_TIMERS
long due_time;
/* When waiting very briefly don't trigger timers. */
if (msec >= 0 && msec < 10L)
- return WaitForCharOrMouse(msec, NULL);
+ return WaitForCharOrMouse(msec, NULL, ignore_input);
while (msec < 0 || remaining > 0)
{
}
if (due_time <= 0 || (msec > 0 && due_time > remaining))
due_time = remaining;
- if (WaitForCharOrMouse(due_time, interrupted))
+ if (WaitForCharOrMouse(due_time, interrupted, ignore_input))
return TRUE;
if (interrupted != NULL && *interrupted)
/* Nothing available, but need to return so that side effects get
}
return FALSE;
#else
- return WaitForCharOrMouse(msec, interrupted);
+ return WaitForCharOrMouse(msec, interrupted, ignore_input);
#endif
}
* Wait "msec" msec until a character is available from the mouse or keyboard
* or from inbuf[].
* "msec" == -1 will block forever.
+ * for "ignore_input" see WaitForCharOr().
* "interrupted" (if not NULL) is set to TRUE when no character is available
* but something else needs to be done.
* When a GUI is being used, this will never get called -- webb
*/
static int
-WaitForCharOrMouse(long msec, int *interrupted)
+WaitForCharOrMouse(long msec, int *interrupted, int ignore_input)
{
#ifdef FEAT_MOUSE_GPM
int gpm_process_wanted;
#endif
int avail;
- if (input_available()) /* something in inbuf[] */
+ if (!ignore_input && input_available()) /* something in inbuf[] */
return 1;
#if defined(FEAT_MOUSE_DEC)
# endif
if (!avail)
{
- if (input_available())
+ if (!ignore_input && input_available())
return 1;
# ifdef FEAT_XCLIPBOARD
if (rest == 0 || !do_xterm_trace())
/*
* Wait until console input from keyboard or mouse is available,
* or the time is up.
+ * When "ignore_input" is TRUE even wait when input is available.
* Return TRUE if something is available FALSE if not.
*/
static int
-WaitForChar(long msec)
+WaitForChar(long msec, int ignore_input)
{
DWORD dwNow = 0, dwEndTime = 0;
INPUT_RECORD ir;
|| g_nMouseClick != -1
#endif
#ifdef FEAT_CLIENTSERVER
- || input_available()
+ || (!ignore_input && input_available())
#endif
)
return TRUE;
int
mch_char_avail(void)
{
- return WaitForChar(0L);
+ return WaitForChar(0L, FALSE);
}
+
+# if defined(FEAT_TERMINAL) || defined(PROTO)
+/*
+ * Check for any pending input or messages.
+ */
+ int
+mch_check_messages(void)
+{
+ return WaitForChar(0L, TRUE);
+}
+# endif
#endif
/*
DWORD cRecords = 0;
#ifdef FEAT_CLIENTSERVER
- (void)WaitForChar(-1L);
+ (void)WaitForChar(-1L, FALSE);
if (input_available())
return 0;
# ifdef FEAT_MOUSE
if (time >= 0)
{
- if (!WaitForChar(time)) /* no character available */
+ if (!WaitForChar(time, FALSE)) /* no character available */
return 0;
}
else /* time == -1, wait forever */
* write the autoscript file to disk. Or cause the CursorHold event
* to be triggered.
*/
- if (!WaitForChar(p_ut))
+ if (!WaitForChar(p_ut, FALSE))
{
#ifdef FEAT_AUTOCMD
if (trigger_cursorhold() && maxlen >= 3)
/* Keep looping until there is something in the typeahead buffer and more
* to get and still room in the buffer (up to two bytes for a char and
* three bytes for a modifier). */
- while ((typeaheadlen == 0 || WaitForChar(0L))
+ while ((typeaheadlen == 0 || WaitForChar(0L, FALSE))
&& typeaheadlen + 5 <= TYPEAHEADLEN)
{
if (typebuf_changed(tb_change_cnt))
/*
- * write `cbToWrite' bytes in `pchBuf' to the screen
+ * Write "cbToWrite" bytes in `pchBuf' to the screen.
* Returns the number of bytes actually written (at least one).
*/
static DWORD
if (p_wd)
{
- WaitForChar(p_wd);
+ WaitForChar(p_wd, FALSE);
if (prefix != 0)
prefix = 1;
}
# endif
Sleep((int)msec);
else
- WaitForChar(msec);
+ WaitForChar(msec, FALSE);
#endif
}
/* Need to break out of vgetc(). */
ins_char_typebuf(K_IGNORE);
+ typebuf_was_filled = TRUE;
term = curbuf->b_term;
if (term != NULL)
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? */