/* this is the main key processing loop for interactive mode */ void display_results_interactively() { bool_t done = 0; int c, c1; /* set up the terminal etc. */ SLang_init_tty(-1, 0, 0); SLtt_get_terminfo(); if(-1 == SLsmg_init_smg() ) { fprintf (stderr, "Unable to initialize terminal."); return; } SLkp_init(); /* for cursor keys */ SLsignal(SIGWINCH, sigwinch_handler); init_disp_state(); while(!done) { redraw_current_state(); c = SLang_getkey(); /* if it's a meta combination, translate */ if( c == '' ) { c1 = SLang_getkey(); switch(c1) { case '<': c = SL_KEY_HOME; break; case '>': c = SL_KEY_END; break; case 'v': case 'V': c = SL_KEY_PPAGE; break; case 'r': case 'R': c = '?'; break; case 's': case 'S': c = '/'; break; default: /* could be special cursor keys */ SLang_ungetkey(c1); SLang_ungetkey(c); c = SLkp_getkey(); } } /* handle key press */ switch(c) { case 'q': case 'Q': done = 1; break; case 'c': interactive_categorize(); disp.highlighted = disp.first_visible = 0; break; case '\r': case 'v': if( emails.num_limited > 0 ) { view_current_email(); } break; case SL_KEY_F(1): if( emails.num_limited > 0 && disp.fkey_cmd[0] ) { interactive_pipe_all_tagged(disp.fkey_cmd[0]); } break; case SL_KEY_F(2): if( emails.num_limited > 0 && disp.fkey_cmd[1] ) { interactive_pipe_all_tagged(disp.fkey_cmd[1]); } break; case SL_KEY_F(3): if( emails.num_limited > 0 && disp.fkey_cmd[2] ) { interactive_pipe_all_tagged(disp.fkey_cmd[2]); } break; case SL_KEY_F(4): if( emails.num_limited > 0 && disp.fkey_cmd[3] ) { interactive_pipe_all_tagged(disp.fkey_cmd[3]); } break; case SL_KEY_F(5): if( emails.num_limited > 0 && disp.fkey_cmd[4] ) { interactive_pipe_all_tagged(disp.fkey_cmd[4]); } break; case SL_KEY_F(6): if( emails.num_limited > 0 && disp.fkey_cmd[5] ) { interactive_pipe_all_tagged(disp.fkey_cmd[5]); } break; case SL_KEY_F(7): if( emails.num_limited > 0 && disp.fkey_cmd[6] ) { interactive_pipe_all_tagged(disp.fkey_cmd[6]); } break; case SL_KEY_F(8): if( emails.num_limited > 0 && disp.fkey_cmd[7] ) { interactive_pipe_all_tagged(disp.fkey_cmd[7]); } break; case SL_KEY_F(9): if( emails.num_limited > 0 && disp.fkey_cmd[8] ) { interactive_pipe_all_tagged(disp.fkey_cmd[8]); } break; case SL_KEY_F(10): if( emails.num_limited > 0 && disp.fkey_cmd[9] ) { interactive_pipe_all_tagged(disp.fkey_cmd[9]); } break; case 's': if( emails.num_limited > 0 ) { interactive_pipe_current(""); } break; case 'S': if( emails.num_limited > 0 ) { interactive_pipe_all_tagged(""); } break; case 'o': if( ++emails.score_type >= MAX_SCORES ) { emails.score_type = 0; } qsort(emails.list, emails.num_emails, sizeof(mbox_item), compare_scores); recalculate_limited(); break; case 'p': if( ++emails.index_format >= MAX_FORMATS ) { emails.index_format = 0; } break; case 't': if( emails.num_limited > 0 ) { tag_current(1); } break; case 'T': if( emails.num_limited > 0 ) { tag_all_limited(1); } break; case 'u': if( emails.num_limited > 0 ) { tag_current(0); } break; case 'U': if( emails.num_limited > 0 ) { tag_all_limited(0); } break; case 'z': reverse_sort(); recalculate_limited(); break; case 'G': case SL_KEY_END: if( emails.num_limited > 0 ) { disp.first_visible = emails.num_limited - 1; } else { disp.highlighted = disp.first_visible = 0; } break; case '1': case SL_KEY_HOME: disp.first_visible = 0; break; case '': case SL_KEY_PPAGE: if( disp.first_visible > disp.num_rows ) { disp.first_visible -= disp.num_rows; } else { disp.first_visible = 0; disp.highlighted = 0; } /* assert emails.num_limited >= disp.first_visible */ if( disp.highlighted > (emails.num_limited - disp.first_visible) ) { disp.highlighted = (emails.num_limited - disp.first_visible); } break; case 'k': case '': case SL_KEY_UP: if( disp.highlighted > 0 ) { disp.highlighted--; } else { if( disp.first_visible > 1 ) { disp.first_visible -= 1; } else { disp.first_visible = 0; } } break; case 'j': case '': case SL_KEY_DOWN: if( emails.num_limited > 0 ) { if( disp.highlighted < (emails.num_limited - disp.first_visible - 1) ) { if( disp.highlighted < (disp.num_rows - 3) ) { disp.highlighted++; } else { if( (disp.first_visible += 1) >= emails.num_limited ) { disp.first_visible = emails.num_limited - 1; } } } } else { disp.highlighted = disp.first_visible = 0; } break; case '': case '': case ' ': case SL_KEY_NPAGE: if( emails.num_limited > 0 ) { if( (disp.first_visible += disp.num_rows) >= emails.num_limited ) { disp.first_visible = emails.num_limited - 1; } if( disp.highlighted > (emails.num_limited - disp.first_visible) ) { disp.highlighted = (emails.num_limited - disp.first_visible) - 1; } } else { disp.highlighted = disp.first_visible = 0; } break; case '?': interactive_search(0, ""); disp.highlighted = disp.first_visible = 0; break; case '/': interactive_search(1, ""); disp.highlighted = disp.first_visible = 0; break; default: break; } } /* we're done */ SLsmg_reset_smg(); SLang_reset_tty(); }
{ SL_KEY_ALT( 'w' ), K_ALT_W }, { SL_KEY_ALT( 'x' ), K_ALT_X }, { SL_KEY_ALT( 'y' ), K_ALT_Y }, { SL_KEY_ALT( 'z' ), K_ALT_Z }, { SL_KEY_ALT( '0' ), K_ALT_0 }, { SL_KEY_ALT( '1' ), K_ALT_1 }, { SL_KEY_ALT( '2' ), K_ALT_2 }, { SL_KEY_ALT( '3' ), K_ALT_3 }, { SL_KEY_ALT( '4' ), K_ALT_4 }, { SL_KEY_ALT( '5' ), K_ALT_5 }, { SL_KEY_ALT( '6' ), K_ALT_6 }, { SL_KEY_ALT( '7' ), K_ALT_7 }, { SL_KEY_ALT( '8' ), K_ALT_8 }, { SL_KEY_ALT( '9' ), K_ALT_9 }, { SL_KEY_F(1), K_F1 }, { SL_KEY_F(2), K_F2 }, { SL_KEY_F(3), K_F3 }, { SL_KEY_F(4), K_F4 }, { SL_KEY_F(5), K_F5 }, { SL_KEY_F(6), K_F6 }, { SL_KEY_F(7), K_F7 }, { SL_KEY_F(8), K_F8 }, { SL_KEY_F(9), K_F9 }, { SL_KEY_F(10), K_F10 }, { SL_KEY_F(11), K_SH_F1 }, { SL_KEY_F(12), K_SH_F2 }, { SL_KEY_F(13), K_SH_F3 }, { SL_KEY_F(14), K_SH_F4 }, { SL_KEY_F(15), K_SH_F5 },
static int slang_get_event(caca_display_t *dp, caca_privevent_t *ev) { int intkey; /* If SIGINT was caught, we pass it to the application as Ctrl-C. */ if(dp->drv.p->sigint_event > 0) { ev->type = CACA_EVENT_KEY_PRESS; ev->data.key.ch = CACA_KEY_CTRL_C; ev->data.key.utf32 = 0x03; ev->data.key.utf8[0] = 0x03; ev->data.key.utf8[1] = 0; dp->drv.p->sigint_event--; return 1; } if(!SLang_input_pending(0)) { ev->type = CACA_EVENT_NONE; return 0; } /* We first use SLang_getkey() to see whether Esc was pressed * alone, then (if it wasn't) we unget the key and use SLkp_getkey() * instead, so that escape sequences are interpreted. */ intkey = SLang_getkey(); if(intkey != 0x1b /* Esc */ || SLang_input_pending(0)) { SLang_ungetkey(intkey); intkey = SLkp_getkey(); } /* If the key was ASCII, return it immediately */ if(intkey < 0x7f) { ev->type = CACA_EVENT_KEY_PRESS; ev->data.key.ch = intkey; ev->data.key.utf32 = intkey; ev->data.key.utf8[0] = intkey; ev->data.key.utf8[1] = '\0'; return 1; } /* If the key was UTF-8, parse the whole sequence */ if(intkey >= 0x80 && intkey < 0x100) { int keys[7]; /* Necessary for ungetkey(); */ char utf8[7]; uint32_t utf32; size_t i, bytes = 0; keys[0] = intkey; utf8[0] = intkey; for(i = 1; i < 6; i++) { if(!SLang_input_pending(0)) break; keys[i] = SLang_getkey(); utf8[i] = (unsigned char)keys[i]; } utf8[i] = '\0'; utf32 = caca_utf8_to_utf32(utf8, &bytes); while(i > bytes) SLang_ungetkey(keys[--i]); if(bytes) { ev->type = CACA_EVENT_KEY_PRESS; ev->data.key.ch = 0; ev->data.key.utf32 = utf32; strcpy(ev->data.key.utf8, utf8); return 1; } } if(intkey == 0x3e9) { int button = (SLang_getkey() - ' ' + 1) & 0xf; int x = SLang_getkey() - '!'; int y = SLang_getkey() - '!'; ev->data.mouse.button = button; ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); if(dp->mouse.x == x && dp->mouse.y == y) return _pop_event(dp, ev); dp->mouse.x = x; dp->mouse.y = y; ev->type = CACA_EVENT_MOUSE_MOTION; ev->data.mouse.x = dp->mouse.x; ev->data.mouse.y = dp->mouse.y; return 1; } switch(intkey) { case SL_KEY_UP: ev->data.key.ch = CACA_KEY_UP; break; case SL_KEY_DOWN: ev->data.key.ch = CACA_KEY_DOWN; break; case SL_KEY_LEFT: ev->data.key.ch = CACA_KEY_LEFT; break; case SL_KEY_RIGHT: ev->data.key.ch = CACA_KEY_RIGHT; break; case SL_KEY_IC: ev->data.key.ch = CACA_KEY_INSERT; break; case SL_KEY_DELETE: ev->data.key.ch = CACA_KEY_DELETE; break; case 0x7f: case SL_KEY_BACKSPACE: ev->data.key.ch = CACA_KEY_BACKSPACE; break; case SL_KEY_HOME: ev->data.key.ch = CACA_KEY_HOME; break; case SL_KEY_END: ev->data.key.ch = CACA_KEY_END; break; case SL_KEY_PPAGE: ev->data.key.ch = CACA_KEY_PAGEUP; break; case SL_KEY_NPAGE: ev->data.key.ch = CACA_KEY_PAGEDOWN; break; case SL_KEY_F(1): ev->data.key.ch = CACA_KEY_F1; break; case SL_KEY_F(2): ev->data.key.ch = CACA_KEY_F2; break; case SL_KEY_F(3): ev->data.key.ch = CACA_KEY_F3; break; case SL_KEY_F(4): ev->data.key.ch = CACA_KEY_F4; break; case SL_KEY_F(5): ev->data.key.ch = CACA_KEY_F5; break; case SL_KEY_F(6): ev->data.key.ch = CACA_KEY_F6; break; case SL_KEY_F(7): ev->data.key.ch = CACA_KEY_F7; break; case SL_KEY_F(8): ev->data.key.ch = CACA_KEY_F8; break; case SL_KEY_F(9): ev->data.key.ch = CACA_KEY_F9; break; case SL_KEY_F(10): ev->data.key.ch = CACA_KEY_F10; break; case SL_KEY_F(11): ev->data.key.ch = CACA_KEY_F11; break; case SL_KEY_F(12): ev->data.key.ch = CACA_KEY_F12; break; default: /* Unknown key */ ev->type = CACA_EVENT_NONE; return 0; } ev->type = CACA_EVENT_KEY_PRESS; ev->data.key.utf32 = 0; ev->data.key.utf8[0] = '\0'; return 1; }