]> granicus.if.org Git - neomutt/commitdiff
Rework timeout handling to support keepalive in the line editor.
authorBrendan Cully <brendan@kublai.com>
Sun, 31 Aug 2008 02:59:42 +0000 (19:59 -0700)
committerBrendan Cully <brendan@kublai.com>
Sun, 31 Aug 2008 02:59:42 +0000 (19:59 -0700)
Also allow keepalives of less than $timeout without returning before
$timeout, so people who don't want to be notified of new mail don't
have to be.

curs_lib.c
enter.c
flags.c
keymap.c
menu.c

index e09570a90b4dcf534785e36d04aca5495597c13c..25d5aa680185050b0fadd45641d744e18a5f6b6f 100644 (file)
@@ -81,6 +81,7 @@ event_t mutt_getch (void)
 {
   int ch;
   event_t err = {-1, OP_NULL }, ret;
+  event_t timeout = {-2, OP_NULL};
 
   if (!option(OPTUNBUFFEREDINPUT) && UngetCount)
     return (KeyEvent[--UngetCount]);
@@ -107,7 +108,7 @@ event_t mutt_getch (void)
       endwin ();
       exit (1);
     }
-    return err;
+    return timeout;
   }
 
   if ((ch & 0x80) && option (OPTMETAKEY))
@@ -228,7 +229,7 @@ int mutt_yesorno (const char *msg, int def)
     ch = mutt_getch ();
     if (CI_is_return (ch.ch))
       break;
-    if (ch.ch == -1)
+    if (ch.ch < 0)
     {
       def = -1;
       break;
@@ -556,7 +557,7 @@ int _mutt_enter_fname (const char *prompt, char *buf, size_t blen, int *redraw,
   mutt_refresh ();
 
   ch = mutt_getch();
-  if (ch.ch == -1)
+  if (ch.ch < 0)
   {
     CLEARLINE (LINES-1);
     return (-1);
@@ -638,7 +639,7 @@ int mutt_multi_choice (char *prompt, char *letters)
   {
     mutt_refresh ();
     ch  = mutt_getch ();
-    if (ch.ch == -1 || CI_is_return (ch.ch))
+    if (ch.ch < 0 || CI_is_return (ch.ch))
     {
       choice = -1;
       break;
diff --git a/enter.c b/enter.c
index fc064d956ec96216ee9c1ca75c62728aa9509094..999b0b74c9617bc1b2ca90396ee51e54acb9c25f 100644 (file)
--- a/enter.c
+++ b/enter.c
@@ -603,7 +603,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x,
            event_t event;
            /*ADDCH (LastKey);*/
            event = mutt_getch ();
-           if (event.ch != -1)
+           if (event.ch >= 0)
            {
              LastKey = event.ch;
              goto self_insert;
diff --git a/flags.c b/flags.c
index 732eb0124eacdf6bdc7ac8615dd9dd7959c7cdc8..9465faf02c6c9dd5d98899aed2fbf6aeb31d3c5c 100644 (file)
--- a/flags.c
+++ b/flags.c
@@ -331,7 +331,7 @@ int mutt_change_flag (HEADER *h, int bf)
 
   event = mutt_getch();
   i = event.ch;
-  if (i == -1)
+  if (i < 0)
   {
     CLEARLINE (LINES-1);
     return (-1);
index 18084d226ffd08fff616e00bd5d47b40026a231c..5de29954e6c8bd87e3018515648022ce10902db0 100644 (file)
--- a/keymap.c
+++ b/keymap.c
@@ -387,25 +387,33 @@ int km_dokey (int menu)
 
   FOREVER
   {
-    /* ncurses doesn't return on resized screen when timeout is set to zero */
-    if (menu != MENU_EDITOR)
-    {
-      i = Timeout > 0 ? Timeout : 60;
+    i = Timeout > 0 ? Timeout : 60;
 #ifdef USE_IMAP
+    /* keepalive may need to run more frequently than Timeout allows */
+    while (ImapKeepalive && ImapKeepalive < i)
+    {
+      timeout (ImapKeepalive * 1000);
+      tmp = mutt_getch ();
+      timeout (-1);
+      if (tmp.ch != -2)
+        /* something other than timeout */
+        goto gotkey;
+      i -= ImapKeepalive;
       imap_keepalive ();
-      if (ImapKeepalive && ImapKeepalive < i)
-        i = ImapKeepalive;
-#endif
-      timeout (i * 1000);
     }
+#endif
 
+    timeout (i * 1000);
     tmp = mutt_getch();
+    timeout (-1);
 
-    if (menu != MENU_EDITOR)
-      timeout (-1); /* restore blocking operation */
+    /* hide timeouts from line editor */
+    if (menu == MENU_EDITOR && tmp.ch == -2)
+      continue;
 
+  gotkey:
     LastKey = tmp.ch;
-    if (LastKey == -1)
+    if (LastKey < 0)
       return -1;
 
     /* do we have an op already? */
diff --git a/menu.c b/menu.c
index 7195c90db184050d4f53ed30771c0171535f5aef..283296af487fa1babd65acdd3e5684950b6d6968 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -796,7 +796,7 @@ static int menu_dialog_dokey (MUTTMENU *menu, int *ip)
 
   ch = mutt_getch ();
 
-  if (ch.ch == -1)
+  if (ch.ch < 0)
   {
     *ip = -1;
     return 0;