From 2980e2bac0e9855349675bfd904c7c983fdbea85 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 25 Jun 2007 21:51:59 +0200 Subject: [PATCH] Mailboxes can be assigned hotkeys. --- cm.c | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/cm.c b/cm.c index a3bba18..0b7fbf1 100644 --- a/cm.c +++ b/cm.c @@ -39,6 +39,7 @@ struct options { int show_flagged; int sender_personal; int sender_mbox; + int hotkey; }; struct option_node { @@ -121,6 +122,7 @@ init_options(struct options *o) o->show_flagged = -1; o->sender_personal = -1; o->sender_mbox = -1; + o->hotkey = -1; } static void @@ -141,6 +143,7 @@ setup_options(struct mbox *b) MERGE(show_flagged); MERGE(sender_personal); MERGE(sender_mbox); + MERGE(hotkey); } } @@ -549,7 +552,9 @@ redraw_line(int i) int hi = b->o.highlight; attrset(attrs[cc][hi][M_IDLE]); - if (cc) + if (b->o.hotkey) + printw("%c ", b->o.hotkey); + else if (cc) printw("> "); else printw(" "); @@ -781,6 +786,20 @@ next_active(int since, int step) move_cursor(besti); } +static void +mbox_run(struct mbox *b) +{ + char cmd[strlen(run_cmd) + strlen(b->path) + 16]; + sprintf(cmd, run_cmd, b->path); + term_cleanup(); + system(cmd); + term_init(); + redraw_all(); + refresh(); + b->force_refresh = 1; + scan_and_redraw(); +} + #define STR2(c) #c #define STR(c) STR2(c) @@ -808,6 +827,7 @@ m\t\t\tShow mailbox name of the sender\n\ p\t\t\tShow personal info (full name) of the sender\n\ s\t\t\tShow message snippets\n\ t\t\t\tHighlight the entry\n\ +!\t\t\tSet hot key\n\ \n\ CheckMail " STR(VERSION) ", (c) " STR(YEAR) " Martin Mares \n\ It can be freely distributed and used according to the GNU GPL v2.\n\ @@ -837,6 +857,8 @@ parse_options(char *c) while (x = *c++) if (x >= '0' && x <= '9') o->priority = x - '0'; + else if (x == '!' && *c) + o->hotkey = *c++; else { int value = !!islower(x); @@ -916,6 +938,7 @@ main(int argc, char **argv) next_active(0, 1); int should_exit = 0; +restart: while (!should_exit) { time_t now = time(NULL); @@ -927,6 +950,14 @@ main(int argc, char **argv) remains *= 10; halfdelay((remains > 255) ? 255 : remains); int ch = getch(); + for (int i=0; io.hotkey) + { + if (i < cursor_max) + cursor_at = i; + mbox_run(mbox_array[i]); + goto restart; + } switch (ch) { case 'q': @@ -959,18 +990,7 @@ main(int argc, char **argv) case '\r': case '\n': if (cursor_at < cursor_max) - { - struct mbox *b = mbox_array[cursor_at]; - char cmd[strlen(run_cmd) + strlen(b->path) + 16]; - sprintf(cmd, run_cmd, b->path); - term_cleanup(); - system(cmd); - term_init(); - redraw_all(); - refresh(); - b->force_refresh = 1; - scan_and_redraw(); - } + mbox_run(mbox_array[cursor_at]); break; case 'l' & 0x1f: clearok(stdscr, TRUE); -- 2.39.2