Exemplo n.º 1
0
static void
dont_treat_multikeys_as_motions(void)
{
	assert_int_equal(KEYS_WAIT, execute_keys(L"d"));
	assert_int_equal(KEYS_WAIT, execute_keys(L"m"));
	assert_int_equal(KEYS_UNKNOWN, execute_keys(L"dm"));
}
Exemplo n.º 2
0
Arquivo: motions.c Projeto: sklnd/vifm
static void
test_d3k(void)
{
	assert_int_equal(KEYS_WAIT, execute_keys(L"d"));
	assert_int_equal(KEYS_WAIT, execute_keys(L"d3"));
	assert_false(IS_KEYS_RET_CODE(execute_keys(L"d3k")));
}
Exemplo n.º 3
0
Arquivo: motions.c Projeto: sklnd/vifm
static void
test_4dj(void)
{
	assert_int_equal(KEYS_WAIT, execute_keys(L"4"));
	assert_int_equal(KEYS_WAIT, execute_keys(L"4d"));
	assert_false(IS_KEYS_RET_CODE(execute_keys(L"4dj")));
}
Exemplo n.º 4
0
static void
test_cancel_on_ctrl_c_and_escape(void)
{
	assert_int_equal(KEYS_WAIT, execute_keys(L"m"));
	assert_int_equal(0, execute_keys(L"m"L"\x03"));
	assert_int_equal(0, execute_keys(L"m"L"\x1b"));
}
Exemplo n.º 5
0
static void
test_when_previous_known(void)
{
	assert_int_equal(KEYS_WAIT_SHORT, execute_keys(L"q"));
	assert_int_equal(KEYS_WAIT_SHORT, execute_keys(L"qb"));
	assert_false(IS_KEYS_RET_CODE(execute_keys(L"qbc")));
}
Exemplo n.º 6
0
static void
multikeys(void)
{
	assert_int_equal(KEYS_WAIT, execute_keys(L"m"));
	assert_false(IS_KEYS_RET_CODE(execute_keys(L"ma")));
	assert_false(IS_KEYS_RET_CODE(execute_keys(L"mb")));
	assert_int_equal(KEYS_UNKNOWN, execute_keys(L"mba"));
}
Exemplo n.º 7
0
static void
cmd_line_tst(void)
{
	counter = 0;

	assert_false(IS_KEYS_RET_CODE(execute_keys(L"s")));
	assert_false(IS_KEYS_RET_CODE(execute_keys(L"q")));

	assert_true(counter == 9);
}
Exemplo n.º 8
0
Arquivo: unmap.c Projeto: sklnd/vifm
static void
test_unmap_remapped(void)
{
	assert_int_equal(0, execute_keys(L"j"));

	assert_int_equal(0, add_user_keys(L"j", L"k", NORMAL_MODE, 0));

	assert_int_equal(0, execute_keys(L"j"));

	assert_int_equal(0, execute_keys(L"j"));
	assert_int_equal(0, remove_user_keys(L"j", NORMAL_MODE));
	assert_int_equal(0, execute_keys(L"j"));
}
Exemplo n.º 9
0
static void
prevent_stack_overflow(void)
{
	assert_int_equal(0, add_user_keys(L"j", L"j", NORMAL_MODE, 0));
	assert_false(IS_KEYS_RET_CODE(execute_keys(L"j")));

	assert_int_equal(0, add_user_keys(L"q", L"q", NORMAL_MODE, 0));
	assert_int_equal(KEYS_UNKNOWN, execute_keys(L"q"));

	set_def_handler(NORMAL_MODE, handler);

	assert_int_equal(0, add_user_keys(L"t", L"toto", NORMAL_MODE, 0));
	assert_int_equal(0, execute_keys(L"t"));

	assert_int_equal(4, counter);

	set_def_handler(NORMAL_MODE, NULL);
}
Exemplo n.º 10
0
static void
test_without_noremap(void)
{
	assert_int_equal(0, execute_keys(L"k"));
	assert_int_equal(1, last);

	assert_int_equal(0, execute_keys(L"j"));
	assert_int_equal(2, last);

	assert_int_equal(0, add_user_keys(L"j", L"k", NORMAL_MODE, 0));
	assert_int_equal(0, add_user_keys(L"q", L"j", NORMAL_MODE, 0));

	assert_int_equal(0, execute_keys(L"j"));
	assert_int_equal(1, last);

	assert_int_equal(0, execute_keys(L"q"));
	assert_int_equal(1, last);
}
Exemplo n.º 11
0
static void
test_noremap_functions(void)
{
	assert_int_equal(0, add_user_keys(L"y", L"k", NORMAL_MODE, 0));

	assert_false(IS_KEYS_RET_CODE(execute_keys(L"y")));
	assert_true(IS_KEYS_RET_CODE(execute_keys_no_remap(L"y")));

	assert_false(IS_KEYS_RET_CODE(execute_keys_timed_out(L"y")));
	assert_true(IS_KEYS_RET_CODE(execute_keys_timed_out_no_remap(L"y")));
}
Exemplo n.º 12
0
Arquivo: count.c Projeto: KryDos/vifm
static void
test_max_count_is_handled_correctly(void)
{
	char *const keys = format_str("%udd", INT_MAX);
	wchar_t *const keysw = to_wide(keys);

	assert_false(IS_KEYS_RET_CODE(execute_keys(keysw)));
	assert_int_equal(INT_MAX, last_command_count);

	free(keysw);
	free(keys);
}
Exemplo n.º 13
0
Arquivo: unmap.c Projeto: sklnd/vifm
static void
test_unmap_users(void)
{
	assert_int_equal(KEYS_UNKNOWN, execute_keys(L","));
	assert_int_equal(KEYS_UNKNOWN, execute_keys(L"q"));
	assert_int_equal(KEYS_UNKNOWN, execute_keys(L"s"));

	assert_int_equal(0, add_user_keys(L",q", L"k", NORMAL_MODE, 0));
	assert_int_equal(0, add_user_keys(L",s", L"j", NORMAL_MODE, 0));

	assert_int_equal(KEYS_WAIT, execute_keys(L","));

	assert_int_equal(0, execute_keys(L",q"));
	assert_int_equal(0, remove_user_keys(L",q", NORMAL_MODE));
	assert_int_equal(KEYS_UNKNOWN, execute_keys(L",q"));

	assert_int_equal(0, execute_keys(L",s"));
	assert_int_equal(0, remove_user_keys(L",s", NORMAL_MODE));
	assert_int_equal(KEYS_UNKNOWN, execute_keys(L",s"));

	assert_int_equal(KEYS_UNKNOWN, execute_keys(L","));
}
Exemplo n.º 14
0
Arquivo: count.c Projeto: KryDos/vifm
static void
test_huge_number_get_intmax(void)
{
	assert_false(IS_KEYS_RET_CODE(execute_keys(L"999999999999dd")));
	assert_int_equal(INT_MAX, last_command_count);
}
Exemplo n.º 15
0
Arquivo: count.c Projeto: KryDos/vifm
static void
test_no_number_get_not_def(void)
{
	assert_false(IS_KEYS_RET_CODE(execute_keys(L"dd")));
	assert_int_equal(NO_COUNT_GIVEN, last_command_count);
}
Exemplo n.º 16
0
Arquivo: count.c Projeto: KryDos/vifm
static void
test_normal_number_get_it(void)
{
	assert_false(IS_KEYS_RET_CODE(execute_keys(L"123dd")));
	assert_int_equal(123, last_command_count);
}
Exemplo n.º 17
0
void
event_loop(const int *quit)
{
	/* TODO: refactor this function event_loop(). */

	LOG_FUNC_ENTER;

	const wchar_t *const prev_input_buf = curr_input_buf;
	const size_t *const prev_input_buf_pos = curr_input_buf_pos;

	wchar_t input_buf[128];
	size_t input_buf_pos;

	int last_result = 0;
	int wait_for_enter = 0;
	int timeout = cfg.timeout_len;

	input_buf[0] = L'\0';
	input_buf_pos = 0;
	curr_input_buf = &input_buf[0];
	curr_input_buf_pos = &input_buf_pos;

	while(!*quit)
	{
		wint_t c;
		size_t counter;
		int got_input;

		if(!ensure_term_is_ready())
		{
			wait_for_enter = 0;
			continue;
		}

		lwin.user_selection = 1;
		rwin.user_selection = 1;

		modes_pre();

		/* Waits for timeout then skips if no keypress.  Short-circuit if we're not
		 * waiting for the next key after timeout. */
		do
		{
			modes_periodic();

			check_background_jobs();

			got_input = get_char_async_loop(status_bar, &c, timeout) != ERR;
			if(!got_input && input_buf_pos == 0)
			{
				timeout = cfg.timeout_len;
				continue;
			}
			break;
		}
		while(1);

		/* Ensure that current working directory is set correctly (some pieces of
		 * code rely on this). */
		(void)vifm_chdir(flist_get_dir(curr_view));

		if(got_input)
		{
			if(wait_for_enter)
			{
				wait_for_enter = 0;
				curr_stats.save_msg = 0;
				clean_status_bar();
				if(c == L'\x0d')
				{
					continue;
				}
			}

			if(c == L'\x1a') /* Ctrl-Z */
			{
				def_prog_mode();
				endwin();
				stop_process();
				continue;
			}

			if(input_buf_pos < ARRAY_LEN(input_buf) - 2)
			{
				input_buf[input_buf_pos++] = c;
				input_buf[input_buf_pos] = L'\0';
			}
			else
			{
				/* Recover from input buffer overflow by resetting its contents. */
				reset_input_buf(input_buf, &input_buf_pos);
				clear_input_bar();
				continue;
			}
		}

		counter = get_key_counter();
		if(!got_input && last_result == KEYS_WAIT_SHORT)
		{
			last_result = execute_keys_timed_out(input_buf);
			counter = get_key_counter() - counter;
			assert(counter <= input_buf_pos);
			if(counter > 0)
			{
				memmove(input_buf, input_buf + counter,
						(wcslen(input_buf) - counter + 1)*sizeof(wchar_t));
			}
		}
		else
		{
			if(got_input)
			{
				curr_stats.save_msg = 0;
			}

			last_result = execute_keys(input_buf);

			counter = get_key_counter() - counter;
			assert(counter <= input_buf_pos);
			if(counter > 0)
			{
				input_buf_pos -= counter;
				memmove(input_buf, input_buf + counter,
						(wcslen(input_buf) - counter + 1)*sizeof(wchar_t));
			}

			if(last_result == KEYS_WAIT || last_result == KEYS_WAIT_SHORT)
			{
				if(got_input)
				{
					modupd_input_bar(input_buf);
				}

				if(last_result == KEYS_WAIT_SHORT && wcscmp(input_buf, L"\033") == 0)
				{
					timeout = 1;
				}

				if(counter > 0)
				{
					clear_input_bar();
				}

				if(!curr_stats.save_msg && curr_view->selected_files &&
						!vle_mode_is(CMDLINE_MODE))
				{
					print_selected_msg();
				}
				continue;
			}
		}

		timeout = cfg.timeout_len;

		process_scheduled_updates();

		reset_input_buf(input_buf, &input_buf_pos);
		clear_input_bar();

		if(is_status_bar_multiline())
		{
			wait_for_enter = 1;
			update_all_windows();
			continue;
		}

		/* Ensure that current working directory is set correctly (some pieces of
		 * code rely on this).  PWD could be changed during command execution, but
		 * it should be correct for modes_post() in case of preview modes. */
		(void)vifm_chdir(flist_get_dir(curr_view));
		modes_post();
	}

	curr_input_buf = prev_input_buf;
	curr_input_buf_pos = prev_input_buf_pos;
}
Exemplo n.º 18
0
Arquivo: count.c Projeto: KryDos/vifm
static void
test_nops_count_not_passed(void)
{
	assert_false(IS_KEYS_RET_CODE(execute_keys(L"10abcdd")));
	assert_int_equal(NO_COUNT_GIVEN, last_command_count);
}
Exemplo n.º 19
0
/*
 * Main Loop
 * Everything is driven from this function with the exception of
 * signals which are handled in signals.c
 */
