2011-07-03 21:51:17 +00:00
|
|
|
/* $Id$ */
|
2007-11-22 18:09:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2009-08-20 11:20:24 +00:00
|
|
|
#include <stdlib.h>
|
2007-11-22 18:09:43 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2009-01-11 23:31:46 +00:00
|
|
|
struct screen *window_copy_init(struct window_pane *);
|
|
|
|
void window_copy_free(struct window_pane *);
|
|
|
|
void window_copy_resize(struct window_pane *, u_int, u_int);
|
2010-05-22 21:56:04 +00:00
|
|
|
void window_copy_key(struct window_pane *, struct session *, int);
|
2009-08-20 11:20:24 +00:00
|
|
|
int window_copy_key_input(struct window_pane *, int);
|
2010-03-08 15:02:07 +00:00
|
|
|
int window_copy_key_numeric_prefix(struct window_pane *, int);
|
2009-01-28 22:00:22 +00:00
|
|
|
void window_copy_mouse(
|
2010-05-22 21:56:04 +00:00
|
|
|
struct window_pane *, struct session *, struct mouse_event *);
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2009-01-11 23:31:46 +00:00
|
|
|
void window_copy_redraw_lines(struct window_pane *, u_int, u_int);
|
|
|
|
void window_copy_redraw_screen(struct window_pane *);
|
2007-12-06 09:46:23 +00:00
|
|
|
void window_copy_write_line(
|
2009-12-04 22:14:47 +00:00
|
|
|
struct window_pane *, struct screen_write_ctx *, u_int);
|
2007-12-06 09:46:23 +00:00
|
|
|
void window_copy_write_lines(
|
2009-12-04 22:14:47 +00:00
|
|
|
struct window_pane *, struct screen_write_ctx *, u_int, u_int);
|
2007-12-06 09:46:23 +00:00
|
|
|
|
2009-08-20 11:20:24 +00:00
|
|
|
void window_copy_scroll_to(struct window_pane *, u_int, u_int);
|
|
|
|
int window_copy_search_compare(
|
|
|
|
struct grid *, u_int, u_int, struct grid *, u_int);
|
|
|
|
int window_copy_search_lr(
|
|
|
|
struct grid *, struct grid *, u_int *, u_int, u_int, u_int);
|
|
|
|
int window_copy_search_rl(
|
|
|
|
struct grid *, struct grid *, u_int *, u_int, u_int, u_int);
|
|
|
|
void window_copy_search_up(struct window_pane *, const char *);
|
|
|
|
void window_copy_search_down(struct window_pane *, const char *);
|
|
|
|
void window_copy_goto_line(struct window_pane *, const char *);
|
2009-08-16 19:12:07 +00:00
|
|
|
void window_copy_update_cursor(struct window_pane *, u_int, u_int);
|
2009-01-11 23:31:46 +00:00
|
|
|
void window_copy_start_selection(struct window_pane *);
|
|
|
|
int window_copy_update_selection(struct window_pane *);
|
2011-10-31 13:54:28 +00:00
|
|
|
void window_copy_copy_selection(struct window_pane *, int);
|
2010-02-26 13:29:25 +00:00
|
|
|
void window_copy_clear_selection(struct window_pane *);
|
2007-11-23 17:52:54 +00:00
|
|
|
void window_copy_copy_line(
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_pane *, char **, size_t *, u_int, u_int, u_int);
|
2010-02-05 01:34:08 +00:00
|
|
|
int window_copy_in_set(struct window_pane *, u_int, u_int, const char *);
|
2009-01-11 23:31:46 +00:00
|
|
|
u_int window_copy_find_length(struct window_pane *, u_int);
|
|
|
|
void window_copy_cursor_start_of_line(struct window_pane *);
|
2009-07-14 06:39:25 +00:00
|
|
|
void window_copy_cursor_back_to_indentation(struct window_pane *);
|
2009-01-11 23:31:46 +00:00
|
|
|
void window_copy_cursor_end_of_line(struct window_pane *);
|
|
|
|
void window_copy_cursor_left(struct window_pane *);
|
|
|
|
void window_copy_cursor_right(struct window_pane *);
|
2009-10-06 14:10:10 +00:00
|
|
|
void window_copy_cursor_up(struct window_pane *, int);
|
|
|
|
void window_copy_cursor_down(struct window_pane *, int);
|
2010-03-16 17:30:58 +00:00
|
|
|
void window_copy_cursor_jump(struct window_pane *);
|
|
|
|
void window_copy_cursor_jump_back(struct window_pane *);
|
2011-12-06 18:50:26 +00:00
|
|
|
void window_copy_cursor_jump_to(struct window_pane *);
|
|
|
|
void window_copy_cursor_jump_to_back(struct window_pane *);
|
2010-02-05 01:34:08 +00:00
|
|
|
void window_copy_cursor_next_word(struct window_pane *, const char *);
|
|
|
|
void window_copy_cursor_next_word_end(struct window_pane *, const char *);
|
|
|
|
void window_copy_cursor_previous_word(struct window_pane *, const char *);
|
2009-01-11 23:31:46 +00:00
|
|
|
void window_copy_scroll_up(struct window_pane *, u_int);
|
|
|
|
void window_copy_scroll_down(struct window_pane *, u_int);
|
2010-02-08 18:13:17 +00:00
|
|
|
void window_copy_rectangle_toggle(struct window_pane *);
|
2007-11-22 18:09:43 +00:00
|
|
|
|
|
|
|
const struct window_mode window_copy_mode = {
|
|
|
|
window_copy_init,
|
2007-12-06 09:46:23 +00:00
|
|
|
window_copy_free,
|
2007-11-22 18:09:43 +00:00
|
|
|
window_copy_resize,
|
2009-01-10 19:35:40 +00:00
|
|
|
window_copy_key,
|
2009-01-28 22:00:22 +00:00
|
|
|
window_copy_mouse,
|
2009-01-28 19:52:21 +00:00
|
|
|
NULL,
|
2007-11-22 18:09:43 +00:00
|
|
|
};
|
|
|
|
|
2009-08-20 11:20:24 +00:00
|
|
|
enum window_copy_input_type {
|
|
|
|
WINDOW_COPY_OFF,
|
2010-03-08 15:02:07 +00:00
|
|
|
WINDOW_COPY_NUMERICPREFIX,
|
2009-08-20 11:20:24 +00:00
|
|
|
WINDOW_COPY_SEARCHUP,
|
|
|
|
WINDOW_COPY_SEARCHDOWN,
|
2010-03-16 17:30:58 +00:00
|
|
|
WINDOW_COPY_JUMPFORWARD,
|
|
|
|
WINDOW_COPY_JUMPBACK,
|
2011-12-06 18:50:26 +00:00
|
|
|
WINDOW_COPY_JUMPTOFORWARD,
|
|
|
|
WINDOW_COPY_JUMPTOBACK,
|
2009-08-20 11:20:24 +00:00
|
|
|
WINDOW_COPY_GOTOLINE,
|
|
|
|
};
|
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
/*
|
|
|
|
* Copy-mode's visible screen (the "screen" field) is filled from one of
|
|
|
|
* two sources: the original contents of the pane (used when we
|
|
|
|
* actually enter via the "copy-mode" command, to copy the contents of
|
|
|
|
* the current pane), or else a series of lines containing the output
|
|
|
|
* from an output-writing tmux command (such as any of the "show-*" or
|
|
|
|
* "list-*" commands).
|
|
|
|
*
|
|
|
|
* In either case, the full content of the copy-mode grid is pointed at
|
|
|
|
* by the "backing" field, and is copied into "screen" as needed (that
|
|
|
|
* is, when scrolling occurs). When copy-mode is backed by a pane,
|
|
|
|
* backing points directly at that pane's screen structure (&wp->base);
|
|
|
|
* when backed by a list of output-lines from a command, it points at
|
|
|
|
* a newly-allocated screen structure (which is deallocated when the
|
|
|
|
* mode ends).
|
|
|
|
*/
|
2007-11-22 18:09:43 +00:00
|
|
|
struct window_copy_mode_data {
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen screen;
|
|
|
|
|
2010-04-06 21:45:36 +00:00
|
|
|
struct screen *backing;
|
|
|
|
int backing_written; /* backing display has started */
|
|
|
|
|
2010-04-06 22:02:52 +00:00
|
|
|
struct mode_key_data mdata;
|
2009-08-20 11:20:24 +00:00
|
|
|
|
|
|
|
u_int oy;
|
|
|
|
|
|
|
|
u_int selx;
|
|
|
|
u_int sely;
|
2009-02-13 21:39:45 +00:00
|
|
|
|
2010-02-08 18:13:17 +00:00
|
|
|
u_int rectflag; /* are we in rectangle copy mode? */
|
|
|
|
|
2009-08-20 11:20:24 +00:00
|
|
|
u_int cx;
|
|
|
|
u_int cy;
|
2007-11-22 19:17:01 +00:00
|
|
|
|
2009-08-21 21:12:07 +00:00
|
|
|
u_int lastcx; /* position in last line with content */
|
|
|
|
u_int lastsx; /* size of last line with content */
|
|
|
|
|
2009-08-20 11:20:24 +00:00
|
|
|
enum window_copy_input_type inputtype;
|
|
|
|
const char *inputprompt;
|
2011-12-06 18:50:26 +00:00
|
|
|
char *inputstr;
|
2008-06-18 22:21:51 +00:00
|
|
|
|
2011-10-31 13:54:28 +00:00
|
|
|
int numprefix;
|
2010-03-08 15:02:07 +00:00
|
|
|
|
2009-08-20 11:20:24 +00:00
|
|
|
enum window_copy_input_type searchtype;
|
|
|
|
char *searchstr;
|
2010-03-16 17:30:58 +00:00
|
|
|
|
|
|
|
enum window_copy_input_type jumptype;
|
|
|
|
char jumpchar;
|
2007-11-22 18:09:43 +00:00
|
|
|
};
|
|
|
|
|
2007-12-06 10:04:43 +00:00
|
|
|
struct screen *
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_init(struct window_pane *wp)
|
2007-11-22 18:09:43 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s;
|
2009-07-28 22:55:59 +00:00
|
|
|
int keys;
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2009-01-11 23:31:46 +00:00
|
|
|
wp->modedata = data = xmalloc(sizeof *data);
|
2007-12-06 09:46:23 +00:00
|
|
|
data->oy = 0;
|
2010-04-05 05:11:44 +00:00
|
|
|
data->cx = 0;
|
|
|
|
data->cy = 0;
|
2007-12-06 09:46:23 +00:00
|
|
|
|
2009-08-21 21:12:07 +00:00
|
|
|
data->lastcx = 0;
|
|
|
|
data->lastsx = 0;
|
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
data->backing_written = 0;
|
|
|
|
|
2010-02-08 18:13:17 +00:00
|
|
|
data->rectflag = 0;
|
|
|
|
|
2009-08-20 11:20:24 +00:00
|
|
|
data->inputtype = WINDOW_COPY_OFF;
|
|
|
|
data->inputprompt = NULL;
|
|
|
|
data->inputstr = xstrdup("");
|
2011-10-31 13:54:28 +00:00
|
|
|
data->numprefix = -1;
|
2009-08-20 11:20:24 +00:00
|
|
|
|
|
|
|
data->searchtype = WINDOW_COPY_OFF;
|
|
|
|
data->searchstr = NULL;
|
|
|
|
|
2010-07-22 19:51:48 +00:00
|
|
|
if (wp->fd != -1)
|
|
|
|
bufferevent_disable(wp->event, EV_READ|EV_WRITE);
|
2010-02-26 13:26:44 +00:00
|
|
|
|
2010-03-16 17:30:58 +00:00
|
|
|
data->jumptype = WINDOW_COPY_OFF;
|
|
|
|
data->jumpchar = '\0';
|
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
s = &data->screen;
|
2009-01-11 23:31:46 +00:00
|
|
|
screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
|
2009-07-30 20:32:05 +00:00
|
|
|
if (options_get_number(&wp->window->options, "mode-mouse"))
|
2010-12-30 22:27:38 +00:00
|
|
|
s->mode |= MODE_MOUSE_STANDARD;
|
2009-01-28 22:00:22 +00:00
|
|
|
|
2009-07-28 22:55:59 +00:00
|
|
|
keys = options_get_number(&wp->window->options, "mode-keys");
|
|
|
|
if (keys == MODEKEY_EMACS)
|
2009-07-28 23:11:18 +00:00
|
|
|
mode_key_init(&data->mdata, &mode_key_tree_emacs_copy);
|
2009-07-28 22:55:59 +00:00
|
|
|
else
|
2009-07-28 23:11:18 +00:00
|
|
|
mode_key_init(&data->mdata, &mode_key_tree_vi_copy);
|
2009-02-13 21:39:45 +00:00
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
data->backing = NULL;
|
|
|
|
|
|
|
|
return (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_init_from_pane(struct window_pane *wp)
|
|
|
|
{
|
2010-04-06 21:45:36 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
2010-04-05 05:11:44 +00:00
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
if (wp->mode != &window_copy_mode)
|
|
|
|
fatalx("not in copy mode");
|
|
|
|
|
|
|
|
data->backing = &wp->base;
|
|
|
|
data->cx = data->backing->cx;
|
|
|
|
data->cy = data->backing->cy;
|
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
s->cx = data->cx;
|
|
|
|
s->cy = data->cy;
|
|
|
|
|
2009-01-11 23:31:46 +00:00
|
|
|
screen_write_start(&ctx, NULL, s);
|
2007-12-06 09:46:23 +00:00
|
|
|
for (i = 0; i < screen_size_y(s); i++)
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_write_line(wp, &ctx, i);
|
2008-09-25 20:08:57 +00:00
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
2007-12-06 09:46:23 +00:00
|
|
|
screen_write_stop(&ctx);
|
2010-04-05 05:11:44 +00:00
|
|
|
}
|
2007-12-06 10:04:43 +00:00
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
void
|
|
|
|
window_copy_init_for_output(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
|
|
|
|
data->backing = xmalloc(sizeof *data->backing);
|
|
|
|
screen_init(data->backing, screen_size_x(&wp->base),
|
|
|
|
screen_size_y(&wp->base), UINT_MAX);
|
|
|
|
data->backing->mode &= ~MODE_WRAP;
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_free(struct window_pane *wp)
|
2007-11-22 18:09:43 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2010-07-22 19:51:48 +00:00
|
|
|
if (wp->fd != -1)
|
|
|
|
bufferevent_enable(wp->event, EV_READ|EV_WRITE);
|
2010-02-26 13:26:44 +00:00
|
|
|
|
2012-07-11 19:34:16 +00:00
|
|
|
free(data->searchstr);
|
|
|
|
free(data->inputstr);
|
2009-08-20 11:20:24 +00:00
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
if (data->backing != &wp->base) {
|
|
|
|
screen_free(data->backing);
|
2012-07-11 19:34:16 +00:00
|
|
|
free(data->backing);
|
2010-04-05 05:11:44 +00:00
|
|
|
}
|
2008-09-10 19:15:06 +00:00
|
|
|
screen_free(&data->screen);
|
2009-08-20 11:20:24 +00:00
|
|
|
|
2012-07-11 19:34:16 +00:00
|
|
|
free(data);
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
void
|
|
|
|
window_copy_add(struct window_pane *wp, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
window_copy_vadd(wp, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_vadd(struct window_pane *wp, const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *backing = data->backing;
|
|
|
|
struct screen_write_ctx back_ctx, ctx;
|
|
|
|
struct grid_cell gc;
|
|
|
|
int utf8flag;
|
|
|
|
u_int old_hsize;
|
|
|
|
|
|
|
|
if (backing == &wp->base)
|
|
|
|
return;
|
|
|
|
|
|
|
|
utf8flag = options_get_number(&wp->window->options, "utf8");
|
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
|
|
|
|
|
|
|
old_hsize = screen_hsize(data->backing);
|
|
|
|
screen_write_start(&back_ctx, NULL, backing);
|
|
|
|
if (data->backing_written) {
|
|
|
|
/*
|
|
|
|
* On the second or later line, do a CRLF before writing
|
|
|
|
* (so it's on a new line).
|
|
|
|
*/
|
|
|
|
screen_write_carriagereturn(&back_ctx);
|
|
|
|
screen_write_linefeed(&back_ctx, 0);
|
|
|
|
} else
|
2010-04-06 21:45:36 +00:00
|
|
|
data->backing_written = 1;
|
2010-04-05 05:11:44 +00:00
|
|
|
screen_write_vnputs(&back_ctx, 0, &gc, utf8flag, fmt, ap);
|
|
|
|
screen_write_stop(&back_ctx);
|
|
|
|
|
|
|
|
data->oy += screen_hsize(data->backing) - old_hsize;
|
|
|
|
|
|
|
|
screen_write_start(&ctx, wp, &data->screen);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the history has changed, draw the top line.
|
|
|
|
* (If there's any history at all, it has changed.)
|
|
|
|
*/
|
|
|
|
if (screen_hsize(data->backing))
|
|
|
|
window_copy_redraw_lines(wp, 0, 1);
|
|
|
|
|
|
|
|
/* Write the line, if it's visible. */
|
|
|
|
if (backing->cy + data->oy < screen_size_y(backing))
|
|
|
|
window_copy_redraw_lines(wp, backing->cy, 1);
|
|
|
|
|
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|
|
|
|
|
2009-01-27 23:35:44 +00:00
|
|
|
void
|
|
|
|
window_copy_pageup(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
2009-08-16 19:23:07 +00:00
|
|
|
u_int n;
|
2009-05-04 17:58:27 +00:00
|
|
|
|
2009-08-16 19:23:07 +00:00
|
|
|
n = 1;
|
|
|
|
if (screen_size_y(s) > 2)
|
|
|
|
n = screen_size_y(s) - 2;
|
2010-04-05 05:11:44 +00:00
|
|
|
if (data->oy + n > screen_hsize(data->backing))
|
|
|
|
data->oy = screen_hsize(data->backing);
|
2009-01-27 23:35:44 +00:00
|
|
|
else
|
2009-08-16 19:23:07 +00:00
|
|
|
data->oy += n;
|
2009-01-27 23:35:44 +00:00
|
|
|
window_copy_update_selection(wp);
|
|
|
|
window_copy_redraw_screen(wp);
|
|
|
|
}
|
2009-05-04 17:58:27 +00:00
|
|
|
|
2007-11-22 18:09:43 +00:00
|
|
|
void
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_resize(struct window_pane *wp, u_int sx, u_int sy)
|
2007-11-22 18:09:43 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s = &data->screen;
|
2008-09-25 20:08:57 +00:00
|
|
|
struct screen_write_ctx ctx;
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2013-02-05 11:08:59 +00:00
|
|
|
screen_resize(s, sx, sy, 0);
|
2010-04-05 05:11:44 +00:00
|
|
|
if (data->backing != &wp->base)
|
2013-02-05 11:08:59 +00:00
|
|
|
screen_resize(data->backing, sx, sy, 0);
|
2009-12-04 22:14:47 +00:00
|
|
|
|
2009-08-16 19:12:07 +00:00
|
|
|
if (data->cy > sy - 1)
|
|
|
|
data->cy = sy - 1;
|
|
|
|
if (data->cx > sx)
|
|
|
|
data->cx = sx;
|
2010-09-18 15:41:18 +00:00
|
|
|
if (data->oy > screen_hsize(data->backing))
|
|
|
|
data->oy = screen_hsize(data->backing);
|
2009-08-16 19:12:07 +00:00
|
|
|
|
2010-02-26 13:29:25 +00:00
|
|
|
window_copy_clear_selection(wp);
|
2009-08-16 19:12:07 +00:00
|
|
|
|
2009-01-11 23:31:46 +00:00
|
|
|
screen_write_start(&ctx, NULL, s);
|
|
|
|
window_copy_write_lines(wp, &ctx, 0, screen_size_y(s) - 1);
|
2008-09-25 20:08:57 +00:00
|
|
|
screen_write_stop(&ctx);
|
2009-08-16 19:12:07 +00:00
|
|
|
|
2009-08-14 21:33:42 +00:00
|
|
|
window_copy_redraw_screen(wp);
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-22 21:56:04 +00:00
|
|
|
window_copy_key(struct window_pane *wp, struct session *sess, int key)
|
2007-11-22 18:09:43 +00:00
|
|
|
{
|
2010-02-26 13:31:39 +00:00
|
|
|
const char *word_separators;
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s = &data->screen;
|
2011-10-31 13:54:28 +00:00
|
|
|
u_int n;
|
|
|
|
int np, keys;
|
2010-02-18 12:35:16 +00:00
|
|
|
enum mode_key_cmd cmd;
|
2009-08-20 11:20:24 +00:00
|
|
|
|
2010-03-08 15:02:07 +00:00
|
|
|
np = data->numprefix;
|
2011-10-31 13:54:28 +00:00
|
|
|
if (np <= 0)
|
2010-03-08 15:02:07 +00:00
|
|
|
np = 1;
|
|
|
|
|
2011-04-06 22:18:56 +00:00
|
|
|
if (data->inputtype == WINDOW_COPY_JUMPFORWARD ||
|
2011-12-06 18:50:26 +00:00
|
|
|
data->inputtype == WINDOW_COPY_JUMPBACK ||
|
|
|
|
data->inputtype == WINDOW_COPY_JUMPTOFORWARD ||
|
|
|
|
data->inputtype == WINDOW_COPY_JUMPTOBACK) {
|
2010-03-16 17:30:58 +00:00
|
|
|
/* Ignore keys with modifiers. */
|
2010-06-05 20:29:11 +00:00
|
|
|
if ((key & KEYC_MASK_MOD) == 0) {
|
2010-03-16 17:30:58 +00:00
|
|
|
data->jumpchar = key;
|
|
|
|
if (data->inputtype == WINDOW_COPY_JUMPFORWARD) {
|
2010-03-16 17:51:32 +00:00
|
|
|
for (; np != 0; np--)
|
2010-03-16 17:30:58 +00:00
|
|
|
window_copy_cursor_jump(wp);
|
2011-12-06 18:50:26 +00:00
|
|
|
} else if (data->inputtype == WINDOW_COPY_JUMPBACK) {
|
2010-03-16 17:51:32 +00:00
|
|
|
for (; np != 0; np--)
|
2010-03-16 17:30:58 +00:00
|
|
|
window_copy_cursor_jump_back(wp);
|
2011-12-06 18:50:26 +00:00
|
|
|
} else if (data->inputtype == WINDOW_COPY_JUMPTOFORWARD) {
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to(wp);
|
|
|
|
} else if (data->inputtype == WINDOW_COPY_JUMPTOBACK) {
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to_back(wp);
|
2010-03-16 17:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
data->jumptype = data->inputtype;
|
|
|
|
data->inputtype = WINDOW_COPY_OFF;
|
|
|
|
window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1);
|
|
|
|
return;
|
2011-04-06 22:18:56 +00:00
|
|
|
} else if (data->inputtype == WINDOW_COPY_NUMERICPREFIX) {
|
2010-03-08 15:02:07 +00:00
|
|
|
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) {
|
2009-08-20 11:20:24 +00:00
|
|
|
if (window_copy_key_input(wp, key) != 0)
|
|
|
|
goto input_off;
|
|
|
|
return;
|
|
|
|
}
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2010-02-18 12:35:16 +00:00
|
|
|
cmd = mode_key_lookup(&data->mdata, key);
|
|
|
|
switch (cmd) {
|
2009-07-28 22:58:20 +00:00
|
|
|
case MODEKEYCOPY_CANCEL:
|
2010-03-14 23:17:59 +00:00
|
|
|
window_pane_reset_mode(wp);
|
|
|
|
return;
|
2009-07-28 22:55:59 +00:00
|
|
|
case MODEKEYCOPY_LEFT:
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_left(wp);
|
|
|
|
break;
|
2009-07-28 22:55:59 +00:00
|
|
|
case MODEKEYCOPY_RIGHT:
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_right(wp);
|
|
|
|
break;
|
2009-07-28 22:55:59 +00:00
|
|
|
case MODEKEYCOPY_UP:
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_up(wp, 0);
|
|
|
|
break;
|
2009-07-28 22:55:59 +00:00
|
|
|
case MODEKEYCOPY_DOWN:
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_down(wp, 0);
|
|
|
|
break;
|
2009-10-06 14:10:10 +00:00
|
|
|
case MODEKEYCOPY_SCROLLUP:
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_up(wp, 1);
|
2009-10-06 14:10:10 +00:00
|
|
|
break;
|
|
|
|
case MODEKEYCOPY_SCROLLDOWN:
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_down(wp, 1);
|
2009-10-06 14:10:10 +00:00
|
|
|
break;
|
2009-07-28 22:55:59 +00:00
|
|
|
case MODEKEYCOPY_PREVIOUSPAGE:
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_pageup(wp);
|
2007-11-22 18:09:43 +00:00
|
|
|
break;
|
2009-07-28 22:55:59 +00:00
|
|
|
case MODEKEYCOPY_NEXTPAGE:
|
2009-08-16 19:23:07 +00:00
|
|
|
n = 1;
|
|
|
|
if (screen_size_y(s) > 2)
|
|
|
|
n = screen_size_y(s) - 2;
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--) {
|
|
|
|
if (data->oy < n)
|
|
|
|
data->oy = 0;
|
|
|
|
else
|
|
|
|
data->oy -= n;
|
|
|
|
}
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_update_selection(wp);
|
|
|
|
window_copy_redraw_screen(wp);
|
2007-11-22 18:09:43 +00:00
|
|
|
break;
|
2009-08-16 19:26:49 +00:00
|
|
|
case MODEKEYCOPY_HALFPAGEUP:
|
|
|
|
n = screen_size_y(s) / 2;
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--) {
|
2010-04-05 05:11:44 +00:00
|
|
|
if (data->oy + n > screen_hsize(data->backing))
|
|
|
|
data->oy = screen_hsize(data->backing);
|
2010-03-08 15:02:07 +00:00
|
|
|
else
|
|
|
|
data->oy += n;
|
|
|
|
}
|
2009-08-16 19:26:49 +00:00
|
|
|
window_copy_update_selection(wp);
|
|
|
|
window_copy_redraw_screen(wp);
|
|
|
|
break;
|
|
|
|
case MODEKEYCOPY_HALFPAGEDOWN:
|
|
|
|
n = screen_size_y(s) / 2;
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--) {
|
|
|
|
if (data->oy < n)
|
|
|
|
data->oy = 0;
|
|
|
|
else
|
|
|
|
data->oy -= n;
|
|
|
|
}
|
2009-08-16 19:26:49 +00:00
|
|
|
window_copy_update_selection(wp);
|
|
|
|
window_copy_redraw_screen(wp);
|
|
|
|
break;
|
2009-10-15 01:52:47 +00:00
|
|
|
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;
|
2010-01-28 22:41:45 +00:00
|
|
|
case MODEKEYCOPY_HISTORYTOP:
|
|
|
|
data->cx = 0;
|
|
|
|
data->cy = 0;
|
2010-04-05 05:11:44 +00:00
|
|
|
data->oy = screen_hsize(data->backing);
|
2010-01-28 22:41:45 +00:00
|
|
|
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;
|
2009-07-28 22:55:59 +00:00
|
|
|
case MODEKEYCOPY_STARTSELECTION:
|
2009-12-04 22:14:47 +00:00
|
|
|
window_copy_start_selection(wp);
|
2009-07-23 23:37:14 +00:00
|
|
|
window_copy_redraw_screen(wp);
|
2007-11-22 19:17:01 +00:00
|
|
|
break;
|
2011-05-18 20:35:36 +00:00
|
|
|
case MODEKEYCOPY_COPYLINE:
|
|
|
|
case MODEKEYCOPY_SELECTLINE:
|
|
|
|
window_copy_cursor_start_of_line(wp);
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case MODEKEYCOPY_COPYENDOFLINE:
|
|
|
|
window_copy_start_selection(wp);
|
|
|
|
for (; np > 1; np--)
|
|
|
|
window_copy_cursor_down(wp, 0);
|
|
|
|
window_copy_cursor_end_of_line(wp);
|
|
|
|
window_copy_redraw_screen(wp);
|
|
|
|
|
|
|
|
/* If a copy command then copy the selection and exit. */
|
|
|
|
if (sess != NULL &&
|
|
|
|
(cmd == MODEKEYCOPY_COPYLINE ||
|
|
|
|
cmd == MODEKEYCOPY_COPYENDOFLINE)) {
|
2011-10-31 13:54:28 +00:00
|
|
|
window_copy_copy_selection(wp, -1);
|
2011-05-18 20:35:36 +00:00
|
|
|
window_pane_reset_mode(wp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2009-07-28 22:55:59 +00:00
|
|
|
case MODEKEYCOPY_CLEARSELECTION:
|
2010-02-26 13:29:25 +00:00
|
|
|
window_copy_clear_selection(wp);
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_redraw_screen(wp);
|
2007-12-06 09:46:23 +00:00
|
|
|
break;
|
2009-07-28 22:55:59 +00:00
|
|
|
case MODEKEYCOPY_COPYSELECTION:
|
2010-05-22 21:56:04 +00:00
|
|
|
if (sess != NULL) {
|
2011-10-31 13:54:28 +00:00
|
|
|
window_copy_copy_selection(wp, data->numprefix);
|
2009-01-11 23:31:46 +00:00
|
|
|
window_pane_reset_mode(wp);
|
2010-03-14 23:17:59 +00:00
|
|
|
return;
|
2008-06-20 17:31:48 +00:00
|
|
|
}
|
2007-12-06 09:46:23 +00:00
|
|
|
break;
|
2009-07-28 22:55:59 +00:00
|
|
|
case MODEKEYCOPY_STARTOFLINE:
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_cursor_start_of_line(wp);
|
2007-12-06 09:46:23 +00:00
|
|
|
break;
|
2009-07-28 22:55:59 +00:00
|
|
|
case MODEKEYCOPY_BACKTOINDENTATION:
|
2009-07-14 06:39:25 +00:00
|
|
|
window_copy_cursor_back_to_indentation(wp);
|
|
|
|
break;
|
2009-07-28 22:55:59 +00:00
|
|
|
case MODEKEYCOPY_ENDOFLINE:
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_cursor_end_of_line(wp);
|
2007-12-06 09:46:23 +00:00
|
|
|
break;
|
2010-02-05 01:34:08 +00:00
|
|
|
case MODEKEYCOPY_NEXTSPACE:
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_next_word(wp, " ");
|
2010-02-05 01:34:08 +00:00
|
|
|
break;
|
|
|
|
case MODEKEYCOPY_NEXTSPACEEND:
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_next_word_end(wp, " ");
|
2010-02-05 01:34:08 +00:00
|
|
|
break;
|
2009-07-28 22:55:59 +00:00
|
|
|
case MODEKEYCOPY_NEXTWORD:
|
2010-02-26 13:31:39 +00:00
|
|
|
word_separators =
|
2011-11-25 13:33:04 +00:00
|
|
|
options_get_string(&sess->options, "word-separators");
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_next_word(wp, word_separators);
|
2008-06-24 07:00:39 +00:00
|
|
|
break;
|
2010-01-28 22:45:57 +00:00
|
|
|
case MODEKEYCOPY_NEXTWORDEND:
|
2010-02-26 13:31:39 +00:00
|
|
|
word_separators =
|
2011-11-25 13:33:04 +00:00
|
|
|
options_get_string(&sess->options, "word-separators");
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_next_word_end(wp, word_separators);
|
2010-02-05 01:34:08 +00:00
|
|
|
break;
|
|
|
|
case MODEKEYCOPY_PREVIOUSSPACE:
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_previous_word(wp, " ");
|
2010-01-28 22:45:57 +00:00
|
|
|
break;
|
2009-07-28 22:55:59 +00:00
|
|
|
case MODEKEYCOPY_PREVIOUSWORD:
|
2010-02-26 13:31:39 +00:00
|
|
|
word_separators =
|
2011-11-25 13:33:04 +00:00
|
|
|
options_get_string(&sess->options, "word-separators");
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_previous_word(wp, word_separators);
|
2008-06-24 07:00:39 +00:00
|
|
|
break;
|
2010-03-16 17:30:58 +00:00
|
|
|
case MODEKEYCOPY_JUMP:
|
|
|
|
data->inputtype = WINDOW_COPY_JUMPFORWARD;
|
|
|
|
data->inputprompt = "Jump Forward";
|
|
|
|
*data->inputstr = '\0';
|
|
|
|
window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1);
|
|
|
|
return; /* skip numprefix reset */
|
|
|
|
case MODEKEYCOPY_JUMPAGAIN:
|
|
|
|
if (data->jumptype == WINDOW_COPY_JUMPFORWARD) {
|
2010-03-16 17:51:32 +00:00
|
|
|
for (; np != 0; np--)
|
2010-03-16 17:30:58 +00:00
|
|
|
window_copy_cursor_jump(wp);
|
|
|
|
} else if (data->jumptype == WINDOW_COPY_JUMPBACK) {
|
2010-03-16 17:51:32 +00:00
|
|
|
for (; np != 0; np--)
|
2010-03-16 17:30:58 +00:00
|
|
|
window_copy_cursor_jump_back(wp);
|
2011-12-06 18:50:26 +00:00
|
|
|
} else if (data->jumptype == WINDOW_COPY_JUMPTOFORWARD) {
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to(wp);
|
|
|
|
} else if (data->jumptype == WINDOW_COPY_JUMPTOBACK) {
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to_back(wp);
|
2010-03-16 17:30:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODEKEYCOPY_JUMPREVERSE:
|
|
|
|
if (data->jumptype == WINDOW_COPY_JUMPFORWARD) {
|
2010-03-16 17:51:32 +00:00
|
|
|
for (; np != 0; np--)
|
2010-03-16 17:30:58 +00:00
|
|
|
window_copy_cursor_jump_back(wp);
|
|
|
|
} else if (data->jumptype == WINDOW_COPY_JUMPBACK) {
|
2010-03-16 17:51:32 +00:00
|
|
|
for (; np != 0; np--)
|
2010-03-16 17:30:58 +00:00
|
|
|
window_copy_cursor_jump(wp);
|
2011-12-06 18:50:26 +00:00
|
|
|
} else if (data->jumptype == WINDOW_COPY_JUMPTOFORWARD) {
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to_back(wp);
|
|
|
|
} else if (data->jumptype == WINDOW_COPY_JUMPTOBACK) {
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to(wp);
|
2010-03-16 17:30:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODEKEYCOPY_JUMPBACK:
|
|
|
|
data->inputtype = WINDOW_COPY_JUMPBACK;
|
|
|
|
data->inputprompt = "Jump Back";
|
|
|
|
*data->inputstr = '\0';
|
|
|
|
window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1);
|
|
|
|
return; /* skip numprefix reset */
|
2011-12-06 18:50:26 +00:00
|
|
|
case MODEKEYCOPY_JUMPTO:
|
|
|
|
data->inputtype = WINDOW_COPY_JUMPTOFORWARD;
|
|
|
|
data->inputprompt = "Jump To";
|
|
|
|
*data->inputstr = '\0';
|
|
|
|
window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1);
|
|
|
|
return; /* skip numprefix reset */
|
|
|
|
case MODEKEYCOPY_JUMPTOBACK:
|
|
|
|
data->inputtype = WINDOW_COPY_JUMPTOBACK;
|
|
|
|
data->inputprompt = "Jump To Back";
|
|
|
|
*data->inputstr = '\0';
|
|
|
|
window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1);
|
|
|
|
return; /* skip numprefix reset */
|
2009-08-20 11:20:24 +00:00
|
|
|
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:
|
2010-02-18 12:35:16 +00:00
|
|
|
case MODEKEYCOPY_SEARCHREVERSE:
|
2009-08-20 11:20:24 +00:00
|
|
|
switch (data->searchtype) {
|
|
|
|
case WINDOW_COPY_OFF:
|
|
|
|
case WINDOW_COPY_GOTOLINE:
|
2010-03-16 17:30:58 +00:00
|
|
|
case WINDOW_COPY_JUMPFORWARD:
|
|
|
|
case WINDOW_COPY_JUMPBACK:
|
2011-12-06 18:50:26 +00:00
|
|
|
case WINDOW_COPY_JUMPTOFORWARD:
|
|
|
|
case WINDOW_COPY_JUMPTOBACK:
|
2010-03-08 15:02:07 +00:00
|
|
|
case WINDOW_COPY_NUMERICPREFIX:
|
2009-08-20 11:20:24 +00:00
|
|
|
break;
|
|
|
|
case WINDOW_COPY_SEARCHUP:
|
2010-03-08 15:02:07 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2009-08-20 11:20:24 +00:00
|
|
|
break;
|
|
|
|
case WINDOW_COPY_SEARCHDOWN:
|
2010-03-08 15:02:07 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2009-08-20 11:20:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODEKEYCOPY_GOTOLINE:
|
|
|
|
data->inputtype = WINDOW_COPY_GOTOLINE;
|
|
|
|
data->inputprompt = "Goto Line";
|
|
|
|
*data->inputstr = '\0';
|
|
|
|
goto input_on;
|
2010-03-08 15:02:07 +00:00
|
|
|
case MODEKEYCOPY_STARTNUMBERPREFIX:
|
2010-06-05 20:29:11 +00:00
|
|
|
key &= KEYC_MASK_KEY;
|
2010-03-08 15:02:07 +00:00
|
|
|
if (key >= '0' && key <= '9') {
|
|
|
|
data->inputtype = WINDOW_COPY_NUMERICPREFIX;
|
|
|
|
data->numprefix = 0;
|
|
|
|
window_copy_key_numeric_prefix(wp, key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2010-02-08 18:13:17 +00:00
|
|
|
case MODEKEYCOPY_RECTANGLETOGGLE:
|
|
|
|
window_copy_rectangle_toggle(wp);
|
2010-03-08 15:02:07 +00:00
|
|
|
break;
|
2009-08-20 11:20:24 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-31 13:54:28 +00:00
|
|
|
data->numprefix = -1;
|
2009-08-20 11:20:24 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
window_copy_key_input(struct window_pane *wp, int key)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
size_t inputlen;
|
2011-10-31 13:54:28 +00:00
|
|
|
int np;
|
2009-08-20 11:20:24 +00:00
|
|
|
|
|
|
|
switch (mode_key_lookup(&data->mdata, key)) {
|
|
|
|
case MODEKEYEDIT_CANCEL:
|
2011-10-31 13:54:28 +00:00
|
|
|
data->numprefix = -1;
|
2009-08-20 11:20:24 +00:00
|
|
|
return (-1);
|
|
|
|
case MODEKEYEDIT_BACKSPACE:
|
|
|
|
inputlen = strlen(data->inputstr);
|
|
|
|
if (inputlen > 0)
|
|
|
|
data->inputstr[inputlen - 1] = '\0';
|
|
|
|
break;
|
2009-08-20 11:22:48 +00:00
|
|
|
case MODEKEYEDIT_DELETELINE:
|
|
|
|
*data->inputstr = '\0';
|
|
|
|
break;
|
2009-08-20 11:20:24 +00:00
|
|
|
case MODEKEYEDIT_ENTER:
|
2010-03-08 15:02:07 +00:00
|
|
|
np = data->numprefix;
|
2011-10-31 13:54:28 +00:00
|
|
|
if (np <= 0)
|
2010-03-08 15:02:07 +00:00
|
|
|
np = 1;
|
|
|
|
|
2009-08-20 11:20:24 +00:00
|
|
|
switch (data->inputtype) {
|
|
|
|
case WINDOW_COPY_OFF:
|
2010-03-16 17:30:58 +00:00
|
|
|
case WINDOW_COPY_JUMPFORWARD:
|
|
|
|
case WINDOW_COPY_JUMPBACK:
|
2011-12-06 18:50:26 +00:00
|
|
|
case WINDOW_COPY_JUMPTOFORWARD:
|
|
|
|
case WINDOW_COPY_JUMPTOBACK:
|
2010-03-08 15:02:07 +00:00
|
|
|
case WINDOW_COPY_NUMERICPREFIX:
|
2009-08-20 11:20:24 +00:00
|
|
|
break;
|
|
|
|
case WINDOW_COPY_SEARCHUP:
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_search_up(wp, data->inputstr);
|
2009-08-20 11:20:24 +00:00
|
|
|
data->searchtype = data->inputtype;
|
|
|
|
data->searchstr = xstrdup(data->inputstr);
|
|
|
|
break;
|
|
|
|
case WINDOW_COPY_SEARCHDOWN:
|
2010-03-08 15:02:07 +00:00
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_search_down(wp, data->inputstr);
|
2009-08-20 11:20:24 +00:00
|
|
|
data->searchtype = data->inputtype;
|
|
|
|
data->searchstr = xstrdup(data->inputstr);
|
|
|
|
break;
|
|
|
|
case WINDOW_COPY_GOTOLINE:
|
|
|
|
window_copy_goto_line(wp, data->inputstr);
|
|
|
|
*data->inputstr = '\0';
|
|
|
|
break;
|
|
|
|
}
|
2011-10-31 13:54:28 +00:00
|
|
|
data->numprefix = -1;
|
2009-08-20 11:20:24 +00:00
|
|
|
return (1);
|
|
|
|
case MODEKEY_OTHER:
|
|
|
|
if (key < 32 || key > 126)
|
|
|
|
break;
|
|
|
|
inputlen = strlen(data->inputstr) + 2;
|
2009-12-04 22:14:47 +00:00
|
|
|
|
2009-08-20 11:20:24 +00:00
|
|
|
data->inputstr = xrealloc(data->inputstr, 1, inputlen);
|
|
|
|
data->inputstr[inputlen - 2] = key;
|
|
|
|
data->inputstr[inputlen - 1] = '\0';
|
|
|
|
break;
|
2008-07-02 21:22:57 +00:00
|
|
|
default:
|
|
|
|
break;
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
2009-08-20 11:20:24 +00:00
|
|
|
|
|
|
|
window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1);
|
|
|
|
return (0);
|
2007-12-06 09:46:23 +00:00
|
|
|
}
|
|
|
|
|
2010-03-08 15:02:07 +00:00
|
|
|
int
|
|
|
|
window_copy_key_numeric_prefix(struct window_pane *wp, int key)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
|
2010-06-05 20:29:11 +00:00
|
|
|
key &= KEYC_MASK_KEY;
|
2010-03-08 15:02:07 +00:00
|
|
|
if (key < '0' || key > '9')
|
2012-04-10 09:54:29 +00:00
|
|
|
return (1);
|
2010-03-08 15:02:07 +00:00
|
|
|
|
2011-10-31 13:54:28 +00:00
|
|
|
if (data->numprefix >= 100) /* no more than three digits */
|
2012-04-10 09:54:29 +00:00
|
|
|
return (0);
|
2010-03-08 15:02:07 +00:00
|
|
|
data->numprefix = data->numprefix * 10 + key - '0';
|
|
|
|
|
|
|
|
window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1);
|
2012-04-10 09:54:29 +00:00
|
|
|
return (0);
|
2010-03-08 15:02:07 +00:00
|
|
|
}
|
|
|
|
|
2009-11-28 14:50:37 +00:00
|
|
|
/* ARGSUSED */
|
2009-01-28 22:00:22 +00:00
|
|
|
void
|
2009-10-12 00:18:19 +00:00
|
|
|
window_copy_mouse(
|
2011-04-25 20:33:42 +00:00
|
|
|
struct window_pane *wp, struct session *sess, struct mouse_event *m)
|
2009-01-28 22:00:22 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
2012-04-10 09:45:41 +00:00
|
|
|
u_int i;
|
2010-06-06 00:23:44 +00:00
|
|
|
|
2009-10-12 00:18:19 +00:00
|
|
|
if (m->x >= screen_size_x(s))
|
2009-01-28 22:00:22 +00:00
|
|
|
return;
|
2009-10-12 00:18:19 +00:00
|
|
|
if (m->y >= screen_size_y(s))
|
2009-01-28 22:00:22 +00:00
|
|
|
return;
|
|
|
|
|
2010-06-06 00:23:44 +00:00
|
|
|
/* If mouse wheel (buttons 4 and 5), scroll. */
|
2012-10-26 14:35:42 +00:00
|
|
|
if (m->event == MOUSE_EVENT_WHEEL) {
|
|
|
|
if (m->wheel == MOUSE_WHEEL_UP) {
|
2010-06-06 00:23:44 +00:00
|
|
|
for (i = 0; i < 5; i++)
|
2012-11-27 14:42:56 +00:00
|
|
|
window_copy_cursor_up(wp, 1);
|
2012-10-26 14:35:42 +00:00
|
|
|
} else if (m->wheel == MOUSE_WHEEL_DOWN) {
|
2010-06-06 00:23:44 +00:00
|
|
|
for (i = 0; i < 5; i++)
|
2012-11-27 14:42:56 +00:00
|
|
|
window_copy_cursor_down(wp, 1);
|
2012-04-10 09:45:41 +00:00
|
|
|
if (data->oy == 0)
|
2011-04-25 20:33:42 +00:00
|
|
|
goto reset_mode;
|
2010-06-06 00:23:44 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If already reading motion, move the cursor while buttons are still
|
|
|
|
* pressed, or stop the selection on their release.
|
|
|
|
*/
|
2011-05-18 20:33:24 +00:00
|
|
|
if (s->mode & MODE_MOUSE_BUTTON) {
|
2012-10-26 14:35:42 +00:00
|
|
|
if (~m->event & MOUSE_EVENT_UP) {
|
2010-06-06 00:23:44 +00:00
|
|
|
window_copy_update_cursor(wp, m->x, m->y);
|
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_screen(wp);
|
2011-04-25 20:33:42 +00:00
|
|
|
return;
|
2010-06-06 00:23:44 +00:00
|
|
|
}
|
2011-04-25 20:33:42 +00:00
|
|
|
goto reset_mode;
|
2010-06-06 00:23:44 +00:00
|
|
|
}
|
|
|
|
|
2010-12-30 22:27:38 +00:00
|
|
|
/* Otherwise if other buttons pressed, start selection and motion. */
|
2012-10-26 14:35:42 +00:00
|
|
|
if (~m->event & MOUSE_EVENT_UP) {
|
2010-12-30 22:27:38 +00:00
|
|
|
s->mode &= ~MODE_MOUSE_STANDARD;
|
2011-05-18 20:33:24 +00:00
|
|
|
s->mode |= MODE_MOUSE_BUTTON;
|
2010-06-06 00:23:44 +00:00
|
|
|
|
|
|
|
window_copy_update_cursor(wp, m->x, m->y);
|
|
|
|
window_copy_start_selection(wp);
|
2009-12-04 22:14:47 +00:00
|
|
|
window_copy_redraw_screen(wp);
|
2010-06-06 00:23:44 +00:00
|
|
|
}
|
2011-04-25 20:33:42 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
reset_mode:
|
2011-05-18 20:33:24 +00:00
|
|
|
s->mode &= ~MODE_MOUSE_BUTTON;
|
2011-04-25 20:33:42 +00:00
|
|
|
s->mode |= MODE_MOUSE_STANDARD;
|
|
|
|
if (sess != NULL) {
|
2011-10-31 13:54:28 +00:00
|
|
|
window_copy_copy_selection(wp, -1);
|
2011-04-25 20:33:42 +00:00
|
|
|
window_pane_reset_mode(wp);
|
|
|
|
}
|
2009-01-28 22:00:22 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 11:20:24 +00:00
|
|
|
void
|
|
|
|
window_copy_scroll_to(struct window_pane *wp, u_int px, u_int py)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-04-05 05:11:44 +00:00
|
|
|
struct grid *gd = data->backing->grid;
|
2009-08-20 11:20:24 +00:00
|
|
|
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;
|
|
|
|
}
|
2009-12-04 22:14:47 +00:00
|
|
|
data->oy = gd->hsize - offset;
|
2009-08-20 11:20:24 +00:00
|
|
|
|
2010-01-28 22:42:36 +00:00
|
|
|
window_copy_update_selection(wp);
|
2009-08-20 11:20:24 +00:00
|
|
|
window_copy_redraw_screen(wp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
window_copy_search_compare(
|
|
|
|
struct grid *gd, u_int px, u_int py, struct grid *sgd, u_int spx)
|
|
|
|
{
|
|
|
|
const struct grid_cell *gc, *sgc;
|
2013-01-18 02:16:21 +00:00
|
|
|
struct utf8_data ud, sud;
|
2009-08-20 11:20:24 +00:00
|
|
|
|
|
|
|
gc = grid_peek_cell(gd, px, py);
|
2013-01-18 02:16:21 +00:00
|
|
|
grid_cell_get(gc, &ud);
|
2009-08-20 11:20:24 +00:00
|
|
|
sgc = grid_peek_cell(sgd, spx, 0);
|
2013-01-18 02:16:21 +00:00
|
|
|
grid_cell_get(sgc, &sud);
|
2009-12-04 22:14:47 +00:00
|
|
|
|
2013-01-18 02:16:21 +00:00
|
|
|
if (ud.size != sud.size || ud.width != sud.width)
|
2009-08-20 11:20:24 +00:00
|
|
|
return (0);
|
2013-01-18 02:16:21 +00:00
|
|
|
return (memcmp(ud.data, sud.data, ud.size) == 0);
|
2009-08-20 11:20:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
window_copy_search_lr(struct grid *gd,
|
|
|
|
struct grid *sgd, u_int *ppx, u_int py, u_int first, u_int last)
|
|
|
|
{
|
|
|
|
u_int ax, bx, px;
|
|
|
|
|
|
|
|
for (ax = first; ax < last; ax++) {
|
|
|
|
if (ax + sgd->sx >= gd->sx)
|
|
|
|
break;
|
|
|
|
for (bx = 0; bx < sgd->sx; bx++) {
|
|
|
|
px = ax + bx;
|
|
|
|
if (!window_copy_search_compare(gd, px, py, sgd, bx))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bx == sgd->sx) {
|
|
|
|
*ppx = ax;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
window_copy_search_rl(struct grid *gd,
|
|
|
|
struct grid *sgd, u_int *ppx, u_int py, u_int first, u_int last)
|
|
|
|
{
|
|
|
|
u_int ax, bx, px;
|
|
|
|
|
|
|
|
for (ax = last + 1; ax > first; ax--) {
|
2009-08-20 11:52:39 +00:00
|
|
|
if (gd->sx - (ax - 1) < sgd->sx)
|
|
|
|
continue;
|
2009-08-20 11:20:24 +00:00
|
|
|
for (bx = 0; bx < sgd->sx; bx++) {
|
|
|
|
px = ax - 1 + bx;
|
|
|
|
if (!window_copy_search_compare(gd, px, py, sgd, bx))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bx == sgd->sx) {
|
|
|
|
*ppx = ax - 1;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_search_up(struct window_pane *wp, const char *searchstr)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-04-05 05:11:44 +00:00
|
|
|
struct screen *s = data->backing, ss;
|
2009-08-20 11:20:24 +00:00
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
struct grid *gd = s->grid, *sgd;
|
|
|
|
struct grid_cell gc;
|
|
|
|
size_t searchlen;
|
|
|
|
u_int i, last, fx, fy, px;
|
2012-03-18 02:12:24 +00:00
|
|
|
int utf8flag, n, wrapped, wrapflag;
|
2009-08-20 11:20:24 +00:00
|
|
|
|
|
|
|
if (*searchstr == '\0')
|
|
|
|
return;
|
|
|
|
utf8flag = options_get_number(&wp->window->options, "utf8");
|
2012-03-18 02:12:24 +00:00
|
|
|
wrapflag = options_get_number(&wp->window->options, "wrap-search");
|
2009-08-20 11:20:24 +00:00
|
|
|
searchlen = screen_write_strlen(utf8flag, "%s", searchstr);
|
|
|
|
|
|
|
|
screen_init(&ss, searchlen, 1, 0);
|
|
|
|
screen_write_start(&ctx, NULL, &ss);
|
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
|
|
|
screen_write_nputs(&ctx, -1, &gc, utf8flag, "%s", searchstr);
|
|
|
|
screen_write_stop(&ctx);
|
|
|
|
|
|
|
|
fx = data->cx;
|
|
|
|
fy = gd->hsize - data->oy + data->cy;
|
|
|
|
|
|
|
|
if (fx == 0) {
|
|
|
|
if (fy == 0)
|
|
|
|
return;
|
|
|
|
fx = gd->sx - 1;
|
|
|
|
fy--;
|
|
|
|
} else
|
|
|
|
fx--;
|
|
|
|
n = wrapped = 0;
|
|
|
|
|
|
|
|
retry:
|
|
|
|
sgd = ss.grid;
|
|
|
|
for (i = fy + 1; i > 0; i--) {
|
|
|
|
last = screen_size_x(s);
|
|
|
|
if (i == fy + 1)
|
|
|
|
last = fx;
|
|
|
|
n = window_copy_search_rl(gd, sgd, &px, i - 1, 0, last);
|
|
|
|
if (n) {
|
|
|
|
window_copy_scroll_to(wp, px, i - 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-18 02:12:24 +00:00
|
|
|
if (wrapflag && !n && !wrapped) {
|
2009-08-20 11:20:24 +00:00
|
|
|
fx = gd->sx - 1;
|
|
|
|
fy = gd->hsize + gd->sy - 1;
|
|
|
|
wrapped = 1;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
screen_free(&ss);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_search_down(struct window_pane *wp, const char *searchstr)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-04-05 05:11:44 +00:00
|
|
|
struct screen *s = data->backing, ss;
|
2009-08-20 11:20:24 +00:00
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
struct grid *gd = s->grid, *sgd;
|
|
|
|
struct grid_cell gc;
|
|
|
|
size_t searchlen;
|
|
|
|
u_int i, first, fx, fy, px;
|
2012-03-18 02:12:24 +00:00
|
|
|
int utf8flag, n, wrapped, wrapflag;
|
2009-08-20 11:20:24 +00:00
|
|
|
|
|
|
|
if (*searchstr == '\0')
|
|
|
|
return;
|
|
|
|
utf8flag = options_get_number(&wp->window->options, "utf8");
|
2012-03-18 02:12:24 +00:00
|
|
|
wrapflag = options_get_number(&wp->window->options, "wrap-search");
|
2009-08-20 11:20:24 +00:00
|
|
|
searchlen = screen_write_strlen(utf8flag, "%s", searchstr);
|
|
|
|
|
|
|
|
screen_init(&ss, searchlen, 1, 0);
|
|
|
|
screen_write_start(&ctx, NULL, &ss);
|
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
|
|
|
screen_write_nputs(&ctx, -1, &gc, utf8flag, "%s", searchstr);
|
|
|
|
screen_write_stop(&ctx);
|
|
|
|
|
|
|
|
fx = data->cx;
|
|
|
|
fy = gd->hsize - data->oy + data->cy;
|
|
|
|
|
|
|
|
if (fx == gd->sx - 1) {
|
|
|
|
if (fy == gd->hsize + gd->sy)
|
|
|
|
return;
|
|
|
|
fx = 0;
|
|
|
|
fy++;
|
|
|
|
} else
|
|
|
|
fx++;
|
|
|
|
n = wrapped = 0;
|
|
|
|
|
|
|
|
retry:
|
|
|
|
sgd = ss.grid;
|
2012-09-25 07:39:28 +00:00
|
|
|
for (i = fy + 1; i < gd->hsize + gd->sy + 1; i++) {
|
2009-08-20 11:20:24 +00:00
|
|
|
first = 0;
|
|
|
|
if (i == fy + 1)
|
|
|
|
first = fx;
|
|
|
|
n = window_copy_search_lr(gd, sgd, &px, i - 1, first, gd->sx);
|
|
|
|
if (n) {
|
|
|
|
window_copy_scroll_to(wp, px, i - 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-18 02:12:24 +00:00
|
|
|
if (wrapflag && !n && !wrapped) {
|
2009-08-20 11:20:24 +00:00
|
|
|
fx = 0;
|
|
|
|
fy = 0;
|
|
|
|
wrapped = 1;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
screen_free(&ss);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
lineno = strtonum(linestr, 0, screen_hsize(data->backing), &errstr);
|
2009-08-20 11:20:24 +00:00
|
|
|
if (errstr != NULL)
|
|
|
|
return;
|
2009-12-04 22:14:47 +00:00
|
|
|
|
2009-08-20 11:20:24 +00:00
|
|
|
data->oy = lineno;
|
2010-01-28 22:42:36 +00:00
|
|
|
window_copy_update_selection(wp);
|
2009-08-20 11:20:24 +00:00
|
|
|
window_copy_redraw_screen(wp);
|
|
|
|
}
|
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
void
|
2009-08-16 19:12:07 +00:00
|
|
|
window_copy_write_line(
|
|
|
|
struct window_pane *wp, struct screen_write_ctx *ctx, u_int py)
|
2007-12-06 09:46:23 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s = &data->screen;
|
2009-09-11 14:13:52 +00:00
|
|
|
struct options *oo = &wp->window->options;
|
2008-09-25 20:08:57 +00:00
|
|
|
struct grid_cell gc;
|
|
|
|
char hdr[32];
|
2009-08-20 11:20:24 +00:00
|
|
|
size_t last, xoff = 0, size = 0;
|
2007-12-06 09:46:23 +00:00
|
|
|
|
2012-08-12 19:28:20 +00:00
|
|
|
window_mode_attrs(&gc, oo);
|
2009-08-20 11:20:24 +00:00
|
|
|
|
|
|
|
last = screen_size_y(s) - 1;
|
2007-12-06 09:46:23 +00:00
|
|
|
if (py == 0) {
|
2008-09-25 20:08:57 +00:00
|
|
|
size = xsnprintf(hdr, sizeof hdr,
|
2010-04-05 05:11:44 +00:00
|
|
|
"[%u/%u]", data->oy, screen_hsize(data->backing));
|
2010-09-10 13:34:12 +00:00
|
|
|
if (size > screen_size_x(s))
|
|
|
|
size = screen_size_x(s);
|
2008-09-25 20:08:57 +00:00
|
|
|
screen_write_cursormove(ctx, screen_size_x(s) - size, 0);
|
|
|
|
screen_write_puts(ctx, &gc, "%s", hdr);
|
2009-08-20 11:20:24 +00:00
|
|
|
} else if (py == last && data->inputtype != WINDOW_COPY_OFF) {
|
2010-03-08 15:02:07 +00:00
|
|
|
if (data->inputtype == WINDOW_COPY_NUMERICPREFIX) {
|
|
|
|
xoff = size = xsnprintf(hdr, sizeof hdr,
|
|
|
|
"Repeat: %u", data->numprefix);
|
|
|
|
} else {
|
|
|
|
xoff = size = xsnprintf(hdr, sizeof hdr,
|
|
|
|
"%s: %s", data->inputprompt, data->inputstr);
|
|
|
|
}
|
2009-08-20 11:20:24 +00:00
|
|
|
screen_write_cursormove(ctx, 0, last);
|
|
|
|
screen_write_puts(ctx, &gc, "%s", hdr);
|
2007-12-06 09:46:23 +00:00
|
|
|
} else
|
|
|
|
size = 0;
|
2008-09-25 20:08:57 +00:00
|
|
|
|
2009-08-20 11:20:24 +00:00
|
|
|
screen_write_cursormove(ctx, xoff, py);
|
2010-04-05 05:11:44 +00:00
|
|
|
screen_write_copy(ctx, data->backing, xoff,
|
|
|
|
(screen_hsize(data->backing) - data->oy) + py,
|
|
|
|
screen_size_x(s) - size, 1);
|
2009-08-16 19:12:07 +00:00
|
|
|
|
|
|
|
if (py == data->cy && data->cx == screen_size_x(s)) {
|
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
|
|
|
screen_write_cursormove(ctx, screen_size_x(s) - 1, py);
|
|
|
|
screen_write_putc(ctx, &gc, '$');
|
|
|
|
}
|
2007-12-06 09:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_write_lines(
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_pane *wp, struct screen_write_ctx *ctx, u_int py, u_int ny)
|
2007-12-06 09:46:23 +00:00
|
|
|
{
|
2008-09-25 20:08:57 +00:00
|
|
|
u_int yy;
|
2007-12-06 09:46:23 +00:00
|
|
|
|
2008-09-25 20:08:57 +00:00
|
|
|
for (yy = py; yy < py + ny; yy++)
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_write_line(wp, ctx, py);
|
2007-12-06 09:46:23 +00:00
|
|
|
}
|
2007-11-23 17:52:54 +00:00
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
void
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_redraw_lines(struct window_pane *wp, u_int py, u_int ny)
|
2007-12-06 09:46:23 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
u_int i;
|
|
|
|
|
2009-01-11 23:31:46 +00:00
|
|
|
screen_write_start(&ctx, wp, NULL);
|
2007-12-06 09:46:23 +00:00
|
|
|
for (i = py; i < py + ny; i++)
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_write_line(wp, &ctx, i);
|
2008-09-25 20:08:57 +00:00
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
2007-12-06 09:46:23 +00:00
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_redraw_screen(struct window_pane *wp)
|
2007-12-06 09:46:23 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_redraw_lines(wp, 0, screen_size_y(&data->screen));
|
2007-12-06 09:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-16 19:12:07 +00:00
|
|
|
window_copy_update_cursor(struct window_pane *wp, u_int cx, u_int cy)
|
2007-12-06 09:46:23 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2009-08-16 19:12:07 +00:00
|
|
|
struct screen *s = &data->screen;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen_write_ctx ctx;
|
2009-08-16 19:12:07 +00:00
|
|
|
u_int old_cx, old_cy;
|
2007-12-06 09:46:23 +00:00
|
|
|
|
2009-08-16 19:12:07 +00:00
|
|
|
old_cx = data->cx; old_cy = data->cy;
|
|
|
|
data->cx = cx; data->cy = cy;
|
|
|
|
if (old_cx == screen_size_x(s))
|
|
|
|
window_copy_redraw_lines(wp, old_cy, 1);
|
|
|
|
if (data->cx == screen_size_x(s))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
|
|
|
else {
|
|
|
|
screen_write_start(&ctx, wp, NULL);
|
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|
2007-12-06 09:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_start_selection(struct window_pane *wp)
|
2007-12-06 09:46:23 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
|
2009-08-16 19:12:07 +00:00
|
|
|
data->selx = data->cx;
|
2010-04-05 05:11:44 +00:00
|
|
|
data->sely = screen_hsize(data->backing) + data->cy - data->oy;
|
2007-12-06 09:46:23 +00:00
|
|
|
|
|
|
|
s->sel.flag = 1;
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_update_selection(wp);
|
2007-12-06 09:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_update_selection(struct window_pane *wp)
|
2007-12-06 09:46:23 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s = &data->screen;
|
2009-09-11 14:13:52 +00:00
|
|
|
struct options *oo = &wp->window->options;
|
2008-12-08 16:19:51 +00:00
|
|
|
struct grid_cell gc;
|
2010-02-08 18:13:17 +00:00
|
|
|
u_int sx, sy, ty, cy;
|
2007-12-06 09:46:23 +00:00
|
|
|
|
|
|
|
if (!s->sel.flag)
|
|
|
|
return (0);
|
|
|
|
|
2008-12-08 16:19:51 +00:00
|
|
|
/* Set colours. */
|
2012-08-12 19:28:20 +00:00
|
|
|
window_mode_attrs(&gc, oo);
|
2008-12-08 16:19:51 +00:00
|
|
|
|
2009-08-16 19:12:07 +00:00
|
|
|
/* Find top of screen. */
|
2010-04-05 05:11:44 +00:00
|
|
|
ty = screen_hsize(data->backing) - data->oy;
|
2007-12-06 09:46:23 +00:00
|
|
|
|
|
|
|
/* Adjust the selection. */
|
|
|
|
sx = data->selx;
|
|
|
|
sy = data->sely;
|
2009-08-16 19:12:07 +00:00
|
|
|
if (sy < ty) { /* above screen */
|
2010-02-08 18:13:17 +00:00
|
|
|
if (!data->rectflag)
|
|
|
|
sx = 0;
|
2007-12-06 09:46:23 +00:00
|
|
|
sy = 0;
|
2009-08-16 19:12:07 +00:00
|
|
|
} else if (sy > ty + screen_size_y(s) - 1) { /* below screen */
|
2010-02-08 18:13:17 +00:00
|
|
|
if (!data->rectflag)
|
|
|
|
sx = screen_size_x(s) - 1;
|
2008-09-25 20:08:57 +00:00
|
|
|
sy = screen_size_y(s) - 1;
|
2009-08-16 19:12:07 +00:00
|
|
|
} else
|
2007-12-06 09:46:23 +00:00
|
|
|
sy -= ty;
|
2008-09-25 20:08:57 +00:00
|
|
|
sy = screen_hsize(s) + sy;
|
2007-12-06 09:46:23 +00:00
|
|
|
|
2010-02-08 18:13:17 +00:00
|
|
|
screen_set_selection(s,
|
|
|
|
sx, sy, data->cx, screen_hsize(s) + data->cy, data->rectflag, &gc);
|
|
|
|
|
|
|
|
if (data->rectflag) {
|
|
|
|
/*
|
|
|
|
* Can't rely on the caller to redraw the right lines for
|
|
|
|
* rectangle selection - find the highest line and the number
|
|
|
|
* of lines, and redraw just past that in both directions
|
|
|
|
*/
|
|
|
|
cy = data->cy;
|
|
|
|
if (sy < cy)
|
|
|
|
window_copy_redraw_lines(wp, sy, cy - sy + 1);
|
|
|
|
else
|
|
|
|
window_copy_redraw_lines(wp, cy, sy - cy + 1);
|
|
|
|
}
|
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
return (1);
|
2007-11-23 17:52:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-10-31 13:54:28 +00:00
|
|
|
window_copy_copy_selection(struct window_pane *wp, int idx)
|
2007-11-23 17:52:54 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-07 09:49:18 +00:00
|
|
|
struct screen *s = &data->screen;
|
2007-11-23 17:52:54 +00:00
|
|
|
char *buf;
|
2010-02-08 18:13:17 +00:00
|
|
|
size_t off;
|
|
|
|
u_int i, xx, yy, sx, sy, ex, ey, limit;
|
|
|
|
u_int firstsx, lastex, restex, restsx;
|
2011-04-25 20:34:26 +00:00
|
|
|
int keys;
|
2007-11-23 17:52:54 +00:00
|
|
|
|
2007-12-07 09:49:18 +00:00
|
|
|
if (!s->sel.flag)
|
|
|
|
return;
|
|
|
|
|
2008-08-07 20:20:52 +00:00
|
|
|
buf = xmalloc(1);
|
2007-11-23 17:52:54 +00:00
|
|
|
off = 0;
|
|
|
|
|
|
|
|
*buf = '\0';
|
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
/*
|
|
|
|
* The selection extends from selx,sely to (adjusted) cx,cy on
|
|
|
|
* the base screen.
|
|
|
|
*/
|
|
|
|
|
2007-11-23 17:52:54 +00:00
|
|
|
/* Find start and end. */
|
2009-08-16 19:12:07 +00:00
|
|
|
xx = data->cx;
|
2010-04-05 05:11:44 +00:00
|
|
|
yy = screen_hsize(data->backing) + data->cy - data->oy;
|
2009-07-02 16:23:54 +00:00
|
|
|
if (yy < data->sely || (yy == data->sely && xx < data->selx)) {
|
2007-11-23 17:52:54 +00:00
|
|
|
sx = xx; sy = yy;
|
|
|
|
ex = data->selx; ey = data->sely;
|
|
|
|
} else {
|
|
|
|
sx = data->selx; sy = data->sely;
|
|
|
|
ex = xx; ey = yy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Trim ex to end of line. */
|
2009-01-11 23:31:46 +00:00
|
|
|
xx = window_copy_find_length(wp, ey);
|
2007-11-23 17:52:54 +00:00
|
|
|
if (ex > xx)
|
|
|
|
ex = xx;
|
|
|
|
|
2010-02-08 18:13:17 +00:00
|
|
|
/*
|
|
|
|
* Deal with rectangle-copy if necessary; four situations: start of
|
|
|
|
* first line (firstsx), end of last line (lastex), start (restsx) and
|
|
|
|
* end (restex) of all other lines.
|
|
|
|
*/
|
|
|
|
xx = screen_size_x(s);
|
2011-04-25 20:34:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Behave according to mode-keys. If it is emacs, copy like emacs,
|
|
|
|
* keeping the top-left-most character, and dropping the
|
|
|
|
* bottom-right-most, regardless of copy direction. If it is vi, also
|
|
|
|
* keep bottom-right-most character.
|
|
|
|
*/
|
|
|
|
keys = options_get_number(&wp->window->options, "mode-keys");
|
2010-02-08 18:13:17 +00:00
|
|
|
if (data->rectflag) {
|
|
|
|
/*
|
|
|
|
* Need to ignore the column with the cursor in it, which for
|
|
|
|
* rectangular copy means knowing which side the cursor is on.
|
|
|
|
*/
|
|
|
|
if (data->selx < data->cx) {
|
|
|
|
/* Selection start is on the left. */
|
2011-04-25 20:34:26 +00:00
|
|
|
if (keys == MODEKEY_EMACS) {
|
|
|
|
lastex = data->cx;
|
|
|
|
restex = data->cx;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastex = data->cx + 1;
|
|
|
|
restex = data->cx + 1;
|
|
|
|
}
|
2010-02-08 18:13:17 +00:00
|
|
|
firstsx = data->selx;
|
|
|
|
restsx = data->selx;
|
|
|
|
} else {
|
|
|
|
/* Cursor is on the left. */
|
|
|
|
lastex = data->selx + 1;
|
|
|
|
restex = data->selx + 1;
|
2010-12-11 17:57:28 +00:00
|
|
|
firstsx = data->cx;
|
|
|
|
restsx = data->cx;
|
2010-02-08 18:13:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-04-25 20:34:26 +00:00
|
|
|
if (keys == MODEKEY_EMACS)
|
|
|
|
lastex = ex;
|
2011-10-31 13:54:28 +00:00
|
|
|
else
|
2011-04-25 20:34:26 +00:00
|
|
|
lastex = ex + 1;
|
2010-02-08 18:13:17 +00:00
|
|
|
restex = xx;
|
|
|
|
firstsx = sx;
|
|
|
|
restsx = 0;
|
|
|
|
}
|
|
|
|
|
2007-11-23 17:52:54 +00:00
|
|
|
/* Copy the lines. */
|
|
|
|
if (sy == ey)
|
2010-02-08 18:13:17 +00:00
|
|
|
window_copy_copy_line(wp, &buf, &off, sy, firstsx, lastex);
|
2007-11-23 17:52:54 +00:00
|
|
|
else {
|
2010-02-08 18:13:17 +00:00
|
|
|
window_copy_copy_line(wp, &buf, &off, sy, firstsx, restex);
|
2007-11-23 17:52:54 +00:00
|
|
|
if (ey - sy > 1) {
|
2010-02-08 18:13:17 +00:00
|
|
|
for (i = sy + 1; i < ey; i++) {
|
|
|
|
window_copy_copy_line(
|
|
|
|
wp, &buf, &off, i, restsx, restex);
|
|
|
|
}
|
2007-11-23 17:52:54 +00:00
|
|
|
}
|
2010-02-08 18:13:17 +00:00
|
|
|
window_copy_copy_line(wp, &buf, &off, ey, restsx, lastex);
|
2007-11-23 17:52:54 +00:00
|
|
|
}
|
|
|
|
|
2009-09-07 23:48:54 +00:00
|
|
|
/* Don't bother if no data. */
|
|
|
|
if (off == 0) {
|
2012-07-11 19:34:16 +00:00
|
|
|
free(buf);
|
2009-09-07 23:48:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
off--; /* remove final \n */
|
2007-11-23 17:52:54 +00:00
|
|
|
|
2011-05-22 16:23:07 +00:00
|
|
|
if (options_get_number(&global_options, "set-clipboard"))
|
|
|
|
screen_write_setselection(&wp->ictx.ctx, buf, off);
|
|
|
|
|
2008-06-20 17:31:48 +00:00
|
|
|
/* Add the buffer to the stack. */
|
2011-10-31 13:54:28 +00:00
|
|
|
if (idx == -1) {
|
|
|
|
limit = options_get_number(&global_options, "buffer-limit");
|
|
|
|
paste_add(&global_buffers, buf, off, limit);
|
|
|
|
} else
|
|
|
|
paste_replace(&global_buffers, idx, buf, off);
|
2007-11-23 17:52:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-28 20:17:29 +00:00
|
|
|
window_copy_copy_line(struct window_pane *wp,
|
|
|
|
char **buf, size_t *off, u_int sy, u_int sx, u_int ex)
|
2007-11-23 17:52:54 +00:00
|
|
|
{
|
2010-04-05 05:11:44 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct grid *gd = data->backing->grid;
|
|
|
|
const struct grid_cell *gc;
|
|
|
|
struct grid_line *gl;
|
2013-01-18 02:16:21 +00:00
|
|
|
struct utf8_data ud;
|
2010-04-05 05:11:44 +00:00
|
|
|
u_int i, xx, wrapped = 0;
|
2007-11-23 17:52:54 +00:00
|
|
|
|
|
|
|
if (sx > ex)
|
|
|
|
return;
|
|
|
|
|
2009-08-09 17:32:06 +00:00
|
|
|
/*
|
|
|
|
* Work out if the line was wrapped at the screen edge and all of it is
|
|
|
|
* on screen.
|
|
|
|
*/
|
|
|
|
gl = &gd->linedata[sy];
|
2009-12-04 22:14:47 +00:00
|
|
|
if (gl->flags & GRID_LINE_WRAPPED && gl->cellsize <= gd->sx)
|
2009-08-09 17:32:06 +00:00
|
|
|
wrapped = 1;
|
|
|
|
|
|
|
|
/* If the line was wrapped, don't strip spaces (use the full length). */
|
|
|
|
if (wrapped)
|
|
|
|
xx = gl->cellsize;
|
|
|
|
else
|
|
|
|
xx = window_copy_find_length(wp, sy);
|
2007-11-23 17:52:54 +00:00
|
|
|
if (ex > xx)
|
|
|
|
ex = xx;
|
|
|
|
if (sx > xx)
|
|
|
|
sx = xx;
|
|
|
|
|
|
|
|
if (sx < ex) {
|
|
|
|
for (i = sx; i < ex; i++) {
|
2009-08-09 17:32:06 +00:00
|
|
|
gc = grid_peek_cell(gd, i, sy);
|
2009-03-30 19:57:02 +00:00
|
|
|
if (gc->flags & GRID_FLAG_PADDING)
|
|
|
|
continue;
|
2013-01-18 02:16:21 +00:00
|
|
|
grid_cell_get(gc, &ud);
|
|
|
|
|
|
|
|
*buf = xrealloc(*buf, 1, (*off) + ud.size);
|
|
|
|
memcpy(*buf + *off, ud.data, ud.size);
|
|
|
|
*off += ud.size;
|
2007-11-23 17:52:54 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-06 09:46:23 +00:00
|
|
|
|
2009-08-09 17:32:06 +00:00
|
|
|
/* Only add a newline if the line wasn't wrapped. */
|
2010-02-18 12:36:18 +00:00
|
|
|
if (!wrapped || ex != xx) {
|
2009-08-09 17:32:06 +00:00
|
|
|
*buf = xrealloc(*buf, 1, (*off) + 1);
|
|
|
|
(*buf)[(*off)++] = '\n';
|
|
|
|
}
|
2007-11-23 17:52:54 +00:00
|
|
|
}
|
|
|
|
|
2010-02-26 13:29:25 +00:00
|
|
|
void
|
|
|
|
window_copy_clear_selection(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
u_int px, py;
|
|
|
|
|
|
|
|
screen_clear_selection(&data->screen);
|
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2010-02-26 13:29:25 +00:00
|
|
|
px = window_copy_find_length(wp, py);
|
|
|
|
if (data->cx > px)
|
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
|
|
|
}
|
|
|
|
|
2008-09-25 20:08:57 +00:00
|
|
|
int
|
2010-02-05 01:34:08 +00:00
|
|
|
window_copy_in_set(struct window_pane *wp, u_int px, u_int py, const char *set)
|
2008-09-25 20:08:57 +00:00
|
|
|
{
|
2010-04-05 05:11:44 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
const struct grid_cell *gc;
|
2013-01-18 02:16:21 +00:00
|
|
|
struct utf8_data ud;
|
2008-09-25 20:08:57 +00:00
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
gc = grid_peek_cell(data->backing->grid, px, py);
|
2013-01-18 02:16:21 +00:00
|
|
|
grid_cell_get(gc, &ud);
|
|
|
|
if (ud.size != 1 || gc->flags & GRID_FLAG_PADDING)
|
2008-09-25 20:08:57 +00:00
|
|
|
return (0);
|
2013-01-18 02:16:21 +00:00
|
|
|
if (*ud.data == 0x00 || *ud.data == 0x7f)
|
2008-09-25 20:08:57 +00:00
|
|
|
return (0);
|
2013-01-18 02:16:21 +00:00
|
|
|
return (strchr(set, *ud.data) != NULL);
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
2007-11-23 17:52:54 +00:00
|
|
|
u_int
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_find_length(struct window_pane *wp, u_int py)
|
2007-11-23 17:52:54 +00:00
|
|
|
{
|
2010-04-05 05:11:44 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = data->backing;
|
|
|
|
const struct grid_cell *gc;
|
2013-01-18 02:16:21 +00:00
|
|
|
struct utf8_data ud;
|
2010-04-05 05:11:44 +00:00
|
|
|
u_int px;
|
2008-09-25 20:08:57 +00:00
|
|
|
|
2009-07-12 17:11:07 +00:00
|
|
|
/*
|
|
|
|
* If the pane has been resized, its grid can contain old overlong
|
|
|
|
* lines. grid_peek_cell does not allow accessing cells beyond the
|
|
|
|
* width of the grid, and screen_write_copy treats them as spaces, so
|
|
|
|
* ignore them here too.
|
|
|
|
*/
|
2010-04-05 05:11:44 +00:00
|
|
|
px = s->grid->linedata[py].cellsize;
|
|
|
|
if (px > screen_size_x(s))
|
|
|
|
px = screen_size_x(s);
|
2008-09-25 20:08:57 +00:00
|
|
|
while (px > 0) {
|
2010-04-05 05:11:44 +00:00
|
|
|
gc = grid_peek_cell(s->grid, px - 1, py);
|
2013-01-18 02:16:21 +00:00
|
|
|
grid_cell_get(gc, &ud);
|
|
|
|
if (ud.size != 1 || *ud.data != ' ')
|
2008-09-25 20:08:57 +00:00
|
|
|
break;
|
2007-11-23 17:52:54 +00:00
|
|
|
px--;
|
2008-09-25 20:08:57 +00:00
|
|
|
}
|
2007-11-23 17:52:54 +00:00
|
|
|
return (px);
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
2009-07-14 06:38:32 +00:00
|
|
|
void
|
|
|
|
window_copy_cursor_start_of_line(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-06-05 07:48:35 +00:00
|
|
|
struct screen *back_s = data->backing;
|
|
|
|
struct grid *gd = back_s->grid;
|
|
|
|
u_int py;
|
2009-07-14 06:38:32 +00:00
|
|
|
|
2010-06-05 07:48:35 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2009-08-16 19:12:07 +00:00
|
|
|
window_copy_update_cursor(wp, 0, data->cy);
|
2009-07-14 06:38:32 +00:00
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
|
|
|
}
|
|
|
|
|
2009-07-14 06:39:25 +00:00
|
|
|
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;
|
2013-01-18 02:16:21 +00:00
|
|
|
struct utf8_data ud;
|
2009-07-14 06:39:25 +00:00
|
|
|
|
|
|
|
px = 0;
|
2010-04-05 05:11:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2009-07-14 06:39:25 +00:00
|
|
|
xx = window_copy_find_length(wp, py);
|
|
|
|
|
|
|
|
while (px < xx) {
|
2010-04-05 05:11:44 +00:00
|
|
|
gc = grid_peek_cell(data->backing->grid, px, py);
|
2013-01-18 02:16:21 +00:00
|
|
|
grid_cell_get(gc, &ud);
|
|
|
|
if (ud.size != 1 || *ud.data != ' ')
|
2009-07-14 06:39:25 +00:00
|
|
|
break;
|
|
|
|
px++;
|
|
|
|
}
|
|
|
|
|
2009-08-16 19:12:07 +00:00
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
2009-07-14 06:39:25 +00:00
|
|
|
}
|
|
|
|
|
2009-07-14 06:38:32 +00:00
|
|
|
void
|
|
|
|
window_copy_cursor_end_of_line(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-04-05 05:11:44 +00:00
|
|
|
struct screen *back_s = data->backing;
|
|
|
|
struct grid *gd = back_s->grid;
|
2009-07-14 06:38:32 +00:00
|
|
|
u_int px, py;
|
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
2009-07-14 06:38:32 +00:00
|
|
|
px = window_copy_find_length(wp, py);
|
|
|
|
|
2010-03-08 14:56:17 +00:00
|
|
|
if (data->cx == px) {
|
|
|
|
if (data->screen.sel.flag && data->rectflag)
|
2010-04-05 05:11:44 +00:00
|
|
|
px = screen_size_x(back_s);
|
2010-03-08 14:56:17 +00:00
|
|
|
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);
|
2010-04-05 05:11:44 +00:00
|
|
|
py = screen_hsize(back_s)
|
|
|
|
+ data->cy - data->oy;
|
2010-03-08 14:56:17 +00:00
|
|
|
}
|
|
|
|
px = window_copy_find_length(wp, py);
|
|
|
|
}
|
|
|
|
}
|
2009-08-16 19:12:07 +00:00
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
2010-03-08 14:56:17 +00:00
|
|
|
|
2009-08-16 19:12:07 +00:00
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
2009-07-14 06:38:32 +00:00
|
|
|
}
|
|
|
|
|
2007-11-22 18:09:43 +00:00
|
|
|
void
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_cursor_left(struct window_pane *wp)
|
2007-11-22 18:09:43 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
if (data->cx == 0) {
|
2009-10-06 14:10:10 +00:00
|
|
|
window_copy_cursor_up(wp, 0);
|
2009-08-16 19:12:07 +00:00
|
|
|
window_copy_cursor_end_of_line(wp);
|
2007-12-06 09:46:23 +00:00
|
|
|
} else {
|
2009-08-16 19:12:07 +00:00
|
|
|
window_copy_update_cursor(wp, data->cx - 1, data->cy);
|
2009-01-11 23:31:46 +00:00
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
2007-11-22 19:17:01 +00:00
|
|
|
}
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_cursor_right(struct window_pane *wp)
|
2007-11-22 18:09:43 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
u_int px, py;
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2010-02-26 13:29:25 +00:00
|
|
|
if (data->screen.sel.flag && data->rectflag)
|
|
|
|
px = screen_size_x(&data->screen);
|
|
|
|
else {
|
2010-04-05 05:11:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2010-02-26 13:29:25 +00:00
|
|
|
px = window_copy_find_length(wp, py);
|
|
|
|
}
|
2007-12-06 09:46:23 +00:00
|
|
|
|
|
|
|
if (data->cx >= px) {
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_cursor_start_of_line(wp);
|
2009-10-06 14:10:10 +00:00
|
|
|
window_copy_cursor_down(wp, 0);
|
2007-12-06 09:46:23 +00:00
|
|
|
} else {
|
2009-08-16 19:12:07 +00:00
|
|
|
window_copy_update_cursor(wp, data->cx + 1, data->cy);
|
2009-01-11 23:31:46 +00:00
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
2007-11-22 19:17:01 +00:00
|
|
|
}
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-10-06 14:10:10 +00:00
|
|
|
window_copy_cursor_up(struct window_pane *wp, int scroll_only)
|
2007-11-22 18:09:43 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-01-25 17:14:42 +00:00
|
|
|
struct screen *s = &data->screen;
|
2007-12-06 09:46:23 +00:00
|
|
|
u_int ox, oy, px, py;
|
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
2009-01-11 23:31:46 +00:00
|
|
|
ox = window_copy_find_length(wp, oy);
|
2012-03-18 01:35:39 +00:00
|
|
|
if (data->cx != ox) {
|
2009-08-21 21:12:07 +00:00
|
|
|
data->lastcx = data->cx;
|
|
|
|
data->lastsx = ox;
|
|
|
|
}
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2009-08-21 21:12:07 +00:00
|
|
|
data->cx = data->lastcx;
|
2009-10-06 14:10:10 +00:00
|
|
|
if (scroll_only || data->cy == 0) {
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_scroll_down(wp, 1);
|
2010-01-25 17:14:42 +00:00
|
|
|
if (scroll_only) {
|
|
|
|
if (data->cy == screen_size_y(s) - 1)
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
|
|
|
else
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 2);
|
|
|
|
}
|
2009-10-06 14:10:10 +00:00
|
|
|
} else {
|
2009-08-16 19:12:07 +00:00
|
|
|
window_copy_update_cursor(wp, data->cx, data->cy - 1);
|
2010-01-25 17:14:42 +00:00
|
|
|
if (window_copy_update_selection(wp)) {
|
|
|
|
if (data->cy == screen_size_y(s) - 1)
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
|
|
|
else
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 2);
|
|
|
|
}
|
2007-11-22 19:17:01 +00:00
|
|
|
}
|
2007-12-06 09:46:23 +00:00
|
|
|
|
2010-02-26 13:29:25 +00:00
|
|
|
if (!data->screen.sel.flag || !data->rectflag) {
|
2010-04-05 05:11:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2010-02-26 13:29:25 +00:00
|
|
|
px = window_copy_find_length(wp, py);
|
2010-03-08 14:56:17 +00:00
|
|
|
if ((data->cx >= data->lastsx && data->cx != px) ||
|
|
|
|
data->cx > px)
|
2010-02-26 13:29:25 +00:00
|
|
|
window_copy_cursor_end_of_line(wp);
|
|
|
|
}
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-10-06 14:10:10 +00:00
|
|
|
window_copy_cursor_down(struct window_pane *wp, int scroll_only)
|
2007-11-22 18:09:43 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
u_int ox, oy, px, py;
|
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
2009-01-11 23:31:46 +00:00
|
|
|
ox = window_copy_find_length(wp, oy);
|
2012-03-18 01:35:39 +00:00
|
|
|
if (data->cx != ox) {
|
2009-08-21 21:12:07 +00:00
|
|
|
data->lastcx = data->cx;
|
|
|
|
data->lastsx = ox;
|
|
|
|
}
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2009-08-21 21:12:07 +00:00
|
|
|
data->cx = data->lastcx;
|
2009-10-06 14:10:10 +00:00
|
|
|
if (scroll_only || data->cy == screen_size_y(s) - 1) {
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_scroll_up(wp, 1);
|
2009-10-23 17:17:20 +00:00
|
|
|
if (scroll_only && data->cy > 0)
|
2009-10-06 14:10:10 +00:00
|
|
|
window_copy_redraw_lines(wp, data->cy - 1, 2);
|
|
|
|
} else {
|
2009-08-16 19:12:07 +00:00
|
|
|
window_copy_update_cursor(wp, data->cx, data->cy + 1);
|
2009-01-11 23:31:46 +00:00
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy - 1, 2);
|
2007-11-22 19:17:01 +00:00
|
|
|
}
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2010-02-26 13:29:25 +00:00
|
|
|
if (!data->screen.sel.flag || !data->rectflag) {
|
2010-04-05 05:11:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2010-02-26 13:29:25 +00:00
|
|
|
px = window_copy_find_length(wp, py);
|
2010-03-08 14:56:17 +00:00
|
|
|
if ((data->cx >= data->lastsx && data->cx != px) ||
|
|
|
|
data->cx > px)
|
2010-02-26 13:29:25 +00:00
|
|
|
window_copy_cursor_end_of_line(wp);
|
|
|
|
}
|
2007-11-22 19:17:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-16 17:30:58 +00:00
|
|
|
void
|
|
|
|
window_copy_cursor_jump(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-04-05 05:11:44 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2010-03-16 17:30:58 +00:00
|
|
|
const struct grid_cell *gc;
|
2013-01-18 02:16:21 +00:00
|
|
|
struct utf8_data ud;
|
2011-04-06 22:18:56 +00:00
|
|
|
u_int px, py, xx;
|
2010-03-16 17:30:58 +00:00
|
|
|
|
|
|
|
px = data->cx + 1;
|
2010-04-05 05:11:44 +00:00
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
2010-03-16 17:30:58 +00:00
|
|
|
xx = window_copy_find_length(wp, py);
|
|
|
|
|
|
|
|
while (px < xx) {
|
2010-04-05 05:11:44 +00:00
|
|
|
gc = grid_peek_cell(back_s->grid, px, py);
|
2013-01-18 02:16:21 +00:00
|
|
|
grid_cell_get(gc, &ud);
|
|
|
|
if (!(gc->flags & GRID_FLAG_PADDING) &&
|
|
|
|
ud.size == 1 && *ud.data == data->jumpchar) {
|
2010-03-16 17:30:58 +00:00
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
px++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_cursor_jump_back(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-04-05 05:11:44 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2010-03-16 17:30:58 +00:00
|
|
|
const struct grid_cell *gc;
|
2013-01-18 02:16:21 +00:00
|
|
|
struct utf8_data ud;
|
2011-04-06 22:18:56 +00:00
|
|
|
u_int px, py;
|
2010-03-16 17:30:58 +00:00
|
|
|
|
|
|
|
px = data->cx;
|
2010-04-05 05:11:44 +00:00
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
2010-03-16 17:30:58 +00:00
|
|
|
|
|
|
|
if (px > 0)
|
|
|
|
px--;
|
|
|
|
|
|
|
|
for (;;) {
|
2010-04-05 05:11:44 +00:00
|
|
|
gc = grid_peek_cell(back_s->grid, px, py);
|
2013-01-18 02:16:21 +00:00
|
|
|
grid_cell_get(gc, &ud);
|
|
|
|
if (!(gc->flags & GRID_FLAG_PADDING) &&
|
|
|
|
ud.size == 1 && *ud.data == data->jumpchar) {
|
2010-03-16 17:30:58 +00:00
|
|
|
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--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-06 18:50:26 +00:00
|
|
|
void
|
|
|
|
window_copy_cursor_jump_to(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *back_s = data->backing;
|
|
|
|
const struct grid_cell *gc;
|
2013-01-18 02:16:21 +00:00
|
|
|
struct utf8_data ud;
|
2011-12-06 18:50:26 +00:00
|
|
|
u_int 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);
|
2013-01-18 02:16:21 +00:00
|
|
|
grid_cell_get(gc, &ud);
|
|
|
|
if (!(gc->flags & GRID_FLAG_PADDING) &&
|
|
|
|
ud.size == 1 && *ud.data == data->jumpchar) {
|
2011-12-06 18:50:26 +00:00
|
|
|
window_copy_update_cursor(wp, px - 1, data->cy);
|
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
px++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_cursor_jump_to_back(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *back_s = data->backing;
|
|
|
|
const struct grid_cell *gc;
|
2013-01-18 02:16:21 +00:00
|
|
|
struct utf8_data ud;
|
2011-12-06 18:50:26 +00:00
|
|
|
u_int 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);
|
2013-01-18 02:16:21 +00:00
|
|
|
grid_cell_get(gc, &ud);
|
|
|
|
if (!(gc->flags & GRID_FLAG_PADDING) &&
|
|
|
|
ud.size == 1 && *ud.data == data->jumpchar) {
|
2011-12-06 18:50:26 +00:00
|
|
|
window_copy_update_cursor(wp, px + 1, data->cy);
|
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (px == 0)
|
|
|
|
break;
|
|
|
|
px--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-24 07:00:39 +00:00
|
|
|
void
|
2010-02-05 01:34:08 +00:00
|
|
|
window_copy_cursor_next_word(struct window_pane *wp, const char *separators)
|
2008-06-24 07:00:39 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-04-05 05:11:44 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2010-01-28 22:43:24 +00:00
|
|
|
u_int px, py, xx, yy;
|
2010-02-26 13:31:39 +00:00
|
|
|
int expected = 0;
|
2008-06-24 07:00:39 +00:00
|
|
|
|
2009-08-16 19:12:07 +00:00
|
|
|
px = data->cx;
|
2010-04-05 05:11:44 +00:00
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
2009-01-11 23:31:46 +00:00
|
|
|
xx = window_copy_find_length(wp, py);
|
2010-04-05 05:11:44 +00:00
|
|
|
yy = screen_hsize(back_s) + screen_size_y(back_s) - 1;
|
2010-01-28 22:43:24 +00:00
|
|
|
|
2010-02-26 13:31:39 +00:00
|
|
|
/*
|
|
|
|
* First skip past any nonword characters and then any word characters.
|
|
|
|
*
|
|
|
|
* expected is initially set to 0 for the former and then 1 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;
|
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
2010-02-26 13:31:39 +00:00
|
|
|
xx = window_copy_find_length(wp, py);
|
|
|
|
} else
|
|
|
|
px++;
|
|
|
|
}
|
|
|
|
expected = !expected;
|
|
|
|
} while (expected == 1);
|
2010-01-28 22:45:57 +00:00
|
|
|
|
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-02-05 01:34:08 +00:00
|
|
|
window_copy_cursor_next_word_end(struct window_pane *wp, const char *separators)
|
2010-01-28 22:45:57 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-04-05 05:11:44 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2010-01-28 22:45:57 +00:00
|
|
|
u_int px, py, xx, yy;
|
2010-02-26 13:31:39 +00:00
|
|
|
int expected = 1;
|
2010-01-28 22:45:57 +00:00
|
|
|
|
|
|
|
px = data->cx;
|
2010-04-05 05:11:44 +00:00
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
2010-01-28 22:45:57 +00:00
|
|
|
xx = window_copy_find_length(wp, py);
|
2010-04-05 05:11:44 +00:00
|
|
|
yy = screen_hsize(back_s) + screen_size_y(back_s) - 1;
|
2010-01-28 22:45:57 +00:00
|
|
|
|
2010-02-26 13:31:39 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
2010-02-26 13:31:39 +00:00
|
|
|
xx = window_copy_find_length(wp, py);
|
|
|
|
} else
|
|
|
|
px++;
|
|
|
|
}
|
|
|
|
expected = !expected;
|
|
|
|
} while (expected == 0);
|
2010-01-28 22:43:24 +00:00
|
|
|
|
2009-08-16 19:12:07 +00:00
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
2008-06-24 07:00:39 +00:00
|
|
|
}
|
|
|
|
|
2009-07-28 22:39:29 +00:00
|
|
|
/* Move to the previous place where a word begins. */
|
2008-06-24 07:00:39 +00:00
|
|
|
void
|
2010-02-05 01:34:08 +00:00
|
|
|
window_copy_cursor_previous_word(struct window_pane *wp, const char *separators)
|
2008-06-24 07:00:39 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2009-07-28 22:39:29 +00:00
|
|
|
u_int px, py;
|
2008-06-24 07:00:39 +00:00
|
|
|
|
2009-08-16 19:12:07 +00:00
|
|
|
px = data->cx;
|
2010-04-05 05:11:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2008-06-24 07:00:39 +00:00
|
|
|
|
2009-07-28 22:39:29 +00:00
|
|
|
/* Move back to the previous word character. */
|
2008-06-24 07:00:39 +00:00
|
|
|
for (;;) {
|
2009-07-28 22:39:29 +00:00
|
|
|
if (px > 0) {
|
|
|
|
px--;
|
2010-02-05 01:34:08 +00:00
|
|
|
if (!window_copy_in_set(wp, px, py, separators))
|
2008-06-27 17:41:48 +00:00
|
|
|
break;
|
2008-06-24 07:00:39 +00:00
|
|
|
} else {
|
2009-07-28 22:39:29 +00:00
|
|
|
if (data->cy == 0 &&
|
2010-04-05 05:11:44 +00:00
|
|
|
(screen_hsize(data->backing) == 0 ||
|
|
|
|
data->oy >= screen_hsize(data->backing) - 1))
|
2009-07-28 22:39:29 +00:00
|
|
|
goto out;
|
2009-10-06 14:10:10 +00:00
|
|
|
window_copy_cursor_up(wp, 0);
|
2009-07-28 22:39:29 +00:00
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2009-07-28 22:39:29 +00:00
|
|
|
px = window_copy_find_length(wp, py);
|
2008-06-24 07:00:39 +00:00
|
|
|
}
|
2009-07-28 22:39:29 +00:00
|
|
|
}
|
2008-09-26 06:45:28 +00:00
|
|
|
|
2009-07-28 22:39:29 +00:00
|
|
|
/* Move back to the beginning of this word. */
|
2010-02-05 01:34:08 +00:00
|
|
|
while (px > 0 && !window_copy_in_set(wp, px - 1, py, separators))
|
2008-06-24 07:00:39 +00:00
|
|
|
px--;
|
|
|
|
|
2009-07-28 22:39:29 +00:00
|
|
|
out:
|
2009-08-16 19:12:07 +00:00
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_scroll_up(struct window_pane *wp, u_int ny)
|
2007-11-22 18:09:43 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
struct screen_write_ctx ctx;
|
2007-11-22 18:09:43 +00:00
|
|
|
|
|
|
|
if (data->oy < ny)
|
|
|
|
ny = data->oy;
|
|
|
|
if (ny == 0)
|
|
|
|
return;
|
|
|
|
data->oy -= ny;
|
2007-12-06 09:46:23 +00:00
|
|
|
|
2009-01-11 23:31:46 +00:00
|
|
|
screen_write_start(&ctx, wp, NULL);
|
2008-09-25 20:08:57 +00:00
|
|
|
screen_write_cursormove(&ctx, 0, 0);
|
|
|
|
screen_write_deleteline(&ctx, ny);
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_write_lines(wp, &ctx, screen_size_y(s) - ny, ny);
|
|
|
|
window_copy_write_line(wp, &ctx, 0);
|
2009-10-23 17:17:20 +00:00
|
|
|
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);
|
2010-02-08 18:13:17 +00:00
|
|
|
if (s->sel.flag && screen_size_y(s) > ny) {
|
|
|
|
window_copy_update_selection(wp);
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_write_line(wp, &ctx, screen_size_y(s) - ny - 1);
|
2010-02-08 18:13:17 +00:00
|
|
|
}
|
2008-09-25 20:08:57 +00:00
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
2010-02-08 18:13:17 +00:00
|
|
|
window_copy_update_selection(wp);
|
2007-12-06 09:46:23 +00:00
|
|
|
screen_write_stop(&ctx);
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_scroll_down(struct window_pane *wp, u_int ny)
|
2007-11-22 18:09:43 +00:00
|
|
|
{
|
2009-01-11 23:31:46 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
struct screen_write_ctx ctx;
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
if (ny > screen_hsize(data->backing))
|
2007-11-23 16:43:04 +00:00
|
|
|
return;
|
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
if (data->oy > screen_hsize(data->backing) - ny)
|
|
|
|
ny = screen_hsize(data->backing) - data->oy;
|
2007-11-22 18:09:43 +00:00
|
|
|
if (ny == 0)
|
|
|
|
return;
|
|
|
|
data->oy += ny;
|
2007-12-06 09:46:23 +00:00
|
|
|
|
2009-01-11 23:31:46 +00:00
|
|
|
screen_write_start(&ctx, wp, NULL);
|
2008-09-25 20:08:57 +00:00
|
|
|
screen_write_cursormove(&ctx, 0, 0);
|
|
|
|
screen_write_insertline(&ctx, ny);
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_write_lines(wp, &ctx, 0, ny);
|
2010-02-08 18:13:17 +00:00
|
|
|
if (s->sel.flag && screen_size_y(s) > ny) {
|
|
|
|
window_copy_update_selection(wp);
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_write_line(wp, &ctx, ny);
|
2010-02-08 18:13:17 +00:00
|
|
|
} else if (ny == 1) /* nuke position */
|
2009-01-11 23:31:46 +00:00
|
|
|
window_copy_write_line(wp, &ctx, 1);
|
2008-09-25 20:08:57 +00:00
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
2010-02-08 18:13:17 +00:00
|
|
|
window_copy_update_selection(wp);
|
2007-12-06 09:46:23 +00:00
|
|
|
screen_write_stop(&ctx);
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
2010-02-08 18:13:17 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_rectangle_toggle(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-02-26 13:29:25 +00:00
|
|
|
u_int px, py;
|
2010-02-08 18:13:17 +00:00
|
|
|
|
|
|
|
data->rectflag = !data->rectflag;
|
|
|
|
|
2010-04-05 05:11:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2010-02-26 13:29:25 +00:00
|
|
|
px = window_copy_find_length(wp, py);
|
|
|
|
if (data->cx > px)
|
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
|
|
|
|
2010-02-08 18:13:17 +00:00
|
|
|
window_copy_update_selection(wp);
|
|
|
|
window_copy_redraw_screen(wp);
|
|
|
|
}
|