Beispiel #1
0
void
window_copy_scroll_up(struct window_pane *wp, u_int ny)
{
	struct window_copy_mode_data	*data = wp->modedata;
	struct screen			*s = &data->screen;
	struct screen_write_ctx		 ctx;

	if (data->oy < ny)
		ny = data->oy;
	if (ny == 0)
		return;
	data->oy -= ny;

	screen_write_start(&ctx, wp, NULL);
	screen_write_cursormove(&ctx, 0, 0);
	screen_write_deleteline(&ctx, ny);
	window_copy_write_lines(wp, &ctx, screen_size_y(s) - ny, ny);
	window_copy_write_line(wp, &ctx, 0);
	if (screen_size_y(s) > 1)
		window_copy_write_line(wp, &ctx, 1);
	if (screen_size_y(s) > 3)
		window_copy_write_line(wp, &ctx, screen_size_y(s) - 2);
	if (s->sel.flag && screen_size_y(s) > ny) {
		window_copy_update_selection(wp);
		window_copy_write_line(wp, &ctx, screen_size_y(s) - ny - 1);
	}
	screen_write_cursormove(&ctx, data->cx, data->cy);
	window_copy_update_selection(wp);
	screen_write_stop(&ctx);
}
Beispiel #2
0
void
window_copy_cursor_jump(struct window_pane *wp)
{
	struct window_copy_mode_data	*data = wp->modedata;
	struct screen			*back_s = data->backing;
	const struct grid_cell		*gc;
	uint				 px, py, xx;

	px = data->cx + 1;
	py = screen_hsize(back_s) + data->cy - data->oy;
	xx = window_copy_find_length(wp, py);

	while (px < xx) {
		gc = grid_peek_cell(back_s->grid, px, py);
		if ((gc->flags & (GRID_FLAG_PADDING|GRID_FLAG_UTF8)) == 0
		    && gc->data == data->jumpchar) {

			window_copy_update_cursor(wp, px, data->cy);
			if (window_copy_update_selection(wp))
				window_copy_redraw_lines(wp, data->cy, 1);
			return;
		}
		px++;
	}
}
Beispiel #3
0
void
window_copy_cursor_jump_back(struct window_pane *wp)
{
	struct window_copy_mode_data	*data = wp->modedata;
	struct screen			*back_s = data->backing;
	const struct grid_cell		*gc;
	uint				 px, py;

	px = data->cx;
	py = screen_hsize(back_s) + data->cy - data->oy;

	if (px > 0)
		px--;

	for (;;) {
		gc = grid_peek_cell(back_s->grid, px, py);
		if ((gc->flags & (GRID_FLAG_PADDING|GRID_FLAG_UTF8)) == 0
		    && gc->data == data->jumpchar) {

			window_copy_update_cursor(wp, px, data->cy);
			if (window_copy_update_selection(wp))
				window_copy_redraw_lines(wp, data->cy, 1);
			return;
		}
		if (px == 0)
			break;
		px--;
	}
}
Beispiel #4
0
void
window_copy_cursor_down(struct window_pane *wp, int scroll_only)
{
	struct window_copy_mode_data	*data = wp->modedata;
	struct screen			*s = &data->screen;
	u_int				 ox, oy, px, py;

	oy = screen_hsize(&wp->base) + data->cy - data->oy;
	ox = window_copy_find_length(wp, oy);
	if (ox != 0) {
		data->lastcx = data->cx;
		data->lastsx = ox;
	}

	data->cx = data->lastcx;
	if (scroll_only || data->cy == screen_size_y(s) - 1) {
		window_copy_scroll_up(wp, 1);
		if (scroll_only && data->cy > 0)
			window_copy_redraw_lines(wp, data->cy - 1, 2);
	} else {
		window_copy_update_cursor(wp, data->cx, data->cy + 1);
		if (window_copy_update_selection(wp))
			window_copy_redraw_lines(wp, data->cy - 1, 2);
	}

	if (!data->screen.sel.flag || !data->rectflag) {
		py = screen_hsize(&wp->base) + data->cy - data->oy;
		px = window_copy_find_length(wp, py);
		if ((data->cx >= data->lastsx && data->cx != px) ||
		    data->cx > px)
			window_copy_cursor_end_of_line(wp);
	}
}
Beispiel #5
0
void
window_copy_scroll_to(struct window_pane *wp, u_int px, u_int py)
{
	struct window_copy_mode_data	*data = wp->modedata;
	struct screen			*s = &wp->base;
	struct grid			*gd = s->grid;
	u_int				 offset, gap;

	data->cx = px;

	gap = gd->sy / 4;
	if (py < gd->sy) {
		offset = 0;
		data->cy = py;
	} else if (py > gd->hsize + gd->sy - gap) {
		offset = gd->hsize;
		data->cy = py - gd->hsize;
	} else {
		offset = py + gap - gd->sy;
		data->cy = py - offset;
	}
	data->oy = gd->hsize - offset;

	window_copy_update_selection(wp);
	window_copy_redraw_screen(wp);
}
Beispiel #6
0
void
window_copy_cursor_end_of_line(struct window_pane *wp)
{
	struct window_copy_mode_data	*data = wp->modedata;
	struct screen			*base_s = &wp->base;
	struct grid			*gd = base_s->grid;
	u_int				 px, py;

	py = screen_hsize(base_s) + data->cy - data->oy;
	px = window_copy_find_length(wp, py);

	if (data->cx == px) {
		if (data->screen.sel.flag && data->rectflag)
			px = screen_size_x(&wp->base);
		if (gd->linedata[py].flags & GRID_LINE_WRAPPED) {
			while (py < gd->sy + gd->hsize &&
			    gd->linedata[py].flags & GRID_LINE_WRAPPED) {
				window_copy_cursor_down(wp, 0);
				py = screen_hsize(base_s) + data->cy - data->oy;
			}
			px = window_copy_find_length(wp, py);
		}
	}
	window_copy_update_cursor(wp, px, data->cy);

	if (window_copy_update_selection(wp))
		window_copy_redraw_lines(wp, data->cy, 1);
}
Beispiel #7
0
void
window_copy_cursor_start_of_line(struct window_pane *wp)
{
	struct window_copy_mode_data	*data = wp->modedata;

	window_copy_update_cursor(wp, 0, data->cy);
	if (window_copy_update_selection(wp))
		window_copy_redraw_lines(wp, data->cy, 1);
}
Beispiel #8
0
/* ARGSUSED */
void
window_copy_mouse(
    struct window_pane *wp, unused struct session *sess, struct mouse_event *m)
{
	struct window_copy_mode_data	*data = wp->modedata;
	struct screen			*s = &data->screen;
	u_int				 i;