void
main_loop(void)
{
	LOG_FUNC_ENTER;

	int last_result = 0;
	int wait_enter = 0;
	int timeout = cfg.timeout_len;

	buf[0] = L'\0';
	while(1)
	{
		wchar_t c;
		size_t counter;
		int ret;

		is_term_working();

#ifdef _WIN32
		update_win_console();
#endif

		lwin.user_selection = 1;
		rwin.user_selection = 1;

		if(curr_stats.too_small_term > 0)
		{
			touchwin(stdscr);
			wrefresh(stdscr);

			mvwin(status_bar, 0, 0);
			wresize(status_bar, getmaxy(stdscr), getmaxx(stdscr));
			werase(status_bar);
			waddstr(status_bar, "Terminal is too small for vifm");
			touchwin(status_bar);
			wrefresh(status_bar);

#ifndef _WIN32
			pause();
#endif
			continue;
		}
		else if(curr_stats.too_small_term < 0)
		{
			wtimeout(status_bar, 0);
			while(wget_wch(status_bar, (wint_t*)&c) != ERR);
			curr_stats.too_small_term = 0;
			modes_redraw();
			wtimeout(status_bar, cfg.timeout_len);

			wait_enter = 0;
			curr_stats.save_msg = 0;
			status_bar_message("");
		}

		modes_pre();

		/* This waits for timeout then skips if no keypress. */
		ret = read_char(status_bar, (wint_t*)&c, timeout);

		/* Ensure that current working directory is set correctly (some pieces of
		 * code rely on this). */
		(void)vifm_chdir(curr_view->curr_dir);

		if(ret != ERR && pos != ARRAY_LEN(buf) - 2)
		{
			if(c == L'\x1a') /* Ctrl-Z */
			{
				def_prog_mode();
				endwin();
#ifndef _WIN32
				{
					void (*saved_stp_sig_handler)(int) = signal(SIGTSTP, SIG_DFL);
					kill(0, SIGTSTP);
					signal(SIGTSTP, saved_stp_sig_handler);
				}
#endif
				continue;
			}

			if(wait_enter)
			{
				wait_enter = 0;
				curr_stats.save_msg = 0;
				clean_status_bar();
				if(c == L'\x0d')
					continue;
			}

			buf[pos++] = c;
			buf[pos] = L'\0';
		}

		if(wait_enter && ret == ERR)
			continue;

		counter = get_key_counter();
		if(ret == ERR && last_result == KEYS_WAIT_SHORT)
		{
			last_result = execute_keys_timed_out(buf);
			counter = get_key_counter() - counter;
			assert(counter <= pos);
			if(counter > 0)
			{
				memmove(buf, buf + counter,
						(wcslen(buf) - counter + 1)*sizeof(wchar_t));
			}
		}
		else
		{
			if(ret != ERR)
				curr_stats.save_msg = 0;
			last_result = execute_keys(buf);
			counter = get_key_counter() - counter;
			assert(counter <= pos);
			if(counter > 0)
			{
				pos -= counter;
				memmove(buf, buf + counter,
						(wcslen(buf) - counter + 1)*sizeof(wchar_t));
			}
			if(last_result == KEYS_WAIT || last_result == KEYS_WAIT_SHORT)
			{
				if(ret != ERR)
					modupd_input_bar(buf);
				if(last_result == KEYS_WAIT_SHORT && wcscmp(buf, L"\033") == 0)
					timeout = 1;
				if(counter > 0)
					clear_input_bar();

				if(!curr_stats.save_msg && curr_view->selected_files &&
						get_mode() != CMDLINE_MODE)
					print_selected_msg();
				continue;
			}
		}

		timeout = cfg.timeout_len;

		process_scheduled_updates();

		pos = 0;
		buf[0] = L'\0';
		clear_input_bar();

		if(is_status_bar_multiline())
		{
			wait_enter = 1;
			update_all_windows();
			continue;
		}

		/* Ensure that current working directory is set correctly (some pieces of
		 * code rely on this).  PWD could be changed during command execution, but
		 * it should be correct for modes_post() in case of preview modes. */
		(void)vifm_chdir(curr_view->curr_dir);
		modes_post();
	}
}