]> granicus.if.org Git - neomutt/commitdiff
Quick fix for ncurses buffering issue with inotify polling.
authorKevin McCarthy <kevin@8t8.us>
Wed, 6 Jun 2018 00:38:44 +0000 (17:38 -0700)
committerRichard Russon <rich@flatcap.org>
Mon, 3 Sep 2018 01:04:32 +0000 (02:04 +0100)
Ncurses does its own buffering for some character sequences, notable
Esc-prefixed input.  Add a non-blocking check for getch() before
performing the mutt_monitor_poll() call.

This is a quick fix, which I'll clean up more later.

curs_lib.c
monitor.c
monitor.h

index 63ab60f38433fe68dd638b36607500c670bb0b65..f1c0943e748111b619f3a55580d28548649ec885 100644 (file)
@@ -132,6 +132,25 @@ void mutt_getch_timeout(int delay)
 #endif
 }
 
+#ifdef USE_INOTIFY
+static int mutt_monitor_getch(void)
+{
+  /* ncurses has its own internal buffer, so before we perform a poll,
+   * we need to make sure there isn't a character waiting */
+  timeout(0);
+  int ch = getch();
+  timeout(mutt_monitor_get_poll_timeout());
+  if (ch == ERR)
+  {
+    if (mutt_monitor_poll() != 0)
+      ch = ERR;
+    else
+      ch = getch();
+  }
+  return ch;
+}
+#endif /* USE_INOTIFY */
+
 /**
  * mutt_getch - Read a character from the input buffer
  * @retval obj Event to process
@@ -166,11 +185,10 @@ struct Event mutt_getch(void)
   while (ch == KEY_RESIZE)
 #endif /* KEY_RESIZE */
 #ifdef USE_INOTIFY
-    if (mutt_monitor_poll() != 0)
-      ch = ERR;
-    else
-#endif
-      ch = getch();
+    ch = mutt_monitor_getch();
+#else
+  ch = getch();
+#endif /* USE_INOTIFY */
   mutt_sig_allow_interrupt(0);
 
   if (SigInt)
index 30019cd6b4069c4e4e184c76a809e65f3eef94f5..2e9d3c67b3651b895f2e5057659f0fbe48409e5d 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -219,6 +219,11 @@ void mutt_monitor_set_poll_timeout(int timeout)
   PollTimeout = timeout;
 }
 
+int mutt_monitor_get_poll_timeout(void)
+{
+  return PollTimeout;
+}
+
 #define EVENT_BUFLEN MAX(4096, sizeof(struct inotify_event) + NAME_MAX + 1)
 
 /* mutt_monitor_poll: Waits for I/O ready file descriptors or signals.
index d61550b051bf1c96bb168e2ef14196d9e8b17780..4d76ca001fe5d3ca4e97195fd4dc247844e693a4 100644 (file)
--- a/monitor.h
+++ b/monitor.h
@@ -30,6 +30,7 @@ struct Mailbox;
 int mutt_monitor_add(struct Mailbox *b);
 int mutt_monitor_remove(struct Mailbox *b);
 void mutt_monitor_set_poll_timeout(int timeout);
+int mutt_monitor_get_poll_timeout(void);
 int mutt_monitor_poll(void);
 
 #endif /* _MUTT_MONITOR_H */