	if (m->x >= screen_size_x(s))
		return;
	if (m->y >= screen_size_y(s))
		return;

	/* If mouse wheel (buttons 4 and 5), scroll. */
	if ((m->b & MOUSE_45)) {
		if ((m->b & MOUSE_BUTTON) == MOUSE_1) {
			for (i = 0; i < 5; i++)
				window_copy_cursor_up(wp, 0);
		} else if ((m->b & MOUSE_BUTTON) == MOUSE_2) {
			for (i = 0; i < 5; i++)
				window_copy_cursor_down(wp, 0);
		}
		return;
	}

	/*
	 * If already reading motion, move the cursor while buttons are still
	 * pressed, or stop the selection on their release.
	 */
	if (s->mode & MODE_MOUSE_ANY) {
		if ((m->b & MOUSE_BUTTON) != MOUSE_UP) {
			window_copy_update_cursor(wp, m->x, m->y);
			if (window_copy_update_selection(wp))
				window_copy_redraw_screen(wp);
		} else {
			s->mode &= ~MODE_MOUSE_ANY;
			s->mode |= MODE_MOUSE_STANDARD;
			if (sess != NULL) {
				window_copy_copy_selection(wp);
				window_pane_reset_mode(wp);
			}
		}
		return;
	}

	/* Otherwise if other buttons pressed, start selection and motion. */
	if ((m->b & MOUSE_BUTTON) != MOUSE_UP) {
		s->mode &= ~MODE_MOUSE_STANDARD;
		s->mode |= MODE_MOUSE_ANY;

		window_copy_update_cursor(wp, m->x, m->y);
		window_copy_start_selection(wp);
		window_copy_redraw_screen(wp);
	}
}
Beispiel #9
0
void
window_copy_start_selection(struct window_pane *wp)
{
	struct window_copy_mode_data	*data = wp->modedata;
	struct screen			*s = &data->screen;

	data->selx = data->cx;
	data->sely = screen_hsize(&wp->base) + data->cy - data->oy;

	s->sel.flag = 1;
	window_copy_update_selection(wp);
}
Beispiel #10
0
void
window_copy_cursor_left(struct window_pane *wp)
{
	struct window_copy_mode_data	*data = wp->modedata;

	if (data->cx == 0) {
		window_copy_cursor_up(wp, 0);
		window_copy_cursor_end_of_line(wp);
	} else {
		window_copy_update_cursor(wp, data->cx - 1, data->cy);
		if (window_copy_update_selection(wp))
			window_copy_redraw_lines(wp, data->cy, 1);
	}
}
Beispiel #11
0
void
window_copy_goto_line(struct window_pane *wp, const char *linestr)
{
	struct window_copy_mode_data	*data = wp->modedata;
	const char			*errstr;
	u_int				 lineno;

	lineno = strtonum(linestr, 0, screen_hsize(&wp->base), &errstr);
	if (errstr != NULL)
		return;

	data->oy = lineno;
	window_copy_update_selection(wp);
	window_copy_redraw_screen(wp);
}
Beispiel #12
0
void
window_copy_rectangle_toggle(struct window_pane *wp)
{
	struct window_copy_mode_data	*data = wp->modedata;
	u_int				 px, py;

	data->rectflag = !data->rectflag;

	py = screen_hsize(&wp->base) + data->cy - data->oy;
	px = window_copy_find_length(wp, py);
	if (data->cx > px)
		window_copy_update_cursor(wp, px, data->cy);

	window_copy_update_selection(wp);
	window_copy_redraw_screen(wp);
}
Beispiel #13
0
void
window_copy_pageup(struct window_pane *wp)
{
	struct window_copy_mode_data	*data = wp->modedata;
	struct screen			*s = &data->screen;
	u_int				 n;

	n = 1;
	if (screen_size_y(s) > 2)
		n = screen_size_y(s) - 2;
	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);
}
Beispiel #14
0
/* ARGSUSED */
void
window_copy_mouse(
    struct window_pane *wp, unused struct client *c, struct mouse_event *m)
{
	struct window_copy_mode_data	*data = wp->modedata;
	struct screen			*s = &data->screen;

