From 244feeb67478582fbf5597f25aaa9723e786d18a Mon Sep 17 00:00:00 2001 From: Brendan Cully Date: Sat, 30 Aug 2008 19:59:42 -0700 Subject: [PATCH] Rework timeout handling to support keepalive in the line editor. 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 | 9 +++++---- enter.c | 2 +- flags.c | 2 +- keymap.c | 30 +++++++++++++++++++----------- menu.c | 2 +- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/curs_lib.c b/curs_lib.c index e09570a9..25d5aa68 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -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 fc064d95..999b0b74 100644 --- 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 732eb012..9465faf0 100644 --- 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); diff --git a/keymap.c b/keymap.c index 18084d22..5de29954 100644 --- 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 7195c90d..283296af 100644 --- 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; -- 2.40.0