static int read_emacs_keys(const char *name) { if (strcmp(name, "^N") == 0) { return KEY_DOWN; } else if (strcmp(name, "^P") == 0) { return KEY_UP; } else if (strcmp(name, "^C") == 0) { return KEY_ESCAPE; } else if (strcmp(name, "^W") == 0) { reset_query(); return 0; } else if (strcmp(name, "^D") == 0) { return KEY_BACKSPACE; } else if (strcmp(name, "^V") == 0) { return KEY_NPAGE; } else if (strcmp(name, "M-6") == 0) { return KEY_PPAGE; } return -1; }
void run_term(void) { const config_t *conf = config(); int c; while ((c = wgetch(window)) != KEY_ESCAPE) { if (conf->section_main->emacs_bindings) { int key = read_emacs_keys(keyname(c)); if (key != -1) { if (key == KEY_ESCAPE) break; c = key; } } open_by_shortcut(c); if (c == KEY_DOWN) { menu_driver(menu_list, REQ_DOWN_ITEM); update_info_bar(); } else if (c == KEY_UP) { menu_driver(menu_list, REQ_UP_ITEM); update_info_bar(); } else if (c == KEY_RETURN) { set_app_to_run(); } else if (c == KEY_NPAGE) { menu_driver(menu_list, REQ_SCR_DPAGE); update_info_bar(); } else if (c == KEY_PPAGE) { menu_driver(menu_list, REQ_SCR_UPAGE); update_info_bar(); } else if (c == KEY_BACKSPACE) { if (query_len >= 1) { query_len--; if (query_len == 0) { reset_query(); } else { form_driver(form, REQ_DEL_PREV); form_driver(form, REQ_VALIDATION); snprintf( query, MAX_INPUT_LENGTH, "%s", field_buffer(field[0], 0) ); char *new_query = smalloc(query_len + 1); memcpy(new_query, query, query_len); new_query[query_len] = '\0'; search(new_query); prepare_for_new_results(True); free(new_query); } } } else if (isprint(c)) { mvprintw(0, 0, "$"); if (! is_cache_ready()) { continue; } if (query_len == 0 && c == ' ') { reset_query(); continue; } else if (query_len == 0) { clean_line(0); } form_driver(form, c); form_driver(form, REQ_VALIDATION); snprintf( query, MAX_INPUT_LENGTH, "%s", field_buffer(field[0], 0) ); query_len++; char new_query[query_len]; memcpy(new_query, query, query_len); new_query[query_len] = '\0'; if (search(new_query)) prepare_for_new_results(True); } if (run_app == True) { break; } } }
// Leave search mode and redraw the map void do_back(){ reset_query(); destroy_matches(); draw_full_image(); about_screen(); }
// Pop up the keyboard void do_pop(){ pop_screen(); reset_query(); kb_listen(); }