/* Opens the editor with already typed in characters, gets entered line and * executes it as if it was typed. */ static void cmd_ctrl_g(key_info_t key_info, keys_info_t *keys_info) { const int type = submode_to_editable_command_type(sub_mode); const int prompt_ee = sub_mode == PROMPT_SUBMODE && sub_mode_allows_ee; if(type != -1 || prompt_ee) { char *const mbstr = (input_stat.line == NULL) ? strdup("") : to_multibyte(input_stat.line); leave_cmdline_mode(); if(sub_mode == FILTER_SUBMODE) { local_filter_cancel(curr_view); } if(prompt_ee) { extedit_prompt(mbstr, input_stat.index + 1); } else { get_and_execute_command(mbstr, input_stat.index + 1, type); } free(mbstr); } }
static int def_handler(wchar_t key) { void *p; wchar_t buf[2] = {key, L'\0'}; input_stat.history_search = HIST_NONE; if(input_stat.complete_continue && input_stat.line[input_stat.index - 1] == L'/' && key == '/') { stop_completion(); return 0; } stop_completion(); if(key != L'\r' && !iswprint(key)) return 0; p = realloc(input_stat.line, (input_stat.len + 2) * sizeof(wchar_t)); if(p == NULL) { leave_cmdline_mode(); return 0; } input_stat.line = (wchar_t *) p; if(input_stat.len == 0) input_stat.line[0] = L'\0'; input_stat.index++; wcsins(input_stat.line, buf, input_stat.index); input_stat.len++; input_stat.curs_pos += wcwidth(key); update_cmdline_size(); update_cmdline_text(); return 0; }
/* Initiates leaving of command-line mode and reverting related changes in other * parts of the interface. */ static void cmd_ctrl_c(key_info_t key_info, keys_info_t *keys_info) { stop_completion(); werase(status_bar); wnoutrefresh(status_bar); if(input_stat.line != NULL) { char *mbstr = to_multibyte(input_stat.line); save_input_to_history(keys_info, mbstr); free(mbstr); input_stat.line[0] = L'\0'; } if(sub_mode != FILTER_SUBMODE) { input_line_changed(); } leave_cmdline_mode(); if(prev_mode == VISUAL_MODE) { if(!input_stat.search_mode) { leave_visual_mode(curr_stats.save_msg, 1, 1); move_to_list_pos(curr_view, check_mark_directory(curr_view, '<')); } } if(sub_mode == CMD_SUBMODE) { curr_stats.save_msg = exec_commands("", curr_view, GET_COMMAND); } else if(sub_mode == FILTER_SUBMODE) { local_filter_cancel(curr_view); curr_view->top_line = input_stat.old_top; curr_view->list_pos = input_stat.old_pos; redraw_current_view(); } }
static void cmd_ctrl_c(key_info_t key_info, keys_info_t *keys_info) { stop_completion(); werase(status_bar); wnoutrefresh(status_bar); if(input_stat.line != NULL) input_stat.line[0] = L'\0'; input_line_changed(); leave_cmdline_mode(); if(prev_mode == VISUAL_MODE) { leave_visual_mode(curr_stats.save_msg, 1, 1); move_to_list_pos(curr_view, check_mark_directory(curr_view, '<')); } if(sub_mode == CMD_SUBMODE) { int save_hist = !keys_info->mapped; curr_stats.save_msg = exec_commands("", curr_view, save_hist, GET_COMMAND); } }
static void cmd_ctrl_m(key_info_t key_info, keys_info_t *keys_info) { char* p; int save_hist = !keys_info->mapped; stop_completion(); werase(status_bar); wnoutrefresh(status_bar); if((!input_stat.line || !input_stat.line[0]) && sub_mode == MENU_CMD_SUBMODE) { leave_cmdline_mode(); return; } p = input_stat.line ? to_multibyte(input_stat.line) : NULL; leave_cmdline_mode(); if(prev_mode == VISUAL_MODE && sub_mode != VSEARCH_FORWARD_SUBMODE && sub_mode != VSEARCH_BACKWARD_SUBMODE) leave_visual_mode(curr_stats.save_msg, 1, 0); if(sub_mode == CMD_SUBMODE || sub_mode == MENU_CMD_SUBMODE) { char* s = (p != NULL) ? p : ""; while(*s == ' ' || *s == ':') s++; if(sub_mode == CMD_SUBMODE) curr_stats.save_msg = exec_commands(s, curr_view, save_hist, GET_COMMAND); else curr_stats.save_msg = exec_commands(s, curr_view, save_hist, GET_MENU_COMMAND); } else if(sub_mode == PROMPT_SUBMODE) { prompt_cb cb; if(p != NULL && p[0] != '\0') save_prompt_history(p); modes_post(); modes_pre(); cb = (prompt_cb)sub_mode_ptr; cb(p); } else if(!cfg.inc_search || prev_mode == VIEW_MODE) { if(sub_mode == SEARCH_FORWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_FSEARCH_PATTERN); } else if(sub_mode == SEARCH_BACKWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_BSEARCH_PATTERN); } else if(sub_mode == MENU_SEARCH_FORWARD_SUBMODE || sub_mode == MENU_SEARCH_BACKWARD_SUBMODE) { curr_stats.need_redraw = 1; search_menu_list(p, sub_mode_ptr); } else if(sub_mode == VSEARCH_FORWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_VFSEARCH_PATTERN); } else if(sub_mode == VSEARCH_BACKWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_VBSEARCH_PATTERN); } else if(sub_mode == VIEW_SEARCH_FORWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_VWFSEARCH_PATTERN); } else if(sub_mode == VIEW_SEARCH_BACKWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_VWBSEARCH_PATTERN); } } free(p); }
static void cmd_ctrl_m(key_info_t key_info, keys_info_t *keys_info) { /* TODO: refactor this cmd_ctrl_m() function. */ char* p; stop_completion(); werase(status_bar); wnoutrefresh(status_bar); if((!input_stat.line || !input_stat.line[0]) && sub_mode == MENU_CMD_SUBMODE) { leave_cmdline_mode(); return; } p = input_stat.line ? to_multibyte(input_stat.line) : NULL; leave_cmdline_mode(); if(prev_mode == VISUAL_MODE && sub_mode != VSEARCH_FORWARD_SUBMODE && sub_mode != VSEARCH_BACKWARD_SUBMODE) leave_visual_mode(curr_stats.save_msg, 1, 0); save_input_to_history(keys_info, p); if(sub_mode == CMD_SUBMODE || sub_mode == MENU_CMD_SUBMODE) { char* s = (p != NULL) ? p : ""; while(*s == ' ' || *s == ':') s++; if(sub_mode == CMD_SUBMODE) curr_stats.save_msg = exec_commands(s, curr_view, GET_COMMAND); else curr_stats.save_msg = exec_commands(s, curr_view, GET_MENU_COMMAND); } else if(sub_mode == PROMPT_SUBMODE) { finish_prompt_submode(p); } else if(sub_mode == FILTER_SUBMODE) { if(cfg.inc_search) { local_filter_accept(curr_view); } else { local_filter_apply(curr_view, p); load_saving_pos(curr_view, 1); } } else if(!cfg.inc_search || prev_mode == VIEW_MODE) { switch(sub_mode) { case SEARCH_FORWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_FSEARCH_PATTERN); break; case SEARCH_BACKWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_BSEARCH_PATTERN); break; case VSEARCH_FORWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_VFSEARCH_PATTERN); break; case VSEARCH_BACKWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_VBSEARCH_PATTERN); break; case VIEW_SEARCH_FORWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_VWFSEARCH_PATTERN); break; case VIEW_SEARCH_BACKWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_VWBSEARCH_PATTERN); break; case MENU_SEARCH_FORWARD_SUBMODE: case MENU_SEARCH_BACKWARD_SUBMODE: curr_stats.need_update = UT_FULL; search_menu_list(p, sub_mode_ptr); break; default: assert(0 && "Unknown command line submode."); break; } } else if(cfg.inc_search && input_stat.search_mode) { /* In case of successful search and 'hlsearch' option set, a message like * "n files selected" is printed automatically. */ if(curr_view->matches == 0 || !cfg.hl_search) { print_search_msg(curr_view, is_backward_search(sub_mode)); curr_stats.save_msg = 1; } } free(p); }