Exemplo n.º 1
0
Arquivo: cmdline.c Projeto: sklnd/vifm
static void
cmd_ctrl_h(key_info_t key_info, keys_info_t *keys_info)
{
	input_stat.history_search = HIST_NONE;
	stop_completion();

	if(input_stat.index == 0 && input_stat.len == 0 && sub_mode != PROMPT_SUBMODE)
	{
		cmd_ctrl_c(key_info, keys_info);
		return;
	}
	if(input_stat.index == 0)
		return;

	if(input_stat.index == input_stat.len)
	{
		input_stat.index--;
		input_stat.len--;

		input_stat.curs_pos -= wcwidth(input_stat.line[input_stat.index]);

		input_stat.line[input_stat.index] = L'\0';
	}
	else
	{
		input_stat.index--;
		input_stat.len--;

		input_stat.curs_pos -= wcwidth(input_stat.line[input_stat.index]);
		wcsdel(input_stat.line, input_stat.index + 1, 1);
	}

	update_cmdline_text();
}
Exemplo n.º 2
0
/* Handles backspace. */
static void
cmd_ctrl_h(key_info_t key_info, keys_info_t *keys_info)
{
	input_stat.history_search = HIST_NONE;
	stop_completion();

	if(should_quit_on_backspace())
	{
		cmd_ctrl_c(key_info, keys_info);
		return;
	}

	if(input_stat.index == 0)
	{
		return;
	}

	input_stat.index--;
	input_stat.len--;

	input_stat.curs_pos -= vifm_wcwidth(input_stat.line[input_stat.index]);

	if(input_stat.index == input_stat.len)
	{
		input_stat.line[input_stat.index] = L'\0';
	}
	else
	{
		wcsdel(input_stat.line, input_stat.index + 1, 1);
	}

	update_cmdline_text();
}
Exemplo n.º 3
0
Arquivo: cmdline.c Projeto: sklnd/vifm
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;
}
Exemplo n.º 4
0
static void
cmd_ctrl_n(key_info_t key_info, keys_info_t *keys_info)
{
	stop_completion();

	if(input_stat.history_search == HIST_NONE)
		save_users_input();

	input_stat.history_search = HIST_GO;

	search_next();
}
Exemplo n.º 5
0
static void
cmd_right(key_info_t key_info, keys_info_t *keys_info)
{
	input_stat.history_search = HIST_NONE;
	stop_completion();

	if(input_stat.index < input_stat.len)
	{
		input_stat.curs_pos += vifm_wcwidth(input_stat.line[input_stat.index]);
		input_stat.index++;
		update_cursor();
	}
}
Exemplo n.º 6
0
static void
cmd_left(key_info_t key_info, keys_info_t *keys_info)
{
	input_stat.history_search = HIST_NONE;
	stop_completion();

	if(input_stat.index > 0)
	{
		input_stat.index--;
		input_stat.curs_pos -= vifm_wcwidth(input_stat.line[input_stat.index]);
		update_cursor();
	}
}
Exemplo n.º 7
0
static void
cmd_delete(key_info_t key_info, keys_info_t *keys_info)
{
	input_stat.history_search = HIST_NONE;
	stop_completion();

	if(input_stat.index == input_stat.len)
		return;

	wcsdel(input_stat.line, input_stat.index+1, 1);
	input_stat.len--;

	update_cmdline_text();
}
Exemplo n.º 8
0
static void
cmd_ctrl_underscore(key_info_t key_info, keys_info_t *keys_info)
{
	if(!input_stat.complete_continue)
		return;
	rewind_completion();

	if(!input_stat.complete_continue)
		draw_wild_menu(1);
	input_stat.reverse_completion = 0;
	do_completion();
	if(cfg.wild_menu)
		draw_wild_menu(0);

	stop_completion();
}
Exemplo n.º 9
0
static void
cmd_down(key_info_t key_info, keys_info_t *keys_info)
{
	stop_completion();

	if(input_stat.history_search == HIST_NONE)
		save_users_input();

	if(input_stat.history_search != HIST_SEARCH)
	{
		input_stat.history_search = HIST_SEARCH;
		input_stat.hist_search_len = input_stat.len;
	}

	search_next();
}
Exemplo n.º 10
0
/* Handler of Ctrl-W shortcut, which remove all to the left until beginning of
 * the word is found (i.e. until first delimiter character). */
static void
cmd_ctrl_w(key_info_t key_info, keys_info_t *keys_info)
{
	int old;

	input_stat.history_search = HIST_NONE;
	stop_completion();

	old = input_stat.index;

	while(input_stat.index > 0 && iswspace(input_stat.line[input_stat.index - 1]))
	{
		input_stat.curs_pos -= vifm_wcwidth(input_stat.line[input_stat.index - 1]);
		input_stat.index--;
	}
	if(iswalnum(input_stat.line[input_stat.index - 1]))
	{
		while(input_stat.index > 0 &&
				iswalnum(input_stat.line[input_stat.index - 1]))
		{
			const wchar_t curr_wchar = input_stat.line[input_stat.index - 1];
			input_stat.curs_pos -= vifm_wcwidth(curr_wchar);
			input_stat.index--;
		}
	}
	else
	{
		while(input_stat.index > 0 &&
				!iswalnum(input_stat.line[input_stat.index - 1]) &&
				!iswspace(input_stat.line[input_stat.index - 1]))
		{
			const wchar_t curr_wchar = input_stat.line[input_stat.index - 1];
			input_stat.curs_pos -= vifm_wcwidth(curr_wchar);
			input_stat.index--;
		}
	}

	if(input_stat.index != old)
	{
		wcsdel(input_stat.line, input_stat.index + 1, old - input_stat.index);
		input_stat.len -= old - input_stat.index;
	}

	update_cmdline_text();
}
Exemplo n.º 11
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();
	}
}
Exemplo n.º 12
0
static void
cmd_ctrl_u(key_info_t key_info, keys_info_t *keys_info)
{
	input_stat.history_search = HIST_NONE;
	stop_completion();

	if(input_stat.index == 0)
		return;

	input_stat.len -= input_stat.index;

	input_stat.curs_pos = input_stat.prompt_wid;
	wcsdel(input_stat.line, 1, input_stat.index);

	input_stat.index = 0;

	werase(status_bar);
	mvwaddwstr(status_bar, 0, 0, input_stat.prompt);
	mvwaddwstr(status_bar, 0, input_stat.prompt_wid, input_stat.line);

	update_cmdline_text();
}
Exemplo n.º 13
0
Arquivo: cmdline.c Projeto: sklnd/vifm
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);
	}
}
Exemplo n.º 14
0
Arquivo: cmdline.c Projeto: sklnd/vifm
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);
}
Exemplo n.º 15
0
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);
}