X-Git-Url: https://git.llucax.com/software/mutt-debian.git/blobdiff_plain/14c29200cb58d3c4a0830265f2433849781858d0..1f4d55392f3d7e8b03c8c0cee62a38c58650458e:/keymap.c?ds=inline diff --git a/keymap.c b/keymap.c index ca23443..70765b1 100644 --- a/keymap.c +++ b/keymap.c @@ -26,6 +26,9 @@ #include "keymap.h" #include "mapping.h" #include "mutt_crypt.h" +#ifdef USE_IMAP +#include "imap/imap.h" +#endif #include #include @@ -44,7 +47,7 @@ struct mapping_t Menus[] = { { "postpone", MENU_POST }, { "pgp", MENU_PGP }, { "smime", MENU_SMIME }, -#ifdef HAVE_GPGME +#ifdef CRYPT_BACKEND_GPGME { "key_select_pgp", MENU_KEY_SELECT_PGP }, { "key_select_smime", MENU_KEY_SELECT_SMIME }, #endif @@ -86,6 +89,39 @@ static struct mapping_t KeyNames[] = { #ifdef KEY_NEXT { "", KEY_NEXT }, #endif +#ifdef NCURSES_VERSION + /* extensions supported by ncurses. values are filled in during initialization */ + + /* CTRL+key */ + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + + /* SHIFT+key */ + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + + /* ALT+key */ + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, + { "", -1 }, +#endif /* NCURSES_VERSION */ { NULL, 0 } }; @@ -131,17 +167,19 @@ static int parse_fkey(char *s) */ static int parse_keycode (const char *s) { - if (isdigit ((unsigned char) s[1]) && - isdigit ((unsigned char) s[2]) && - isdigit ((unsigned char) s[3]) && - s[4] == '>') - { - return (s[3] - '0') + (s[2] - '0') * 8 + (s[1] - '0') * 64; - } - return -1; + const char *endChar; + long int result = strtol(s+1, &endChar, 8); + /* allow trailing whitespace, eg. < 1001 > */ + while (ISSPACE(*endChar)) + ++endChar; + /* negative keycodes don't make sense, also detect overflow */ + if (*endChar != '>' || result < 0 || result == LONG_MAX) { + return -1; + } + return result; } -static int parsekeys (char *str, keycode_t *d, int max) +static int parsekeys (const char *str, keycode_t *d, int max) { int n, len = max; char buff[SHORT_STRING]; @@ -384,17 +422,39 @@ int km_dokey (int menu) FOREVER { - /* ncurses doesn't return on resized screen when timeout is set to zero */ - if (menu != MENU_EDITOR) - timeout ((Timeout > 0 ? Timeout : 60) * 1000); + i = Timeout > 0 ? Timeout : 60; +#ifdef USE_IMAP + /* keepalive may need to run more frequently than Timeout allows */ + if (ImapKeepalive) + { + if (ImapKeepalive >= i) + imap_keepalive (); + else + 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 (); + } + } +#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? */ @@ -548,6 +608,97 @@ struct keymap_t *km_find_func (int menu, int func) return (map); } +#ifdef NCURSES_VERSION +struct extkey { + const char *name; + const char *sym; +}; + +static const struct extkey ExtKeys[] = { + { "", "kUP5" }, + { "", "kUP" }, + { "", "kUP3" }, + + { "", "kDN" }, + { "", "kDN3" }, + { "", "kDN5" }, + + { "", "kRIT5" }, + { "", "kRIT" }, + { "", "kRIT3" }, + + { "", "kLFT" }, + { "", "kLFT3" }, + { "", "kLFT5" }, + + { "", "kHOM" }, + { "", "kHOM3" }, + { "", "kHOM5" }, + + { "", "kEND" }, + { "", "kEND3" }, + { "", "kEND5" }, + + { "", "kNXT" }, + { "", "kNXT3" }, + { "", "kNXT5" }, + + { "", "kPRV" }, + { "", "kPRV3" }, + { "", "kPRV5" }, + + { 0, 0 } +}; + +/* Look up Mutt's name for a key and find the ncurses extended name for it */ +static const char *find_ext_name(const char *key) +{ + int j; + + for (j = 0; ExtKeys[j].name; ++j) + { + if (strcasecmp(key, ExtKeys[j].name) == 0) + return ExtKeys[j].sym; + } + return 0; +} +#endif /* NCURSES_VERSION */ + +/* Determine the keycodes for ncurses extended keys and fill in the KeyNames array. + * + * This function must be called *after* initscr(), or tigetstr() returns -1. This + * creates a bit of a chicken-and-egg problem because km_init() is called prior to + * start_curses(). This means that the default keybindings can't include any of the + * extended keys because they won't be defined until later. + */ +void init_extended_keys(void) +{ +#ifdef NCURSES_VERSION + int j; + + use_extended_names(TRUE); + + for (j = 0; KeyNames[j].name; ++j) + { + if (KeyNames[j].value == -1) + { + const char *keyname = find_ext_name(KeyNames[j].name); + + if (keyname) + { + char *s = tigetstr(keyname); + if (s && (long)(s) != -1) + { + int code = key_defined(s); + if (code > 0) + KeyNames[j].value = code; + } + } + } + } +#endif +} + void km_init (void) { memset (Keymaps, 0, sizeof (struct keymap_t *) * MENU_MAX); @@ -975,4 +1126,5 @@ void mutt_what_key (void) while (ch != ERR && ch != ctrl ('G')); mutt_flushinp(); + mutt_clear_error(); }