	if ((m->b & 3) == 3)
		return;
	if (m->x >= screen_size_x(s))
		return;
	if (m->y >= screen_size_y(s))
		return;

	window_copy_update_cursor(wp, m->x, m->y);
	if (window_copy_update_selection(wp))
		window_copy_redraw_screen(wp);
}
Beispiel #15
0
void
window_copy_cursor_start_of_line(struct window_pane *wp)
{
	struct window_copy_mode_data	*data = wp->modedata;
	struct screen			*back_s = data->backing;
	struct grid			*gd = back_s->grid;
	u_int				 py;

	if (data->cx == 0) {
		py = screen_hsize(back_s) + data->cy - data->oy;
		while (py > 0 && gd->linedata[py-1].flags & GRID_LINE_WRAPPED) {
			window_copy_cursor_up(wp, 0);
			py = screen_hsize(back_s) + data->cy - data->oy;
		}
	}
	window_copy_update_cursor(wp, 0, data->cy);
	if (window_copy_update_selection(wp))
		window_copy_redraw_lines(wp, data->cy, 1);
}
Beispiel #16
0
void
window_copy_cursor_next_word_end(struct window_pane *wp, const char *separators)
{
	struct window_copy_mode_data	*data = wp->modedata;
	struct screen			*base_s = &wp->base;
	u_int				 px, py, xx, yy;
	int				 expected = 1;

	px = data->cx;
	py = screen_hsize(base_s) + data->cy - data->oy;
	xx = window_copy_find_length(wp, py);
	yy = screen_hsize(base_s) + screen_size_y(base_s) - 1;

	/*
	 * First skip past any word characters, then any nonword characters.
	 *
	 * expected is initially set to 1 for the former and then 0 for the
	 * latter.
	 */
	do {
		while (px > xx ||
		    window_copy_in_set(wp, px, py, separators) == expected) {
			/* Move down if we're past the end of the line. */
			if (px > xx) {
				if (py == yy)
					return;
				window_copy_cursor_down(wp, 0);
				px = 0;

				py = screen_hsize(base_s) + data->cy - data->oy;
				xx = window_copy_find_length(wp, py);
			} else
				px++;
		}
		expected = !expected;
	} while (expected == 0);

	window_copy_update_cursor(wp, px, data->cy);
	if (window_copy_update_selection(wp))
		window_copy_redraw_lines(wp, data->cy, 1);
}
Beispiel #17
0
void
window_copy_cursor_right(struct window_pane *wp)
{
	struct window_copy_mode_data	*data = wp->modedata;
	u_int				 px, py;

	if (data->screen.sel.flag && data->rectflag)
		px = screen_size_x(&data->screen);
	else {
		py = screen_hsize(&wp->base) + data->cy - data->oy;
		px = window_copy_find_length(wp, py);
	}

	if (data->cx >= px) {
		window_copy_cursor_start_of_line(wp);
		window_copy_cursor_down(wp, 0);
	} else {
		window_copy_update_cursor(wp, data->cx + 1, data->cy);
		if (window_copy_update_selection(wp))
			window_copy_redraw_lines(wp, data->cy, 1);
	}
}
Beispiel #18
0
/* Move to the previous place where a word begins. */
void
window_copy_cursor_previous_word(struct window_pane *wp, const char *separators)
{
	struct window_copy_mode_data	*data = wp->modedata;
	u_int				 px, py;

	px = data->cx;
	py = screen_hsize(&wp->base) + data->cy - data->oy;

	/* Move back to the previous word character. */
	for (;;) {
		if (px > 0) {
			px--;
			if (!window_copy_in_set(wp, px, py, separators))
				break;
		} else {
			if (data->cy == 0 &&
			    (screen_hsize(&wp->base) == 0 ||
			    data->oy >= screen_hsize(&wp->base) - 1))
				goto out;
			window_copy_cursor_up(wp, 0);

			py = screen_hsize(&wp->base) + data->cy - data->oy;
			px = window_copy_find_length(wp, py);
		}
	}

	/* Move back to the beginning of this word. */
	while (px > 0 && !window_copy_in_set(wp, px - 1, py, separators))
		px--;

out:
	window_copy_update_cursor(wp, px, data->cy);
	if (window_copy_update_selection(wp))
		window_copy_redraw_lines(wp, data->cy, 1);
}
Beispiel #19
0
void
window_copy_cursor_back_to_indentation(struct window_pane *wp)
{
	struct window_copy_mode_data	*data = wp->modedata;
	u_int				 px, py, xx;
	const struct grid_cell		*gc;

	px = 0;
	py = screen_hsize(&wp->base) + data->cy - data->oy;
	xx = window_copy_find_length(wp, py);

	while (px < xx) {
		gc = grid_peek_cell(wp->base.grid, px, py);
		if (gc->flags & GRID_FLAG_UTF8)
			break;
		if (gc->data != ' ')
			break;
		px++;
	}

	window_copy_update_cursor(wp, px, data->cy);
	if (window_copy_update_selection(wp))
		window_copy_redraw_lines(wp, data->cy, 1);
}
Beispiel #20
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);
}