예제 #1
0
파일: window-copy.c 프로젝트: ddollar/tmux
void
window_copy_resize(struct window_pane *wp, u_int sx, u_int sy)
{
	struct window_copy_mode_data	*data = wp->modedata;
	struct screen			*s = &data->screen;
	struct screen_write_ctx	 	 ctx;

	screen_resize(s, sx, sy);
	if (data->backing != &wp->base)
		screen_resize(data->backing, sx, sy);

	if (data->cy > sy - 1)
		data->cy = sy - 1;
	if (data->cx > sx)
		data->cx = sx;
	if (data->oy > screen_hsize(data->backing))
		data->oy = screen_hsize(data->backing);

	window_copy_clear_selection(wp);

	screen_write_start(&ctx, NULL, s);
	window_copy_write_lines(wp, &ctx, 0, screen_size_y(s) - 1);
	screen_write_stop(&ctx);

	window_copy_redraw_screen(wp);
}
예제 #2
0
void
window_copy_key(struct window_pane *wp, struct client *c, int key)
{
	const char			*word_separators;
	struct window_copy_mode_data	*data = wp->modedata;
	struct screen			*s = &data->screen;
	u_int				 n, np;
	int				 keys;
	enum mode_key_cmd		 cmd;

	np = data->numprefix;
	if (np == 0)
		np = 1;

	if (data->inputtype == WINDOW_COPY_NUMERICPREFIX) {
		if (window_copy_key_numeric_prefix(wp, key) == 0)
			return;
		data->inputtype = WINDOW_COPY_OFF;
		window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1);
	} else if (data->inputtype != WINDOW_COPY_OFF) {
		if (window_copy_key_input(wp, key) != 0)
			goto input_off;
		return;
	}

	cmd = mode_key_lookup(&data->mdata, key);
	switch (cmd) {
	case MODEKEYCOPY_CANCEL:
		for (; np != 0; np--)
			window_pane_reset_mode(wp);
		break;
	case MODEKEYCOPY_LEFT:
		for (; np != 0; np--)
			window_copy_cursor_left(wp);
		break;
	case MODEKEYCOPY_RIGHT:
		for (; np != 0; np--)
			window_copy_cursor_right(wp);
		break;
	case MODEKEYCOPY_UP:
		for (; np != 0; np--)
			window_copy_cursor_up(wp, 0);
		break;
	case MODEKEYCOPY_DOWN:
		for (; np != 0; np--)
			window_copy_cursor_down(wp, 0);
		break;
	case MODEKEYCOPY_SCROLLUP:
		for (; np != 0; np--)
			window_copy_cursor_up(wp, 1);
		break;
	case MODEKEYCOPY_SCROLLDOWN:
		for (; np != 0; np--)
			window_copy_cursor_down(wp, 1);
		break;
	case MODEKEYCOPY_PREVIOUSPAGE:
		for (; np != 0; np--)
			window_copy_pageup(wp);
		break;
	case MODEKEYCOPY_NEXTPAGE:
		n = 1;
		if (screen_size_y(s) > 2)
			n = screen_size_y(s) - 2;
		for (; np != 0; np--) {
			if (data->oy < n)
				data->oy = 0;
			else
				data->oy -= n;
		}
		window_copy_update_selection(wp);
		window_copy_redraw_screen(wp);
		break;
	case MODEKEYCOPY_HALFPAGEUP:
		n = screen_size_y(s) / 2;
		for (; np != 0; np--) {
			if (data->oy + n > screen_hsize(&wp->base))
				data->oy = screen_hsize(&wp->base);
			else
				data->oy += n;
		}
		window_copy_update_selection(wp);
		window_copy_redraw_screen(wp);
		break;
	case MODEKEYCOPY_HALFPAGEDOWN:
		n = screen_size_y(s) / 2;
		for (; np != 0; np--) {
			if (data->oy < n)
				data->oy = 0;
			else
				data->oy -= n;
		}
		window_copy_update_selection(wp);
		window_copy_redraw_screen(wp);
		break;
	case MODEKEYCOPY_TOPLINE:
		data->cx = 0;
		data->cy = 0;
		window_copy_update_selection(wp);
		window_copy_redraw_screen(wp);
		break;
	case MODEKEYCOPY_MIDDLELINE:
		data->cx = 0;
		data->cy = (screen_size_y(s) - 1) / 2;
		window_copy_update_selection(wp);
		window_copy_redraw_screen(wp);
		break;
	case MODEKEYCOPY_BOTTOMLINE:
		data->cx = 0;
		data->cy = screen_size_y(s) - 1;
		window_copy_update_selection(wp);
		window_copy_redraw_screen(wp);
		break;
	case MODEKEYCOPY_HISTORYTOP:
		data->cx = 0;
		data->cy = 0;
		data->oy = screen_hsize(&wp->base);
		window_copy_update_selection(wp);
		window_copy_redraw_screen(wp);
		break;
	case MODEKEYCOPY_HISTORYBOTTOM:
		data->cx = 0;
		data->cy = screen_size_y(s) - 1;
		data->oy = 0;
		window_copy_update_selection(wp);
		window_copy_redraw_screen(wp);
		break;
	case MODEKEYCOPY_STARTSELECTION:
		window_copy_start_selection(wp);
		window_copy_redraw_screen(wp);
		break;
	case MODEKEYCOPY_CLEARSELECTION:
		window_copy_clear_selection(wp);
		window_copy_redraw_screen(wp);
		break;
	case MODEKEYCOPY_COPYSELECTION:
		if (c != NULL && c->session != NULL) {
			window_copy_copy_selection(wp, c);
			window_pane_reset_mode(wp);
		}
		break;
	case MODEKEYCOPY_STARTOFLINE:
		window_copy_cursor_start_of_line(wp);
		break;
	case MODEKEYCOPY_BACKTOINDENTATION:
		window_copy_cursor_back_to_indentation(wp);
		break;
	case MODEKEYCOPY_ENDOFLINE:
		window_copy_cursor_end_of_line(wp);
		break;
	case MODEKEYCOPY_NEXTSPACE:
		for (; np != 0; np--)
			window_copy_cursor_next_word(wp, " ");
		break;
	case MODEKEYCOPY_NEXTSPACEEND:
		for (; np != 0; np--)
			window_copy_cursor_next_word_end(wp, " ");
		break;
	case MODEKEYCOPY_NEXTWORD:
		word_separators =
		    options_get_string(&wp->window->options, "word-separators");
		for (; np != 0; np--)
			window_copy_cursor_next_word(wp, word_separators);
		break;
	case MODEKEYCOPY_NEXTWORDEND:
		word_separators =
		    options_get_string(&wp->window->options, "word-separators");
		for (; np != 0; np--)
			window_copy_cursor_next_word_end(wp, word_separators);
		break;
	case MODEKEYCOPY_PREVIOUSSPACE:
		for (; np != 0; np--)
			window_copy_cursor_previous_word(wp, " ");
		break;
	case MODEKEYCOPY_PREVIOUSWORD:
		word_separators =
		    options_get_string(&wp->window->options, "word-separators");
		for (; np != 0; np--)
			window_copy_cursor_previous_word(wp, word_separators);
		break;
	case MODEKEYCOPY_SEARCHUP:
		data->inputtype = WINDOW_COPY_SEARCHUP;
		data->inputprompt = "Search Up";
		goto input_on;
	case MODEKEYCOPY_SEARCHDOWN:
		data->inputtype = WINDOW_COPY_SEARCHDOWN;
		data->inputprompt = "Search Down";
		goto input_on;
	case MODEKEYCOPY_SEARCHAGAIN:
	case MODEKEYCOPY_SEARCHREVERSE:
		switch (data->searchtype) {
		case WINDOW_COPY_OFF:
		case WINDOW_COPY_GOTOLINE:
		case WINDOW_COPY_NUMERICPREFIX:
			break;
		case WINDOW_COPY_SEARCHUP:
			if (cmd == MODEKEYCOPY_SEARCHAGAIN) {
				for (; np != 0; np--) {
					window_copy_search_up(
					    wp, data->searchstr);
				}
			} else {
				for (; np != 0; np--) {
					window_copy_search_down(
					    wp, data->searchstr);
				}
			}
			break;
		case WINDOW_COPY_SEARCHDOWN:
			if (cmd == MODEKEYCOPY_SEARCHAGAIN) {
				for (; np != 0; np--) {
					window_copy_search_down(
					    wp, data->searchstr);
				}
			} else {
				for (; np != 0; np--) {
					window_copy_search_up(
					    wp, data->searchstr);
				}
			}
			break;
		}
		break;
	case MODEKEYCOPY_GOTOLINE:
		data->inputtype = WINDOW_COPY_GOTOLINE;
		data->inputprompt = "Goto Line";
		*data->inputstr = '\0';
		goto input_on;
	case MODEKEYCOPY_STARTNUMBERPREFIX:
		key &= 0xff;
		if (key >= '0' && key <= '9') {
			data->inputtype = WINDOW_COPY_NUMERICPREFIX;
			data->numprefix = 0;
			window_copy_key_numeric_prefix(wp, key);
			return;
		}
		break;
	case MODEKEYCOPY_RECTANGLETOGGLE:
		window_copy_rectangle_toggle(wp);
		break;
	default:
		break;
	}

	data->numprefix = 0;
	return;

input_on:
	keys = options_get_number(&wp->window->options, "mode-keys");
	if (keys == MODEKEY_EMACS)
		mode_key_init(&data->mdata, &mode_key_tree_emacs_edit);
	else
		mode_key_init(&data->mdata, &mode_key_tree_vi_edit);

	window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1);
	return;

input_off:
	keys = options_get_number(&wp->window->options, "mode-keys");
	if (keys == MODEKEY_EMACS)
		mode_key_init(&data->mdata, &mode_key_tree_emacs_copy);
	else
		mode_key_init(&data->mdata, &mode_key_tree_vi_copy);

	data->inputtype = WINDOW_COPY_OFF;
	data->inputprompt = NULL;

	window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1);
}