2010-03-22 19:13:28 +00:00
|
|
|
/* $OpenBSD$ */
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
/*
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2009-06-01 22:58:49 +00:00
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
2013-11-09 00:48:57 +00:00
|
|
|
#include <ctype.h>
|
2009-08-18 07:08:26 +00:00
|
|
|
#include <stdlib.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static const char *window_copy_key_table(struct window_pane *);
|
|
|
|
static void window_copy_command(struct window_pane *, struct client *,
|
|
|
|
struct session *, struct args *, struct mouse_event *);
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
static struct screen *window_copy_init(struct window_pane *,
|
|
|
|
struct cmd_find_state *, struct args *);
|
2016-10-11 13:21:59 +00:00
|
|
|
static void window_copy_free(struct window_pane *);
|
2017-02-08 17:33:51 +00:00
|
|
|
static int window_copy_pagedown(struct window_pane *, int);
|
2016-10-11 13:21:59 +00:00
|
|
|
static void window_copy_next_paragraph(struct window_pane *);
|
|
|
|
static void window_copy_previous_paragraph(struct window_pane *);
|
|
|
|
static void window_copy_resize(struct window_pane *, u_int, u_int);
|
|
|
|
|
|
|
|
static void window_copy_redraw_selection(struct window_pane *, u_int);
|
|
|
|
static void window_copy_redraw_lines(struct window_pane *, u_int, u_int);
|
|
|
|
static void window_copy_redraw_screen(struct window_pane *);
|
|
|
|
static void window_copy_write_line(struct window_pane *,
|
|
|
|
struct screen_write_ctx *, u_int);
|
|
|
|
static void window_copy_write_lines(struct window_pane *,
|
|
|
|
struct screen_write_ctx *, u_int, u_int);
|
|
|
|
|
|
|
|
static void window_copy_scroll_to(struct window_pane *, u_int, u_int);
|
|
|
|
static int window_copy_search_compare(struct grid *, u_int, u_int,
|
|
|
|
struct grid *, u_int, int);
|
|
|
|
static int window_copy_search_lr(struct grid *, struct grid *, u_int *,
|
|
|
|
u_int, u_int, u_int, int);
|
|
|
|
static int window_copy_search_rl(struct grid *, struct grid *, u_int *,
|
|
|
|
u_int, u_int, u_int, int);
|
2017-01-05 09:07:15 +00:00
|
|
|
static int window_copy_search_marks(struct window_pane *, struct screen *);
|
2017-01-06 11:57:03 +00:00
|
|
|
static void window_copy_clear_marks(struct window_pane *);
|
2016-10-11 13:21:59 +00:00
|
|
|
static void window_copy_move_left(struct screen *, u_int *, u_int *);
|
|
|
|
static void window_copy_move_right(struct screen *, u_int *, u_int *);
|
|
|
|
static int window_copy_is_lowercase(const char *);
|
2017-01-06 11:57:03 +00:00
|
|
|
static int window_copy_search_jump(struct window_pane *, struct grid *,
|
2016-10-11 13:21:59 +00:00
|
|
|
struct grid *, u_int, u_int, u_int, int, int, int);
|
2017-01-06 11:57:03 +00:00
|
|
|
static int window_copy_search(struct window_pane *, int, int);
|
|
|
|
static int window_copy_search_up(struct window_pane *, int);
|
|
|
|
static int window_copy_search_down(struct window_pane *, int);
|
2016-10-11 13:21:59 +00:00
|
|
|
static void window_copy_goto_line(struct window_pane *, const char *);
|
|
|
|
static void window_copy_update_cursor(struct window_pane *, u_int, u_int);
|
|
|
|
static void window_copy_start_selection(struct window_pane *);
|
2016-11-24 13:38:44 +00:00
|
|
|
static int window_copy_adjust_selection(struct window_pane *, u_int *,
|
|
|
|
u_int *);
|
2016-10-11 13:21:59 +00:00
|
|
|
static int window_copy_update_selection(struct window_pane *, int);
|
2016-11-24 13:38:44 +00:00
|
|
|
static void window_copy_synchronize_cursor(struct window_pane *wp);
|
2016-11-15 09:53:23 +00:00
|
|
|
static void *window_copy_get_selection(struct window_pane *, size_t *);
|
2016-10-11 13:21:59 +00:00
|
|
|
static void window_copy_copy_buffer(struct window_pane *, const char *,
|
|
|
|
void *, size_t);
|
|
|
|
static void window_copy_copy_pipe(struct window_pane *, struct session *,
|
|
|
|
const char *, const char *);
|
|
|
|
static void window_copy_copy_selection(struct window_pane *, const char *);
|
|
|
|
static void window_copy_append_selection(struct window_pane *,
|
|
|
|
const char *);
|
|
|
|
static void window_copy_clear_selection(struct window_pane *);
|
|
|
|
static void window_copy_copy_line(struct window_pane *, char **, size_t *,
|
|
|
|
u_int, u_int, u_int);
|
|
|
|
static int window_copy_in_set(struct window_pane *, u_int, u_int,
|
|
|
|
const char *);
|
|
|
|
static u_int window_copy_find_length(struct window_pane *, u_int);
|
|
|
|
static void window_copy_cursor_start_of_line(struct window_pane *);
|
|
|
|
static void window_copy_cursor_back_to_indentation(struct window_pane *);
|
|
|
|
static void window_copy_cursor_end_of_line(struct window_pane *);
|
|
|
|
static void window_copy_other_end(struct window_pane *);
|
|
|
|
static void window_copy_cursor_left(struct window_pane *);
|
|
|
|
static void window_copy_cursor_right(struct window_pane *);
|
|
|
|
static void window_copy_cursor_up(struct window_pane *, int);
|
|
|
|
static void window_copy_cursor_down(struct window_pane *, int);
|
|
|
|
static void window_copy_cursor_jump(struct window_pane *);
|
|
|
|
static void window_copy_cursor_jump_back(struct window_pane *);
|
|
|
|
static void window_copy_cursor_jump_to(struct window_pane *, int);
|
|
|
|
static void window_copy_cursor_jump_to_back(struct window_pane *, int);
|
|
|
|
static void window_copy_cursor_next_word(struct window_pane *,
|
|
|
|
const char *);
|
|
|
|
static void window_copy_cursor_next_word_end(struct window_pane *,
|
|
|
|
const char *);
|
|
|
|
static void window_copy_cursor_previous_word(struct window_pane *,
|
|
|
|
const char *);
|
|
|
|
static void window_copy_scroll_up(struct window_pane *, u_int);
|
|
|
|
static void window_copy_scroll_down(struct window_pane *, u_int);
|
|
|
|
static void window_copy_rectangle_toggle(struct window_pane *);
|
|
|
|
static void window_copy_move_mouse(struct mouse_event *);
|
|
|
|
static void window_copy_drag_update(struct client *, struct mouse_event *);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
const struct window_mode window_copy_mode = {
|
2017-05-07 22:27:57 +00:00
|
|
|
.name = "copy-mode",
|
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
.init = window_copy_init,
|
|
|
|
.free = window_copy_free,
|
|
|
|
.resize = window_copy_resize,
|
|
|
|
.key_table = window_copy_key_table,
|
|
|
|
.command = window_copy_command,
|
2009-06-01 22:58:49 +00:00
|
|
|
};
|
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
enum {
|
2009-08-18 07:08:26 +00:00
|
|
|
WINDOW_COPY_OFF,
|
|
|
|
WINDOW_COPY_SEARCHUP,
|
|
|
|
WINDOW_COPY_SEARCHDOWN,
|
2010-03-22 19:10:42 +00:00
|
|
|
WINDOW_COPY_JUMPFORWARD,
|
2016-10-11 07:23:34 +00:00
|
|
|
WINDOW_COPY_JUMPBACKWARD,
|
2011-12-04 16:18:01 +00:00
|
|
|
WINDOW_COPY_JUMPTOFORWARD,
|
2016-10-11 07:23:34 +00:00
|
|
|
WINDOW_COPY_JUMPTOBACKWARD,
|
2009-08-18 07:08:26 +00:00
|
|
|
};
|
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
enum {
|
|
|
|
WINDOW_COPY_REL_POS_ABOVE,
|
|
|
|
WINDOW_COPY_REL_POS_ON_SCREEN,
|
|
|
|
WINDOW_COPY_REL_POS_BELOW,
|
|
|
|
};
|
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
/*
|
2016-11-24 13:38: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).
|
2010-04-06 21:35:44 +00:00
|
|
|
*
|
2016-11-24 13:38:44 +00:00
|
|
|
* 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).
|
2010-04-06 21:35:44 +00:00
|
|
|
*/
|
2009-06-01 22:58:49 +00:00
|
|
|
struct window_copy_mode_data {
|
2016-10-11 07:23:34 +00:00
|
|
|
struct screen screen;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
struct screen *backing;
|
|
|
|
int backing_written; /* backing display started */
|
2010-04-06 21:35:44 +00:00
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
u_int oy; /* number of lines scrolled up */
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
u_int selx; /* beginning of selection */
|
2016-10-11 07:23:34 +00:00
|
|
|
u_int sely;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
u_int endselx; /* end of selection */
|
|
|
|
u_int endsely;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CURSORDRAG_NONE, /* selection is independent of cursor */
|
|
|
|
CURSORDRAG_ENDSEL, /* end is synchronized with cursor */
|
|
|
|
CURSORDRAG_SEL, /* start is synchronized with cursor */
|
|
|
|
} cursordrag;
|
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
int rectflag; /* in rectangle copy mode? */
|
|
|
|
int scroll_exit; /* exit on scroll to end? */
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
u_int cx;
|
|
|
|
u_int cy;
|
2010-02-06 17:35:01 +00:00
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
u_int lastcx; /* position in last line w/ content */
|
|
|
|
u_int lastsx; /* size of last line w/ content */
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
int searchtype;
|
|
|
|
char *searchstr;
|
2017-01-05 09:07:15 +00:00
|
|
|
bitstr_t *searchmark;
|
2017-03-24 07:14:27 +00:00
|
|
|
u_int searchcount;
|
|
|
|
int searchthis;
|
2017-01-06 11:57:03 +00:00
|
|
|
int searchx;
|
|
|
|
int searchy;
|
|
|
|
int searcho;
|
2009-08-21 07:33:58 +00:00
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
int jumptype;
|
|
|
|
char jumpchar;
|
2009-06-01 22:58:49 +00:00
|
|
|
};
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static struct screen *
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
window_copy_init(struct window_pane *wp, __unused struct cmd_find_state *fs,
|
|
|
|
__unused struct args *args)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data;
|
|
|
|
struct screen *s;
|
|
|
|
|
|
|
|
wp->modedata = data = xmalloc(sizeof *data);
|
2017-01-05 09:07:15 +00:00
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
data->oy = 0;
|
2010-04-06 21:35:44 +00:00
|
|
|
data->cx = 0;
|
|
|
|
data->cy = 0;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
data->cursordrag = CURSORDRAG_NONE;
|
|
|
|
|
2009-08-21 07:33:58 +00:00
|
|
|
data->lastcx = 0;
|
|
|
|
data->lastsx = 0;
|
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
data->backing_written = 0;
|
|
|
|
|
2010-02-06 17:35:01 +00:00
|
|
|
data->rectflag = 0;
|
2015-09-13 13:31:40 +00:00
|
|
|
data->scroll_exit = 0;
|
2010-02-06 17:35:01 +00:00
|
|
|
|
2017-05-12 10:45:38 +00:00
|
|
|
if (wp->searchstr != NULL) {
|
|
|
|
data->searchtype = WINDOW_COPY_SEARCHUP;
|
|
|
|
data->searchstr = xstrdup(wp->searchstr);
|
|
|
|
} else {
|
|
|
|
data->searchtype = WINDOW_COPY_OFF;
|
|
|
|
data->searchstr = NULL;
|
|
|
|
}
|
2017-01-05 09:07:15 +00:00
|
|
|
data->searchmark = NULL;
|
2017-01-06 11:57:03 +00:00
|
|
|
data->searchx = data->searchy = data->searcho = -1;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2010-07-22 21:10:51 +00:00
|
|
|
if (wp->fd != -1)
|
|
|
|
bufferevent_disable(wp->event, EV_READ|EV_WRITE);
|
2010-02-19 00:03:21 +00:00
|
|
|
|
2010-03-22 19:10:42 +00:00
|
|
|
data->jumptype = WINDOW_COPY_OFF;
|
|
|
|
data->jumpchar = '\0';
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
s = &data->screen;
|
|
|
|
screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
|
2016-10-11 07:23:34 +00:00
|
|
|
s->sel.modekeys = options_get_number(wp->window->options, "mode-keys");
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
data->backing = NULL;
|
|
|
|
|
|
|
|
return (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-09-14 11:57:22 +00:00
|
|
|
window_copy_init_from_pane(struct window_pane *wp, int scroll_exit)
|
2010-04-06 21:35:44 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
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;
|
2015-09-13 13:31:40 +00:00
|
|
|
data->scroll_exit = scroll_exit;
|
2010-04-06 21:35:44 +00:00
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
s->cx = data->cx;
|
|
|
|
s->cy = data->cy;
|
|
|
|
|
|
|
|
screen_write_start(&ctx, NULL, s);
|
|
|
|
for (i = 0; i < screen_size_y(s); i++)
|
|
|
|
window_copy_write_line(wp, &ctx, i);
|
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
|
|
|
screen_write_stop(&ctx);
|
2010-04-06 21:35:44 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2010-04-06 21:35: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);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_free(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
|
2010-07-22 21:10:51 +00:00
|
|
|
if (wp->fd != -1)
|
|
|
|
bufferevent_enable(wp->event, EV_READ|EV_WRITE);
|
2010-02-19 00:03:21 +00:00
|
|
|
|
2017-01-05 09:07:15 +00:00
|
|
|
free(data->searchmark);
|
2012-07-10 11:53:01 +00:00
|
|
|
free(data->searchstr);
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
if (data->backing != &wp->base) {
|
|
|
|
screen_free(data->backing);
|
2012-07-10 11:53:01 +00:00
|
|
|
free(data->backing);
|
2010-04-06 21:35:44 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
screen_free(&data->screen);
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2012-07-10 11:53:01 +00:00
|
|
|
free(data);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2010-04-06 21:35: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;
|
2014-11-06 10:56:44 +00:00
|
|
|
u_int old_hsize, old_cy;
|
2010-04-06 21:35:44 +00:00
|
|
|
|
|
|
|
if (backing == &wp->base)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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);
|
2017-05-12 13:00:56 +00:00
|
|
|
screen_write_linefeed(&back_ctx, 0, 8);
|
2010-04-06 21:35:44 +00:00
|
|
|
} else
|
|
|
|
data->backing_written = 1;
|
2014-11-06 10:56:44 +00:00
|
|
|
old_cy = backing->cy;
|
2015-11-12 11:09:11 +00:00
|
|
|
screen_write_vnputs(&back_ctx, 0, &gc, fmt, ap);
|
2010-04-06 21:35:44 +00:00
|
|
|
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);
|
|
|
|
|
2014-11-06 10:56:44 +00:00
|
|
|
/* Write the new lines. */
|
|
|
|
window_copy_redraw_lines(wp, old_cy, backing->cy - old_cy + 1);
|
2010-04-06 21:35:44 +00:00
|
|
|
|
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
2016-05-01 13:39:05 +00:00
|
|
|
window_copy_pageup(struct window_pane *wp, int half_page)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
2017-01-05 09:07:15 +00:00
|
|
|
u_int n, ox, oy, px, py;
|
2016-03-18 14:27:24 +00:00
|
|
|
|
|
|
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
ox = window_copy_find_length(wp, oy);
|
|
|
|
|
|
|
|
if (s->sel.lineflag == LINE_SEL_LEFT_RIGHT && oy == data->sely)
|
|
|
|
window_copy_other_end(wp);
|
|
|
|
|
|
|
|
if (data->cx != ox) {
|
|
|
|
data->lastcx = data->cx;
|
|
|
|
data->lastsx = ox;
|
|
|
|
}
|
|
|
|
data->cx = data->lastcx;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-08-13 22:11:43 +00:00
|
|
|
n = 1;
|
2016-05-01 13:39:05 +00:00
|
|
|
if (screen_size_y(s) > 2) {
|
|
|
|
if (half_page)
|
|
|
|
n = screen_size_y(s) / 2;
|
|
|
|
else
|
|
|
|
n = screen_size_y(s) - 2;
|
|
|
|
}
|
2016-03-18 14:27:24 +00:00
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
if (data->oy + n > screen_hsize(data->backing))
|
|
|
|
data->oy = screen_hsize(data->backing);
|
2009-06-01 22:58:49 +00:00
|
|
|
else
|
2009-08-13 22:11:43 +00:00
|
|
|
data->oy += n;
|
2016-03-18 14:27:24 +00:00
|
|
|
|
|
|
|
if (!data->screen.sel.flag || !data->rectflag) {
|
2017-01-05 09:07:15 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
px = window_copy_find_length(wp, py);
|
|
|
|
if ((data->cx >= data->lastsx && data->cx != px) ||
|
|
|
|
data->cx > px)
|
2016-03-18 14:27:24 +00:00
|
|
|
window_copy_cursor_end_of_line(wp);
|
|
|
|
}
|
|
|
|
|
|
|
|
window_copy_update_selection(wp, 1);
|
|
|
|
window_copy_redraw_screen(wp);
|
|
|
|
}
|
|
|
|
|
2017-02-08 17:33:51 +00:00
|
|
|
static int
|
2016-05-01 13:39:05 +00:00
|
|
|
window_copy_pagedown(struct window_pane *wp, int half_page)
|
2016-03-18 14:27:24 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
2016-11-24 13:38:44 +00:00
|
|
|
u_int n, ox, oy, px, py;
|
2016-03-18 14:27:24 +00:00
|
|
|
|
|
|
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
ox = window_copy_find_length(wp, oy);
|
|
|
|
|
|
|
|
if (s->sel.lineflag == LINE_SEL_RIGHT_LEFT && oy == data->sely)
|
|
|
|
window_copy_other_end(wp);
|
|
|
|
|
|
|
|
if (data->cx != ox) {
|
|
|
|
data->lastcx = data->cx;
|
|
|
|
data->lastsx = ox;
|
|
|
|
}
|
|
|
|
data->cx = data->lastcx;
|
|
|
|
|
|
|
|
n = 1;
|
2016-05-01 13:39:05 +00:00
|
|
|
if (screen_size_y(s) > 2) {
|
|
|
|
if (half_page)
|
|
|
|
n = screen_size_y(s) / 2;
|
|
|
|
else
|
|
|
|
n = screen_size_y(s) - 2;
|
|
|
|
}
|
2016-03-18 14:27:24 +00:00
|
|
|
|
|
|
|
if (data->oy < n)
|
|
|
|
data->oy = 0;
|
|
|
|
else
|
|
|
|
data->oy -= n;
|
|
|
|
|
|
|
|
if (!data->screen.sel.flag || !data->rectflag) {
|
2016-11-24 13:38:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
px = window_copy_find_length(wp, py);
|
|
|
|
if ((data->cx >= data->lastsx && data->cx != px) ||
|
|
|
|
data->cx > px)
|
2016-03-18 14:27:24 +00:00
|
|
|
window_copy_cursor_end_of_line(wp);
|
|
|
|
}
|
|
|
|
|
2017-02-08 17:33:51 +00:00
|
|
|
if (data->scroll_exit && data->oy == 0)
|
|
|
|
return (1);
|
2013-11-08 12:39:20 +00:00
|
|
|
window_copy_update_selection(wp, 1);
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_redraw_screen(wp);
|
2017-02-08 17:33:51 +00:00
|
|
|
return (0);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2016-04-27 09:39:09 +00:00
|
|
|
window_copy_previous_paragraph(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2016-05-23 20:03:14 +00:00
|
|
|
u_int oy;
|
2016-04-27 09:39:09 +00:00
|
|
|
|
|
|
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
|
|
|
|
while (oy > 0 && window_copy_find_length(wp, oy) == 0)
|
|
|
|
oy--;
|
|
|
|
|
|
|
|
while (oy > 0 && window_copy_find_length(wp, oy) > 0)
|
|
|
|
oy--;
|
|
|
|
|
|
|
|
window_copy_scroll_to(wp, 0, oy);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2016-04-27 09:39:09 +00:00
|
|
|
window_copy_next_paragraph(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
u_int maxy, ox, oy;
|
|
|
|
|
|
|
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
maxy = screen_hsize(data->backing) + screen_size_y(s) - 1;
|
|
|
|
|
|
|
|
while (oy < maxy && window_copy_find_length(wp, oy) == 0)
|
|
|
|
oy++;
|
|
|
|
|
|
|
|
while (oy < maxy && window_copy_find_length(wp, oy) > 0)
|
|
|
|
oy++;
|
|
|
|
|
|
|
|
ox = window_copy_find_length(wp, oy);
|
|
|
|
window_copy_scroll_to(wp, ox, oy);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_resize(struct window_pane *wp, u_int sx, u_int sy)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
|
2014-11-06 10:56:44 +00:00
|
|
|
screen_resize(s, sx, sy, 1);
|
2010-04-06 21:35:44 +00:00
|
|
|
if (data->backing != &wp->base)
|
2014-11-06 10:56:44 +00:00
|
|
|
screen_resize(data->backing, sx, sy, 1);
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-08-13 19:35:20 +00:00
|
|
|
if (data->cy > sy - 1)
|
|
|
|
data->cy = sy - 1;
|
|
|
|
if (data->cx > sx)
|
|
|
|
data->cx = sx;
|
2010-09-11 15:39:55 +00:00
|
|
|
if (data->oy > screen_hsize(data->backing))
|
|
|
|
data->oy = screen_hsize(data->backing);
|
2009-08-13 19:35:20 +00:00
|
|
|
|
2010-02-22 20:28:21 +00:00
|
|
|
window_copy_clear_selection(wp);
|
2009-08-13 19:35:20 +00:00
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
screen_write_start(&ctx, NULL, s);
|
|
|
|
window_copy_write_lines(wp, &ctx, 0, screen_size_y(s) - 1);
|
|
|
|
screen_write_stop(&ctx);
|
2009-08-13 19:35:20 +00:00
|
|
|
|
2017-01-05 09:07:15 +00:00
|
|
|
if (data->searchmark != NULL)
|
|
|
|
window_copy_search_marks(wp, NULL);
|
2017-01-06 11:57:03 +00:00
|
|
|
data->searchx = data->cx;
|
|
|
|
data->searchy = data->cy;
|
|
|
|
data->searcho = data->oy;
|
2017-01-05 09:07:15 +00:00
|
|
|
|
2009-08-13 16:48:43 +00:00
|
|
|
window_copy_redraw_screen(wp);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static const char *
|
2016-10-11 07:23:34 +00:00
|
|
|
window_copy_key_table(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
if (options_get_number(wp->window->options, "mode-keys") == MODEKEY_VI)
|
|
|
|
return ("copy-mode-vi");
|
|
|
|
return ("copy-mode");
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2016-10-11 07:23:34 +00:00
|
|
|
window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
|
|
|
|
struct args *args, struct mouse_event *m)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2016-10-11 07:23:34 +00:00
|
|
|
struct screen *sn = &data->screen;
|
2017-01-05 09:07:15 +00:00
|
|
|
const char *command, *argument, *ws;
|
2016-10-11 07:23:34 +00:00
|
|
|
u_int np = wp->modeprefix;
|
2017-01-06 11:57:03 +00:00
|
|
|
int cancel = 0, redraw = 0;
|
|
|
|
char prefix;
|
2016-10-11 07:23:34 +00:00
|
|
|
|
|
|
|
if (args->argc == 0)
|
2009-08-18 07:08:26 +00:00
|
|
|
return;
|
2016-10-11 07:23:34 +00:00
|
|
|
command = args->argv[0];
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-10-11 09:30:36 +00:00
|
|
|
if (m != NULL && m->valid)
|
|
|
|
window_copy_move_mouse(m);
|
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
if (args->argc == 1) {
|
|
|
|
if (strcmp(command, "append-selection") == 0) {
|
|
|
|
if (s != NULL)
|
|
|
|
window_copy_append_selection(wp, NULL);
|
2015-04-10 16:00:08 +00:00
|
|
|
window_copy_clear_selection(wp);
|
2017-01-06 11:57:03 +00:00
|
|
|
redraw = 1;
|
2014-03-31 21:39:31 +00:00
|
|
|
}
|
2016-10-11 07:23:34 +00:00
|
|
|
if (strcmp(command, "append-selection-and-cancel") == 0) {
|
|
|
|
if (s != NULL)
|
|
|
|
window_copy_append_selection(wp, NULL);
|
|
|
|
window_copy_clear_selection(wp);
|
2017-01-06 11:57:03 +00:00
|
|
|
redraw = 1;
|
2017-01-05 09:07:15 +00:00
|
|
|
cancel = 1;
|
2015-09-13 13:31:40 +00:00
|
|
|
}
|
2016-10-11 07:23:34 +00:00
|
|
|
if (strcmp(command, "back-to-indentation") == 0)
|
|
|
|
window_copy_cursor_back_to_indentation(wp);
|
|
|
|
if (strcmp(command, "begin-selection") == 0) {
|
|
|
|
if (m != NULL)
|
2015-04-19 21:34:21 +00:00
|
|
|
window_copy_start_drag(c, m);
|
2016-10-11 07:23:34 +00:00
|
|
|
else {
|
|
|
|
sn->sel.lineflag = LINE_SEL_NONE;
|
|
|
|
window_copy_start_selection(wp);
|
2017-01-06 11:57:03 +00:00
|
|
|
redraw = 1;
|
2016-10-11 07:23:34 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-24 13:38:44 +00:00
|
|
|
if (strcmp(command, "stop-selection") == 0)
|
|
|
|
data->cursordrag = CURSORDRAG_NONE;
|
2016-10-11 07:23:34 +00:00
|
|
|
if (strcmp(command, "bottom-line") == 0) {
|
|
|
|
data->cx = 0;
|
|
|
|
data->cy = screen_size_y(sn) - 1;
|
|
|
|
window_copy_update_selection(wp, 1);
|
2017-01-06 11:57:03 +00:00
|
|
|
redraw = 1;
|
2015-04-19 21:34:21 +00:00
|
|
|
}
|
2016-10-11 07:23:34 +00:00
|
|
|
if (strcmp(command, "cancel") == 0)
|
2017-01-05 09:07:15 +00:00
|
|
|
cancel = 1;
|
2016-10-11 07:23:34 +00:00
|
|
|
if (strcmp(command, "clear-selection") == 0) {
|
|
|
|
window_copy_clear_selection(wp);
|
2017-01-06 11:57:03 +00:00
|
|
|
redraw = 1;
|
2011-05-18 18:06:36 +00:00
|
|
|
}
|
2016-10-11 07:23:34 +00:00
|
|
|
if (strcmp(command, "copy-end-of-line") == 0) {
|
|
|
|
window_copy_start_selection(wp);
|
|
|
|
for (; np > 1; np--)
|
|
|
|
window_copy_cursor_down(wp, 0);
|
|
|
|
window_copy_cursor_end_of_line(wp);
|
2017-01-06 11:57:03 +00:00
|
|
|
redraw = 1;
|
2016-10-11 07:23:34 +00:00
|
|
|
|
|
|
|
if (s != NULL) {
|
|
|
|
window_copy_copy_selection(wp, NULL);
|
2017-01-05 09:07:15 +00:00
|
|
|
cancel = 1;
|
2016-10-11 07:23:34 +00:00
|
|
|
}
|
2013-03-22 15:52:40 +00:00
|
|
|
}
|
2016-10-11 07:23:34 +00:00
|
|
|
if (strcmp(command, "copy-line") == 0) {
|
|
|
|
window_copy_cursor_start_of_line(wp);
|
|
|
|
window_copy_start_selection(wp);
|
|
|
|
for (; np > 1; np--)
|
|
|
|
window_copy_cursor_down(wp, 0);
|
|
|
|
window_copy_cursor_end_of_line(wp);
|
2017-01-06 11:57:03 +00:00
|
|
|
redraw = 1;
|
2016-10-11 07:23:34 +00:00
|
|
|
|
|
|
|
if (s != NULL) {
|
|
|
|
window_copy_copy_selection(wp, NULL);
|
2017-01-05 09:07:15 +00:00
|
|
|
cancel = 1;
|
2015-04-10 16:00:08 +00:00
|
|
|
}
|
2016-10-11 07:23:34 +00:00
|
|
|
}
|
|
|
|
if (strcmp(command, "copy-selection") == 0) {
|
|
|
|
if (s != NULL)
|
|
|
|
window_copy_copy_selection(wp, NULL);
|
2015-04-10 16:00:08 +00:00
|
|
|
window_copy_clear_selection(wp);
|
2017-01-06 11:57:03 +00:00
|
|
|
redraw = 1;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2016-10-11 07:23:34 +00:00
|
|
|
if (strcmp(command, "copy-selection-and-cancel") == 0) {
|
|
|
|
if (s != NULL)
|
|
|
|
window_copy_copy_selection(wp, NULL);
|
|
|
|
window_copy_clear_selection(wp);
|
2017-01-06 11:57:03 +00:00
|
|
|
redraw = 1;
|
2017-01-05 09:07:15 +00:00
|
|
|
cancel = 1;
|
2016-10-11 07:23:34 +00:00
|
|
|
}
|
|
|
|
if (strcmp(command, "cursor-down") == 0) {
|
2010-03-22 19:10:42 +00:00
|
|
|
for (; np != 0; np--)
|
2016-10-11 07:23:34 +00:00
|
|
|
window_copy_cursor_down(wp, 0);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "cursor-left") == 0) {
|
2010-03-22 19:10:42 +00:00
|
|
|
for (; np != 0; np--)
|
2016-10-11 07:23:34 +00:00
|
|
|
window_copy_cursor_left(wp);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "cursor-right") == 0) {
|
2011-12-04 16:18:01 +00:00
|
|
|
for (; np != 0; np--)
|
2016-10-11 07:23:34 +00:00
|
|
|
window_copy_cursor_right(wp);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "cursor-up") == 0) {
|
2011-12-04 16:18:01 +00:00
|
|
|
for (; np != 0; np--)
|
2016-10-11 07:23:34 +00:00
|
|
|
window_copy_cursor_up(wp, 0);
|
2010-03-22 19:10:42 +00:00
|
|
|
}
|
2016-10-11 07:23:34 +00:00
|
|
|
if (strcmp(command, "end-of-line") == 0)
|
|
|
|
window_copy_cursor_end_of_line(wp);
|
|
|
|
if (strcmp(command, "halfpage-down") == 0) {
|
2017-02-08 17:33:51 +00:00
|
|
|
for (; np != 0; np--) {
|
|
|
|
if (window_copy_pagedown(wp, 1)) {
|
|
|
|
cancel = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-10-11 07:23:34 +00:00
|
|
|
}
|
|
|
|
if (strcmp(command, "halfpage-up") == 0) {
|
2010-03-22 19:10:42 +00:00
|
|
|
for (; np != 0; np--)
|
2016-10-11 07:23:34 +00:00
|
|
|
window_copy_pageup(wp, 1);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "history-bottom") == 0) {
|
|
|
|
data->cx = 0;
|
|
|
|
data->cy = screen_size_y(sn) - 1;
|
|
|
|
data->oy = 0;
|
|
|
|
window_copy_update_selection(wp, 1);
|
2017-01-06 11:57:03 +00:00
|
|
|
redraw = 1;
|
2016-10-11 07:23:34 +00:00
|
|
|
}
|
|
|
|
if (strcmp(command, "history-top") == 0) {
|
|
|
|
data->cx = 0;
|
|
|
|
data->cy = 0;
|
|
|
|
data->oy = screen_hsize(data->backing);
|
|
|
|
window_copy_update_selection(wp, 1);
|
2017-01-06 11:57:03 +00:00
|
|
|
redraw = 1;
|
2016-10-11 07:23:34 +00:00
|
|
|
}
|
|
|
|
if (strcmp(command, "jump-again") == 0) {
|
|
|
|
switch (data->jumptype) {
|
|
|
|
case WINDOW_COPY_JUMPFORWARD:
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump(wp);
|
|
|
|
break;
|
|
|
|
case WINDOW_COPY_JUMPBACKWARD:
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_back(wp);
|
|
|
|
break;
|
|
|
|
case WINDOW_COPY_JUMPTOFORWARD:
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to(wp, 1);
|
|
|
|
break;
|
|
|
|
case WINDOW_COPY_JUMPTOBACKWARD:
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to_back(wp, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (strcmp(command, "jump-reverse") == 0) {
|
|
|
|
switch (data->jumptype) {
|
|
|
|
case WINDOW_COPY_JUMPFORWARD:
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_back(wp);
|
|
|
|
break;
|
|
|
|
case WINDOW_COPY_JUMPBACKWARD:
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump(wp);
|
|
|
|
break;
|
|
|
|
case WINDOW_COPY_JUMPTOFORWARD:
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to_back(wp, 1);
|
|
|
|
break;
|
|
|
|
case WINDOW_COPY_JUMPTOBACKWARD:
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to(wp, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (strcmp(command, "middle-line") == 0) {
|
|
|
|
data->cx = 0;
|
|
|
|
data->cy = (screen_size_y(sn) - 1) / 2;
|
|
|
|
window_copy_update_selection(wp, 1);
|
2017-01-06 11:57:03 +00:00
|
|
|
redraw = 1;
|
2016-10-11 07:23:34 +00:00
|
|
|
}
|
|
|
|
if (strcmp(command, "next-paragraph") == 0) {
|
2011-12-04 16:18:01 +00:00
|
|
|
for (; np != 0; np--)
|
2016-10-11 07:23:34 +00:00
|
|
|
window_copy_next_paragraph(wp);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "next-space") == 0) {
|
2011-12-04 16:18:01 +00:00
|
|
|
for (; np != 0; np--)
|
2016-10-11 07:23:34 +00:00
|
|
|
window_copy_cursor_next_word(wp, " ");
|
2010-03-22 19:10:42 +00:00
|
|
|
}
|
2016-10-11 07:23:34 +00:00
|
|
|
if (strcmp(command, "next-space-end") == 0) {
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_next_word_end(wp, " ");
|
|
|
|
}
|
|
|
|
if (strcmp(command, "next-word") == 0) {
|
|
|
|
ws = options_get_string(s->options, "word-separators");
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_next_word(wp, ws);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "next-word-end") == 0) {
|
|
|
|
ws = options_get_string(s->options, "word-separators");
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_next_word_end(wp, ws);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "other-end") == 0) {
|
|
|
|
if ((np % 2) != 0)
|
|
|
|
window_copy_other_end(wp);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "page-down") == 0) {
|
2017-02-08 17:33:51 +00:00
|
|
|
for (; np != 0; np--) {
|
|
|
|
if (window_copy_pagedown(wp, 0)) {
|
|
|
|
cancel = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-10-11 07:23:34 +00:00
|
|
|
}
|
|
|
|
if (strcmp(command, "page-up") == 0) {
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_pageup(wp, 0);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "previous-paragraph") == 0) {
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_previous_paragraph(wp);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "previous-space") == 0) {
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_previous_word(wp, " ");
|
|
|
|
}
|
|
|
|
if (strcmp(command, "previous-word") == 0) {
|
|
|
|
ws = options_get_string(s->options, "word-separators");
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_previous_word(wp, ws);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "rectangle-toggle") == 0) {
|
|
|
|
sn->sel.lineflag = LINE_SEL_NONE;
|
|
|
|
window_copy_rectangle_toggle(wp);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "scroll-down") == 0) {
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_down(wp, 1);
|
|
|
|
if (data->scroll_exit && data->oy == 0)
|
2017-01-05 09:07:15 +00:00
|
|
|
cancel = 1;
|
2016-10-11 07:23:34 +00:00
|
|
|
}
|
|
|
|
if (strcmp(command, "scroll-up") == 0) {
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_up(wp, 1);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "search-again") == 0) {
|
|
|
|
if (data->searchtype == WINDOW_COPY_SEARCHUP) {
|
2014-11-06 09:17:25 +00:00
|
|
|
for (; np != 0; np--)
|
2017-01-05 09:07:15 +00:00
|
|
|
window_copy_search_up(wp, 1);
|
2016-10-11 07:23:34 +00:00
|
|
|
} else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) {
|
2014-11-06 09:17:25 +00:00
|
|
|
for (; np != 0; np--)
|
2017-01-05 09:07:15 +00:00
|
|
|
window_copy_search_down(wp, 1);
|
2010-03-02 00:32:41 +00:00
|
|
|
}
|
2016-10-11 07:23:34 +00:00
|
|
|
}
|
|
|
|
if (strcmp(command, "search-reverse") == 0) {
|
|
|
|
if (data->searchtype == WINDOW_COPY_SEARCHUP) {
|
2014-11-06 09:17:25 +00:00
|
|
|
for (; np != 0; np--)
|
2017-01-05 09:07:15 +00:00
|
|
|
window_copy_search_down(wp, 1);
|
2016-10-11 07:23:34 +00:00
|
|
|
} else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) {
|
2014-11-06 09:17:25 +00:00
|
|
|
for (; np != 0; np--)
|
2017-01-05 09:07:15 +00:00
|
|
|
window_copy_search_up(wp, 1);
|
2010-03-02 00:32:41 +00:00
|
|
|
}
|
2009-08-18 07:08:26 +00:00
|
|
|
}
|
2016-10-11 07:23:34 +00:00
|
|
|
if (strcmp(command, "select-line") == 0) {
|
|
|
|
sn->sel.lineflag = LINE_SEL_LEFT_RIGHT;
|
|
|
|
data->rectflag = 0;
|
|
|
|
window_copy_cursor_start_of_line(wp);
|
|
|
|
window_copy_start_selection(wp);
|
|
|
|
for (; np > 1; np--)
|
|
|
|
window_copy_cursor_down(wp, 0);
|
|
|
|
window_copy_cursor_end_of_line(wp);
|
2017-01-06 11:57:03 +00:00
|
|
|
redraw = 1;
|
2010-03-02 00:32:41 +00:00
|
|
|
}
|
2016-10-11 09:30:36 +00:00
|
|
|
if (strcmp(command, "select-word") == 0) {
|
|
|
|
sn->sel.lineflag = LINE_SEL_LEFT_RIGHT;
|
|
|
|
data->rectflag = 0;
|
|
|
|
ws = options_get_string(s->options, "word-separators");
|
|
|
|
window_copy_cursor_previous_word(wp, ws);
|
|
|
|
window_copy_start_selection(wp);
|
|
|
|
window_copy_cursor_next_word_end(wp, ws);
|
2017-01-06 11:57:03 +00:00
|
|
|
redraw = 1;
|
2014-01-22 22:32:15 +00:00
|
|
|
}
|
2016-10-11 09:30:36 +00:00
|
|
|
if (strcmp(command, "start-of-line") == 0)
|
|
|
|
window_copy_cursor_start_of_line(wp);
|
2016-10-11 07:23:34 +00:00
|
|
|
if (strcmp(command, "top-line") == 0) {
|
|
|
|
data->cx = 0;
|
|
|
|
data->cy = 0;
|
|
|
|
window_copy_update_selection(wp, 1);
|
2017-01-06 11:57:03 +00:00
|
|
|
redraw = 1;
|
2016-10-11 07:23:34 +00:00
|
|
|
}
|
|
|
|
} else if (args->argc == 2 && *args->argv[1] != '\0') {
|
|
|
|
argument = args->argv[1];
|
|
|
|
if (strcmp(command, "copy-pipe") == 0) {
|
2016-11-15 09:53:23 +00:00
|
|
|
if (s != NULL)
|
|
|
|
window_copy_copy_pipe(wp, s, NULL, argument);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "copy-pipe-and-cancel") == 0) {
|
2016-10-11 07:23:34 +00:00
|
|
|
if (s != NULL) {
|
|
|
|
window_copy_copy_pipe(wp, s, NULL, argument);
|
2017-01-05 09:07:15 +00:00
|
|
|
cancel = 1;
|
2015-04-10 16:00:08 +00:00
|
|
|
}
|
2009-08-18 07:08:26 +00:00
|
|
|
}
|
2016-10-11 07:23:34 +00:00
|
|
|
if (strcmp(command, "goto-line") == 0)
|
|
|
|
window_copy_goto_line(wp, argument);
|
|
|
|
if (strcmp(command, "jump-backward") == 0) {
|
|
|
|
data->jumptype = WINDOW_COPY_JUMPBACKWARD;
|
|
|
|
data->jumpchar = *argument;
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_back(wp);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "jump-forward") == 0) {
|
|
|
|
data->jumptype = WINDOW_COPY_JUMPFORWARD;
|
|
|
|
data->jumpchar = *argument;
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump(wp);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "jump-to-backward") == 0) {
|
|
|
|
data->jumptype = WINDOW_COPY_JUMPTOBACKWARD;
|
|
|
|
data->jumpchar = *argument;
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to_back(wp, 1);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "jump-to-forward") == 0) {
|
|
|
|
data->jumptype = WINDOW_COPY_JUMPTOFORWARD;
|
|
|
|
data->jumpchar = *argument;
|
|
|
|
for (; np != 0; np--)
|
|
|
|
window_copy_cursor_jump_to(wp, 1);
|
|
|
|
}
|
|
|
|
if (strcmp(command, "search-backward") == 0) {
|
|
|
|
data->searchtype = WINDOW_COPY_SEARCHUP;
|
2017-01-06 11:57:03 +00:00
|
|
|
free(data->searchstr);
|
2016-10-11 07:23:34 +00:00
|
|
|
data->searchstr = xstrdup(argument);
|
|
|
|
for (; np != 0; np--)
|
2017-01-05 09:07:15 +00:00
|
|
|
window_copy_search_up(wp, 1);
|
2016-10-11 07:23:34 +00:00
|
|
|
}
|
|
|
|
if (strcmp(command, "search-forward") == 0) {
|
|
|
|
data->searchtype = WINDOW_COPY_SEARCHDOWN;
|
2017-01-06 11:57:03 +00:00
|
|
|
free(data->searchstr);
|
2016-10-11 07:23:34 +00:00
|
|
|
data->searchstr = xstrdup(argument);
|
|
|
|
for (; np != 0; np--)
|
2017-01-05 09:07:15 +00:00
|
|
|
window_copy_search_down(wp, 1);
|
2016-10-11 07:23:34 +00:00
|
|
|
}
|
2017-01-06 11:57:03 +00:00
|
|
|
if (strcmp(command, "search-backward-incremental") == 0) {
|
|
|
|
prefix = *argument++;
|
|
|
|
if (data->searchx == -1 || data->searchy == -1) {
|
|
|
|
data->searchx = data->cx;
|
|
|
|
data->searchy = data->cy;
|
|
|
|
data->searcho = data->oy;
|
|
|
|
} else if (data->searchstr != NULL &&
|
|
|
|
strcmp(argument, data->searchstr) != 0) {
|
|
|
|
data->cx = data->searchx;
|
|
|
|
data->cy = data->searchy;
|
|
|
|
data->oy = data->searcho;
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
if (*argument == '\0') {
|
|
|
|
window_copy_clear_marks(wp);
|
|
|
|
redraw = 1;
|
|
|
|
} else if (prefix == '=' || prefix == '-') {
|
|
|
|
data->searchtype = WINDOW_COPY_SEARCHUP;
|
|
|
|
free(data->searchstr);
|
|
|
|
data->searchstr = xstrdup(argument);
|
|
|
|
if (!window_copy_search_up(wp, 1)) {
|
|
|
|
window_copy_clear_marks(wp);
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
} else if (prefix == '+') {
|
|
|
|
data->searchtype = WINDOW_COPY_SEARCHDOWN;
|
|
|
|
free(data->searchstr);
|
|
|
|
data->searchstr = xstrdup(argument);
|
|
|
|
if (!window_copy_search_down(wp, 1)) {
|
|
|
|
window_copy_clear_marks(wp);
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (strcmp(command, "search-forward-incremental") == 0) {
|
|
|
|
prefix = *argument++;
|
|
|
|
if (data->searchx == -1 || data->searchy == -1) {
|
|
|
|
data->searchx = data->cx;
|
|
|
|
data->searchy = data->cy;
|
|
|
|
data->searcho = data->oy;
|
|
|
|
} else if (data->searchstr != NULL &&
|
|
|
|
strcmp(argument, data->searchstr) != 0) {
|
|
|
|
data->cx = data->searchx;
|
|
|
|
data->cy = data->searchy;
|
|
|
|
data->oy = data->searcho;
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
if (*argument == '\0') {
|
|
|
|
window_copy_clear_marks(wp);
|
|
|
|
redraw = 1;
|
|
|
|
} else if (prefix == '=' || prefix == '+') {
|
|
|
|
data->searchtype = WINDOW_COPY_SEARCHDOWN;
|
|
|
|
free(data->searchstr);
|
|
|
|
data->searchstr = xstrdup(argument);
|
|
|
|
if (!window_copy_search_down(wp, 1)) {
|
|
|
|
window_copy_clear_marks(wp);
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
} else if (prefix == '-') {
|
|
|
|
data->searchtype = WINDOW_COPY_SEARCHUP;
|
|
|
|
free(data->searchstr);
|
|
|
|
data->searchstr = xstrdup(argument);
|
|
|
|
if (!window_copy_search_up(wp, 1)) {
|
|
|
|
window_copy_clear_marks(wp);
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2017-01-05 09:07:15 +00:00
|
|
|
if (strncmp(command, "search-", 7) != 0 && data->searchmark != NULL) {
|
2017-01-06 11:57:03 +00:00
|
|
|
window_copy_clear_marks(wp);
|
|
|
|
redraw = 1;
|
|
|
|
data->searchx = data->searchy = -1;
|
2017-01-05 09:07:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cancel)
|
|
|
|
window_pane_reset_mode(wp);
|
2017-01-06 11:57:03 +00:00
|
|
|
else if (redraw)
|
|
|
|
window_copy_redraw_screen(wp);
|
2016-10-11 07:23:34 +00:00
|
|
|
wp->modeprefix = 1;
|
2010-03-02 00:32:41 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-08-18 07:08:26 +00:00
|
|
|
window_copy_scroll_to(struct window_pane *wp, u_int px, u_int py)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct grid *gd = data->backing->grid;
|
2009-08-18 07:08:26 +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-03 22:50:09 +00:00
|
|
|
data->oy = gd->hsize - offset;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2013-11-08 12:39:20 +00:00
|
|
|
window_copy_update_selection(wp, 1);
|
2009-08-18 07:08:26 +00:00
|
|
|
window_copy_redraw_screen(wp);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static int
|
2014-11-06 09:17:25 +00:00
|
|
|
window_copy_search_compare(struct grid *gd, u_int px, u_int py,
|
|
|
|
struct grid *sgd, u_int spx, int cis)
|
2009-08-18 07:08:26 +00:00
|
|
|
{
|
2015-11-13 08:09:28 +00:00
|
|
|
struct grid_cell gc, sgc;
|
|
|
|
const struct utf8_data *ud, *sud;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2015-11-13 08:09:28 +00:00
|
|
|
grid_get_cell(gd, px, py, &gc);
|
|
|
|
ud = &gc.data;
|
|
|
|
grid_get_cell(sgd, spx, 0, &sgc);
|
|
|
|
sud = &sgc.data;
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2015-11-13 08:09:28 +00:00
|
|
|
if (ud->size != sud->size || ud->width != sud->width)
|
2009-08-18 07:08:26 +00:00
|
|
|
return (0);
|
2013-11-09 00:48:57 +00:00
|
|
|
|
2015-11-13 08:09:28 +00:00
|
|
|
if (cis && ud->size == 1)
|
|
|
|
return (tolower(ud->data[0]) == sud->data[0]);
|
2013-11-09 00:48:57 +00:00
|
|
|
|
2015-11-13 08:09:28 +00:00
|
|
|
return (memcmp(ud->data, sud->data, ud->size) == 0);
|
2009-08-18 07:08:26 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static int
|
2009-08-18 07:08:26 +00:00
|
|
|
window_copy_search_lr(struct grid *gd,
|
2013-11-09 00:48:57 +00:00
|
|
|
struct grid *sgd, u_int *ppx, u_int py, u_int first, u_int last, int cis)
|
2009-08-18 07:08:26 +00:00
|
|
|
{
|
|
|
|
u_int ax, bx, px;
|
2013-11-09 00:48:57 +00:00
|
|
|
int matched;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
|
|
|
for (ax = first; ax < last; ax++) {
|
|
|
|
if (ax + sgd->sx >= gd->sx)
|
|
|
|
break;
|
|
|
|
for (bx = 0; bx < sgd->sx; bx++) {
|
|
|
|
px = ax + bx;
|
2013-11-09 00:48:57 +00:00
|
|
|
matched = window_copy_search_compare(gd, px, py, sgd,
|
|
|
|
bx, cis);
|
|
|
|
if (!matched)
|
2009-08-18 07:08:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bx == sgd->sx) {
|
|
|
|
*ppx = ax;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static int
|
2009-08-18 07:08:26 +00:00
|
|
|
window_copy_search_rl(struct grid *gd,
|
2013-11-09 00:48:57 +00:00
|
|
|
struct grid *sgd, u_int *ppx, u_int py, u_int first, u_int last, int cis)
|
2009-08-18 07:08:26 +00:00
|
|
|
{
|
|
|
|
u_int ax, bx, px;
|
2013-11-09 00:48:57 +00:00
|
|
|
int matched;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
|
|
|
for (ax = last + 1; ax > first; ax--) {
|
2009-08-19 14:46:56 +00:00
|
|
|
if (gd->sx - (ax - 1) < sgd->sx)
|
|
|
|
continue;
|
2009-08-18 07:08:26 +00:00
|
|
|
for (bx = 0; bx < sgd->sx; bx++) {
|
|
|
|
px = ax - 1 + bx;
|
2013-11-09 00:48:57 +00:00
|
|
|
matched = window_copy_search_compare(gd, px, py, sgd,
|
|
|
|
bx, cis);
|
|
|
|
if (!matched)
|
2009-08-18 07:08:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bx == sgd->sx) {
|
|
|
|
*ppx = ax - 1;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2016-05-03 13:40:50 +00:00
|
|
|
window_copy_move_left(struct screen *s, u_int *fx, u_int *fy)
|
2009-08-18 07:08:26 +00:00
|
|
|
{
|
2016-05-03 13:40:50 +00:00
|
|
|
if (*fx == 0) { /* left */
|
|
|
|
if (*fy == 0) /* top */
|
|
|
|
return;
|
|
|
|
*fx = screen_size_x(s) - 1;
|
|
|
|
*fy = *fy - 1;
|
|
|
|
} else
|
|
|
|
*fx = *fx - 1;
|
|
|
|
}
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2016-05-03 13:40:50 +00:00
|
|
|
window_copy_move_right(struct screen *s, u_int *fx, u_int *fy)
|
|
|
|
{
|
|
|
|
if (*fx == screen_size_x(s) - 1) { /* right */
|
|
|
|
if (*fy == screen_hsize(s) + screen_size_y(s)) /* bottom */
|
2009-08-18 07:08:26 +00:00
|
|
|
return;
|
2016-05-03 13:40:50 +00:00
|
|
|
*fx = 0;
|
|
|
|
*fy = *fy + 1;
|
2009-08-18 07:08:26 +00:00
|
|
|
} else
|
2016-05-03 13:40:50 +00:00
|
|
|
*fx = *fx + 1;
|
|
|
|
}
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static int
|
2016-05-03 13:40:50 +00:00
|
|
|
window_copy_is_lowercase(const char *ptr)
|
|
|
|
{
|
|
|
|
while (*ptr != '\0') {
|
|
|
|
if (*ptr != tolower((u_char)*ptr))
|
|
|
|
return (0);
|
|
|
|
++ptr;
|
2013-11-09 00:48:57 +00:00
|
|
|
}
|
2016-05-03 13:40:50 +00:00
|
|
|
return (1);
|
|
|
|
}
|
2013-11-09 00:48:57 +00:00
|
|
|
|
2016-05-03 13:40:50 +00:00
|
|
|
/*
|
|
|
|
* Search for text stored in sgd starting from position fx,fy up to endline. If
|
|
|
|
* found, jump to it. If cis then ignore case. The direction is 0 for searching
|
|
|
|
* up, down otherwise. If wrap then go to begin/end of grid and try again if
|
|
|
|
* not found.
|
|
|
|
*/
|
2017-01-06 11:57:03 +00:00
|
|
|
static int
|
2016-05-03 13:40:50 +00:00
|
|
|
window_copy_search_jump(struct window_pane *wp, struct grid *gd,
|
|
|
|
struct grid *sgd, u_int fx, u_int fy, u_int endline, int cis, int wrap,
|
|
|
|
int direction)
|
|
|
|
{
|
|
|
|
u_int i, px;
|
|
|
|
int found;
|
|
|
|
|
|
|
|
found = 0;
|
|
|
|
if (direction) {
|
|
|
|
for (i = fy; i <= endline; i++) {
|
|
|
|
found = window_copy_search_lr(gd, sgd, &px, i, fx,
|
|
|
|
gd->sx, cis);
|
|
|
|
if (found)
|
|
|
|
break;
|
|
|
|
fx = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = fy + 1; endline < i; i--) {
|
|
|
|
found = window_copy_search_rl(gd, sgd, &px, i - 1, 0,
|
|
|
|
fx, cis);
|
|
|
|
if (found) {
|
|
|
|
i--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fx = gd->sx;
|
2009-08-18 07:08:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-06 11:57:03 +00:00
|
|
|
if (found) {
|
2016-05-03 13:40:50 +00:00
|
|
|
window_copy_scroll_to(wp, px, i);
|
2017-01-06 11:57:03 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (wrap) {
|
|
|
|
return (window_copy_search_jump(wp, gd, sgd,
|
|
|
|
direction ? 0 : gd->sx - 1,
|
2016-05-03 13:40:50 +00:00
|
|
|
direction ? 0 : gd->hsize + gd->sy - 1, fy, cis, 0,
|
2017-01-06 11:57:03 +00:00
|
|
|
direction));
|
2016-05-03 13:40:50 +00:00
|
|
|
}
|
2017-01-06 11:57:03 +00:00
|
|
|
return (0);
|
2009-08-18 07:08:26 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 13:40:50 +00:00
|
|
|
/*
|
|
|
|
* Search in for text searchstr. If direction is 0 then search up, otherwise
|
|
|
|
* down. If moveflag is 0 then look for string at the current cursor position
|
|
|
|
* as well.
|
|
|
|
*/
|
2017-01-06 11:57:03 +00:00
|
|
|
static int
|
2017-01-05 09:07:15 +00:00
|
|
|
window_copy_search(struct window_pane *wp, int direction, int moveflag)
|
2009-08-18 07:08:26 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct screen *s = data->backing, ss;
|
2009-08-18 07:08:26 +00:00
|
|
|
struct screen_write_ctx ctx;
|
2016-05-03 13:40:50 +00:00
|
|
|
struct grid *gd = s->grid;
|
|
|
|
u_int fx, fy, endline;
|
2017-01-06 11:57:03 +00:00
|
|
|
int wrapflag, cis, found;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2017-05-12 10:45:38 +00:00
|
|
|
free(wp->searchstr);
|
|
|
|
wp->searchstr = xstrdup(data->searchstr);
|
|
|
|
|
2009-08-18 07:08:26 +00:00
|
|
|
fx = data->cx;
|
2016-05-03 13:40:50 +00:00
|
|
|
fy = screen_hsize(data->backing) - data->oy + data->cy;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2017-01-05 09:07:15 +00:00
|
|
|
screen_init(&ss, screen_write_strlen("%s", data->searchstr), 1, 0);
|
2016-05-03 13:40:50 +00:00
|
|
|
screen_write_start(&ctx, NULL, &ss);
|
2017-01-05 09:07:15 +00:00
|
|
|
screen_write_nputs(&ctx, -1, &grid_default_cell, "%s", data->searchstr);
|
2016-05-03 13:40:50 +00:00
|
|
|
screen_write_stop(&ctx);
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2016-05-03 13:40:50 +00:00
|
|
|
if (moveflag) {
|
|
|
|
if (direction)
|
|
|
|
window_copy_move_right(s, &fx, &fy);
|
|
|
|
else
|
|
|
|
window_copy_move_left(s, &fx, &fy);
|
2013-11-09 00:48:57 +00:00
|
|
|
}
|
2016-05-03 13:40:50 +00:00
|
|
|
window_copy_clear_selection(wp);
|
2013-11-09 00:48:57 +00:00
|
|
|
|
2016-05-03 13:40:50 +00:00
|
|
|
wrapflag = options_get_number(wp->window->options, "wrap-search");
|
2017-01-05 09:07:15 +00:00
|
|
|
cis = window_copy_is_lowercase(data->searchstr);
|
2016-05-03 13:40:50 +00:00
|
|
|
|
|
|
|
if (direction)
|
|
|
|
endline = gd->hsize + gd->sy - 1;
|
|
|
|
else
|
|
|
|
endline = 0;
|
2017-01-06 11:57:03 +00:00
|
|
|
found = window_copy_search_jump(wp, gd, ss.grid, fx, fy, endline, cis,
|
2017-01-05 09:07:15 +00:00
|
|
|
wrapflag, direction);
|
|
|
|
|
|
|
|
if (window_copy_search_marks(wp, &ss))
|
|
|
|
window_copy_redraw_screen(wp);
|
2009-08-18 07:08:26 +00:00
|
|
|
|
|
|
|
screen_free(&ss);
|
2017-01-06 11:57:03 +00:00
|
|
|
return (found);
|
2009-08-18 07:08:26 +00:00
|
|
|
}
|
|
|
|
|
2017-01-05 09:07:15 +00:00
|
|
|
static int
|
|
|
|
window_copy_search_marks(struct window_pane *wp, struct screen *ssp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = data->backing, ss;
|
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
struct grid *gd = s->grid;
|
2017-03-24 07:14:27 +00:00
|
|
|
int found, cis, which = -1;
|
2017-01-05 09:07:15 +00:00
|
|
|
u_int px, py, b, nfound = 0, width;
|
|
|
|
|
|
|
|
if (ssp == NULL) {
|
|
|
|
width = screen_write_strlen("%s", data->searchstr);
|
|
|
|
screen_init(&ss, width, 1, 0);
|
|
|
|
screen_write_start(&ctx, NULL, &ss);
|
|
|
|
screen_write_nputs(&ctx, -1, &grid_default_cell, "%s",
|
|
|
|
data->searchstr);
|
|
|
|
screen_write_stop(&ctx);
|
|
|
|
ssp = &ss;
|
|
|
|
} else
|
|
|
|
width = screen_size_x(ssp);
|
|
|
|
|
|
|
|
cis = window_copy_is_lowercase(data->searchstr);
|
|
|
|
|
|
|
|
free(data->searchmark);
|
|
|
|
data->searchmark = bit_alloc((gd->hsize + gd->sy) * gd->sx);
|
|
|
|
|
|
|
|
for (py = 0; py < gd->hsize + gd->sy; py++) {
|
|
|
|
px = 0;
|
|
|
|
for (;;) {
|
|
|
|
found = window_copy_search_lr(gd, ssp->grid, &px, py,
|
|
|
|
px, gd->sx, cis);
|
|
|
|
if (!found)
|
|
|
|
break;
|
2017-03-24 07:14:27 +00:00
|
|
|
|
2017-01-05 09:07:15 +00:00
|
|
|
nfound++;
|
2017-03-24 07:14:27 +00:00
|
|
|
if (px == data->cx && py == gd->hsize + data->cy - data->oy)
|
|
|
|
which = nfound;
|
2017-01-05 09:07:15 +00:00
|
|
|
|
|
|
|
b = (py * gd->sx) + px;
|
|
|
|
bit_nset(data->searchmark, b, b + width - 1);
|
|
|
|
|
|
|
|
px++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-24 07:14:27 +00:00
|
|
|
if (which != -1)
|
|
|
|
data->searchthis = 1 + nfound - which;
|
|
|
|
else
|
|
|
|
data->searchthis = -1;
|
|
|
|
data->searchcount = nfound;
|
|
|
|
|
2017-01-05 09:07:15 +00:00
|
|
|
if (ssp == &ss)
|
|
|
|
screen_free(&ss);
|
|
|
|
return (nfound);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2017-01-06 11:57:03 +00:00
|
|
|
window_copy_clear_marks(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
|
|
|
|
free(data->searchmark);
|
|
|
|
data->searchmark = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-01-05 09:07:15 +00:00
|
|
|
window_copy_search_up(struct window_pane *wp, int moveflag)
|
2016-05-03 13:40:50 +00:00
|
|
|
{
|
2017-01-06 11:57:03 +00:00
|
|
|
return (window_copy_search(wp, 0, moveflag));
|
2016-05-03 13:40:50 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 11:57:03 +00:00
|
|
|
static int
|
2017-01-05 09:07:15 +00:00
|
|
|
window_copy_search_down(struct window_pane *wp, int moveflag)
|
2016-05-03 13:40:50 +00:00
|
|
|
{
|
2017-01-06 11:57:03 +00:00
|
|
|
return (window_copy_search(wp, 1, moveflag));
|
2016-05-03 13:40:50 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-08-18 07:08:26 +00:00
|
|
|
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-06 21:35:44 +00:00
|
|
|
lineno = strtonum(linestr, 0, screen_hsize(data->backing), &errstr);
|
2009-08-18 07:08:26 +00:00
|
|
|
if (errstr != NULL)
|
|
|
|
return;
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-08-18 07:08:26 +00:00
|
|
|
data->oy = lineno;
|
2013-11-08 12:39:20 +00:00
|
|
|
window_copy_update_selection(wp, 1);
|
2009-08-18 07:08:26 +00:00
|
|
|
window_copy_redraw_screen(wp);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2014-11-06 09:17:25 +00:00
|
|
|
window_copy_write_line(struct window_pane *wp, struct screen_write_ctx *ctx,
|
|
|
|
u_int py)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
2015-10-27 15:58:42 +00:00
|
|
|
struct options *oo = wp->window->options;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct grid_cell gc;
|
2014-01-22 22:32:15 +00:00
|
|
|
char hdr[512];
|
2017-01-05 09:07:15 +00:00
|
|
|
size_t size = 0;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2014-01-28 23:07:09 +00:00
|
|
|
style_apply(&gc, oo, "mode-style");
|
2017-01-07 15:28:13 +00:00
|
|
|
gc.flags |= GRID_FLAG_NOPALETTE;
|
2009-08-18 07:08:26 +00:00
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
if (py == 0) {
|
2017-03-24 07:14:27 +00:00
|
|
|
if (data->searchmark == NULL) {
|
|
|
|
size = xsnprintf(hdr, sizeof hdr,
|
|
|
|
"[%u/%u]", data->oy, screen_hsize(data->backing));
|
|
|
|
} else {
|
|
|
|
if (data->searchthis == -1) {
|
|
|
|
size = xsnprintf(hdr, sizeof hdr,
|
|
|
|
"(%u results) [%d/%u]", data->searchcount,
|
|
|
|
data->oy, screen_hsize(data->backing));
|
|
|
|
} else {
|
|
|
|
size = xsnprintf(hdr, sizeof hdr,
|
|
|
|
"(%u/%u results) [%d/%u]", data->searchthis,
|
|
|
|
data->searchcount, data->oy,
|
|
|
|
screen_hsize(data->backing));
|
|
|
|
}
|
|
|
|
}
|
2010-09-08 20:36:42 +00:00
|
|
|
if (size > screen_size_x(s))
|
|
|
|
size = screen_size_x(s);
|
2009-06-01 22:58:49 +00:00
|
|
|
screen_write_cursormove(ctx, screen_size_x(s) - size, 0);
|
|
|
|
screen_write_puts(ctx, &gc, "%s", hdr);
|
|
|
|
} else
|
|
|
|
size = 0;
|
|
|
|
|
2014-04-11 19:35:54 +00:00
|
|
|
if (size < screen_size_x(s)) {
|
2017-01-05 09:07:15 +00:00
|
|
|
screen_write_cursormove(ctx, 0, py);
|
|
|
|
screen_write_copy(ctx, data->backing, 0,
|
2014-04-11 19:35:54 +00:00
|
|
|
(screen_hsize(data->backing) - data->oy) + py,
|
2017-01-05 09:07:15 +00:00
|
|
|
screen_size_x(s) - size, 1, data->searchmark, &gc);
|
2014-04-11 19:35:54 +00:00
|
|
|
}
|
2009-08-13 19:35:20 +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, '$');
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2014-11-06 09:17:25 +00:00
|
|
|
window_copy_write_lines(struct window_pane *wp, struct screen_write_ctx *ctx,
|
|
|
|
u_int py, u_int ny)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
u_int yy;
|
|
|
|
|
|
|
|
for (yy = py; yy < py + ny; yy++)
|
|
|
|
window_copy_write_line(wp, ctx, py);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2014-12-15 10:02:55 +00:00
|
|
|
window_copy_redraw_selection(struct window_pane *wp, u_int old_y)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
u_int new_y, start, end;
|
|
|
|
|
|
|
|
new_y = data->cy;
|
|
|
|
if (old_y <= new_y) {
|
|
|
|
start = old_y;
|
|
|
|
end = new_y;
|
|
|
|
} else {
|
|
|
|
start = new_y;
|
|
|
|
end = old_y;
|
|
|
|
}
|
|
|
|
window_copy_redraw_lines(wp, start, end - start + 1);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_redraw_lines(struct window_pane *wp, u_int py, u_int ny)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
screen_write_start(&ctx, wp, NULL);
|
|
|
|
for (i = py; i < py + ny; i++)
|
|
|
|
window_copy_write_line(wp, &ctx, i);
|
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_redraw_screen(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
|
|
|
|
window_copy_redraw_lines(wp, 0, screen_size_y(&data->screen));
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
static void
|
|
|
|
window_copy_synchronize_cursor(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
u_int xx, yy;
|
|
|
|
|
|
|
|
xx = data->cx;
|
|
|
|
yy = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
|
|
|
|
switch (data->cursordrag) {
|
|
|
|
case CURSORDRAG_ENDSEL:
|
|
|
|
data->endselx = xx;
|
|
|
|
data->endsely = yy;
|
|
|
|
break;
|
|
|
|
case CURSORDRAG_SEL:
|
|
|
|
data->selx = xx;
|
|
|
|
data->sely = yy;
|
|
|
|
break;
|
|
|
|
case CURSORDRAG_NONE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-08-13 19:35:20 +00:00
|
|
|
window_copy_update_cursor(struct window_pane *wp, u_int cx, u_int cy)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2009-08-13 19:35:20 +00:00
|
|
|
struct screen *s = &data->screen;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct screen_write_ctx ctx;
|
2009-08-13 19:35:20 +00:00
|
|
|
u_int old_cx, old_cy;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-08-13 19:35:20 +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);
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_start_selection(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
|
2009-08-13 19:35:20 +00:00
|
|
|
data->selx = data->cx;
|
2010-04-06 21:35:44 +00:00
|
|
|
data->sely = screen_hsize(data->backing) + data->cy - data->oy;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
data->endselx = data->selx;
|
|
|
|
data->endsely = data->sely;
|
|
|
|
|
|
|
|
data->cursordrag = CURSORDRAG_ENDSEL;
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
s->sel.flag = 1;
|
2013-11-08 12:39:20 +00:00
|
|
|
window_copy_update_selection(wp, 1);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
static int
|
|
|
|
window_copy_adjust_selection(struct window_pane *wp, u_int *selx, u_int *sely)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
u_int sx, sy, ty;
|
|
|
|
int relpos;
|
|
|
|
|
|
|
|
sx = *selx;
|
|
|
|
sy = *sely;
|
|
|
|
|
|
|
|
ty = screen_hsize(data->backing) - data->oy;
|
|
|
|
if (sy < ty) {
|
|
|
|
relpos = WINDOW_COPY_REL_POS_ABOVE;
|
|
|
|
if (!data->rectflag)
|
|
|
|
sx = 0;
|
|
|
|
sy = 0;
|
|
|
|
} else if (sy > ty + screen_size_y(s) - 1) {
|
|
|
|
relpos = WINDOW_COPY_REL_POS_BELOW;
|
|
|
|
if (!data->rectflag)
|
|
|
|
sx = screen_size_x(s) - 1;
|
|
|
|
sy = screen_size_y(s) - 1;
|
|
|
|
} else {
|
|
|
|
relpos = WINDOW_COPY_REL_POS_ON_SCREEN;
|
|
|
|
sy -= ty;
|
|
|
|
}
|
|
|
|
|
|
|
|
*selx = sx;
|
2017-05-29 07:58:33 +00:00
|
|
|
*sely = sy;
|
2016-11-24 13:38:44 +00:00
|
|
|
return (relpos);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static int
|
2013-11-08 12:39:20 +00:00
|
|
|
window_copy_update_selection(struct window_pane *wp, int may_redraw)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
2015-10-27 15:58:42 +00:00
|
|
|
struct options *oo = wp->window->options;
|
2009-06-01 22:58:49 +00:00
|
|
|
struct grid_cell gc;
|
2016-11-24 13:38:44 +00:00
|
|
|
u_int sx, sy, cy, endsx, endsy;
|
|
|
|
int startrelpos, endrelpos;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2014-11-06 09:17:25 +00:00
|
|
|
if (!s->sel.flag && s->sel.lineflag == LINE_SEL_NONE)
|
2009-06-01 22:58:49 +00:00
|
|
|
return (0);
|
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
window_copy_synchronize_cursor(wp);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
/* Adjust the selection. */
|
|
|
|
sx = data->selx;
|
|
|
|
sy = data->sely;
|
2016-11-24 13:38:44 +00:00
|
|
|
startrelpos = window_copy_adjust_selection(wp, &sx, &sy);
|
|
|
|
|
|
|
|
/* Adjust the end of selection. */
|
|
|
|
endsx = data->endselx;
|
|
|
|
endsy = data->endsely;
|
|
|
|
endrelpos = window_copy_adjust_selection(wp, &endsx, &endsy);
|
|
|
|
|
|
|
|
/* Selection is outside of the current screen */
|
|
|
|
if (startrelpos == endrelpos &&
|
|
|
|
startrelpos != WINDOW_COPY_REL_POS_ON_SCREEN) {
|
|
|
|
screen_hide_selection(s);
|
|
|
|
return (0);
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
/* Set colours and selection. */
|
|
|
|
style_apply(&gc, oo, "mode-style");
|
2017-01-07 15:28:13 +00:00
|
|
|
gc.flags |= GRID_FLAG_NOPALETTE;
|
2016-11-24 13:38:44 +00:00
|
|
|
screen_set_selection(s, sx, sy, endsx, endsy, data->rectflag, &gc);
|
2010-02-06 17:35:01 +00:00
|
|
|
|
2013-11-08 12:39:20 +00:00
|
|
|
if (data->rectflag && may_redraw) {
|
2010-02-06 17:35:01 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void *
|
2013-03-22 15:52:40 +00:00
|
|
|
window_copy_get_selection(struct window_pane *wp, size_t *len)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
char *buf;
|
2010-02-06 17:35:01 +00:00
|
|
|
size_t off;
|
2014-06-19 07:37:59 +00:00
|
|
|
u_int i, xx, yy, sx, sy, ex, ey, ey_last;
|
2010-02-06 17:35:01 +00:00
|
|
|
u_int firstsx, lastex, restex, restsx;
|
2011-04-24 21:06:12 +00:00
|
|
|
int keys;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2014-11-06 09:17:25 +00:00
|
|
|
if (!s->sel.flag && s->sel.lineflag == LINE_SEL_NONE)
|
2013-03-22 15:52:40 +00:00
|
|
|
return (NULL);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
buf = xmalloc(1);
|
|
|
|
off = 0;
|
|
|
|
|
|
|
|
*buf = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The selection extends from selx,sely to (adjusted) cx,cy on
|
|
|
|
* the base screen.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Find start and end. */
|
2016-11-24 13:38:44 +00:00
|
|
|
xx = data->endselx;
|
|
|
|
yy = data->endsely;
|
2009-07-02 16:15:43 +00:00
|
|
|
if (yy < data->sely || (yy == data->sely && xx < data->selx)) {
|
2009-06-01 22:58:49 +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. */
|
2014-06-19 07:37:59 +00:00
|
|
|
ey_last = window_copy_find_length(wp, ey);
|
|
|
|
if (ex > ey_last)
|
|
|
|
ex = ey_last;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2010-02-06 17:35:01 +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-24 21:06:12 +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.
|
|
|
|
*/
|
2015-10-27 15:58:42 +00:00
|
|
|
keys = options_get_number(wp->window->options, "mode-keys");
|
2010-02-06 17:35:01 +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-24 21:06:12 +00:00
|
|
|
if (keys == MODEKEY_EMACS) {
|
|
|
|
lastex = data->cx;
|
|
|
|
restex = data->cx;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastex = data->cx + 1;
|
|
|
|
restex = data->cx + 1;
|
|
|
|
}
|
2010-02-06 17:35:01 +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:56:01 +00:00
|
|
|
firstsx = data->cx;
|
|
|
|
restsx = data->cx;
|
2010-02-06 17:35:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-04-24 21:06:12 +00:00
|
|
|
if (keys == MODEKEY_EMACS)
|
|
|
|
lastex = ex;
|
2011-10-23 23:38:16 +00:00
|
|
|
else
|
2011-04-24 21:06:12 +00:00
|
|
|
lastex = ex + 1;
|
2010-02-06 17:35:01 +00:00
|
|
|
restex = xx;
|
|
|
|
firstsx = sx;
|
|
|
|
restsx = 0;
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
/* Copy the lines. */
|
2014-05-14 06:39:58 +00:00
|
|
|
for (i = sy; i <= ey; i++) {
|
|
|
|
window_copy_copy_line(wp, &buf, &off, i,
|
|
|
|
(i == sy ? firstsx : restsx),
|
|
|
|
(i == ey ? lastex : restex));
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2009-09-07 18:50:45 +00:00
|
|
|
/* Don't bother if no data. */
|
|
|
|
if (off == 0) {
|
2012-07-10 11:53:01 +00:00
|
|
|
free(buf);
|
2013-03-22 15:52:40 +00:00
|
|
|
return (NULL);
|
2009-09-07 18:50:45 +00:00
|
|
|
}
|
2014-06-19 07:37:59 +00:00
|
|
|
if (keys == MODEKEY_EMACS || lastex <= ey_last)
|
|
|
|
off -= 1; /* remove final \n (unless at end in vi mode) */
|
|
|
|
*len = off;
|
2013-03-22 15:52:40 +00:00
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2014-05-13 07:34:35 +00:00
|
|
|
window_copy_copy_buffer(struct window_pane *wp, const char *bufname, void *buf,
|
|
|
|
size_t len)
|
2013-03-22 15:52:40 +00:00
|
|
|
{
|
2013-03-25 11:43:33 +00:00
|
|
|
struct screen_write_ctx ctx;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2017-06-03 17:43:01 +00:00
|
|
|
if (options_get_number(global_options, "set-clipboard") != 0) {
|
2013-03-25 11:43:33 +00:00
|
|
|
screen_write_start(&ctx, wp, NULL);
|
|
|
|
screen_write_setselection(&ctx, buf, len);
|
|
|
|
screen_write_stop(&ctx);
|
2017-06-09 09:21:24 +00:00
|
|
|
notify_pane("pane-set-clipboard", wp);
|
2013-03-25 11:43:33 +00:00
|
|
|
}
|
2011-05-18 20:24:29 +00:00
|
|
|
|
2014-05-13 07:34:35 +00:00
|
|
|
if (paste_set(buf, len, bufname, NULL) != 0)
|
2014-02-17 23:07:03 +00:00
|
|
|
free(buf);
|
2013-03-22 15:52:40 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2017-03-08 13:36:12 +00:00
|
|
|
window_copy_copy_pipe(struct window_pane *wp, struct session *s,
|
2014-05-13 07:34:35 +00:00
|
|
|
const char *bufname, const char *arg)
|
2013-03-22 15:52:40 +00:00
|
|
|
{
|
2017-03-08 13:36:12 +00:00
|
|
|
void *buf;
|
|
|
|
size_t len;
|
|
|
|
struct job *job;
|
|
|
|
char *expanded;
|
2013-03-22 15:52:40 +00:00
|
|
|
|
|
|
|
buf = window_copy_get_selection(wp, &len);
|
|
|
|
if (buf == NULL)
|
|
|
|
return;
|
2017-03-08 13:36:12 +00:00
|
|
|
expanded = format_single(NULL, arg, NULL, s, NULL, wp);
|
2013-03-22 15:52:40 +00:00
|
|
|
|
2017-04-20 09:20:22 +00:00
|
|
|
job = job_run(expanded, s, NULL, NULL, NULL, NULL, NULL);
|
2013-03-25 11:43:33 +00:00
|
|
|
bufferevent_write(job->event, buf, len);
|
2013-03-22 15:52:40 +00:00
|
|
|
|
2014-11-09 15:13:01 +00:00
|
|
|
free(expanded);
|
2014-05-13 07:34:35 +00:00
|
|
|
window_copy_copy_buffer(wp, bufname, buf, len);
|
2013-03-22 15:52:40 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2014-05-13 07:34:35 +00:00
|
|
|
window_copy_copy_selection(struct window_pane *wp, const char *bufname)
|
2013-03-22 15:52:40 +00:00
|
|
|
{
|
2014-09-01 21:50:18 +00:00
|
|
|
void *buf;
|
|
|
|
size_t len;
|
2013-03-22 15:52:40 +00:00
|
|
|
|
|
|
|
buf = window_copy_get_selection(wp, &len);
|
|
|
|
if (buf == NULL)
|
|
|
|
return;
|
|
|
|
|
2014-05-13 07:34:35 +00:00
|
|
|
window_copy_copy_buffer(wp, bufname, buf, len);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2014-05-13 07:34:35 +00:00
|
|
|
window_copy_append_selection(struct window_pane *wp, const char *bufname)
|
2014-03-31 21:39:31 +00:00
|
|
|
{
|
2014-05-13 07:34:35 +00:00
|
|
|
char *buf;
|
|
|
|
struct paste_buffer *pb;
|
2015-08-29 09:25:00 +00:00
|
|
|
const char *bufdata;
|
|
|
|
size_t len, bufsize;
|
2014-05-13 07:34:35 +00:00
|
|
|
struct screen_write_ctx ctx;
|
2014-03-31 21:39:31 +00:00
|
|
|
|
|
|
|
buf = window_copy_get_selection(wp, &len);
|
|
|
|
if (buf == NULL)
|
|
|
|
return;
|
|
|
|
|
2017-06-03 17:43:01 +00:00
|
|
|
if (options_get_number(global_options, "set-clipboard") != 0) {
|
2014-03-31 21:39:31 +00:00
|
|
|
screen_write_start(&ctx, wp, NULL);
|
|
|
|
screen_write_setselection(&ctx, buf, len);
|
|
|
|
screen_write_stop(&ctx);
|
2017-06-09 09:21:24 +00:00
|
|
|
notify_pane("pane-set-clipboard", wp);
|
2014-03-31 21:39:31 +00:00
|
|
|
}
|
|
|
|
|
2015-08-29 09:25:00 +00:00
|
|
|
if (bufname == NULL || *bufname == '\0')
|
|
|
|
pb = paste_get_top(&bufname);
|
|
|
|
else
|
2014-05-13 07:34:35 +00:00
|
|
|
pb = paste_get_name(bufname);
|
2014-03-31 21:39:31 +00:00
|
|
|
if (pb != NULL) {
|
2015-08-29 09:25:00 +00:00
|
|
|
bufdata = paste_buffer_data(pb, &bufsize);
|
|
|
|
buf = xrealloc(buf, len + bufsize);
|
|
|
|
memmove(buf + bufsize, buf, len);
|
|
|
|
memcpy(buf, bufdata, bufsize);
|
|
|
|
len += bufsize;
|
2014-03-31 21:39:31 +00:00
|
|
|
}
|
2014-05-13 07:34:35 +00:00
|
|
|
if (paste_set(buf, len, bufname, NULL) != 0)
|
2014-03-31 21:39:31 +00:00
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2015-11-13 08:09:28 +00:00
|
|
|
window_copy_copy_line(struct window_pane *wp, char **buf, size_t *off, u_int sy,
|
|
|
|
u_int sx, u_int ex)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2010-04-06 21:35:44 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct grid *gd = data->backing->grid;
|
2015-11-13 08:09:28 +00:00
|
|
|
struct grid_cell gc;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct grid_line *gl;
|
2013-01-18 02:16:21 +00:00
|
|
|
struct utf8_data ud;
|
2010-04-06 21:35:44 +00:00
|
|
|
u_int i, xx, wrapped = 0;
|
2014-10-02 08:36:26 +00:00
|
|
|
const char *s;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
if (sx > ex)
|
|
|
|
return;
|
|
|
|
|
2009-08-08 15:57:49 +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-03 22:50:09 +00:00
|
|
|
if (gl->flags & GRID_LINE_WRAPPED && gl->cellsize <= gd->sx)
|
2009-08-08 15:57:49 +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);
|
2009-06-01 22:58:49 +00:00
|
|
|
if (ex > xx)
|
|
|
|
ex = xx;
|
|
|
|
if (sx > xx)
|
|
|
|
sx = xx;
|
|
|
|
|
|
|
|
if (sx < ex) {
|
|
|
|
for (i = sx; i < ex; i++) {
|
2015-11-13 08:09:28 +00:00
|
|
|
grid_get_cell(gd, i, sy, &gc);
|
|
|
|
if (gc.flags & GRID_FLAG_PADDING)
|
2009-06-01 22:58:49 +00:00
|
|
|
continue;
|
2015-11-13 08:09:28 +00:00
|
|
|
utf8_copy(&ud, &gc.data);
|
|
|
|
if (ud.size == 1 && (gc.attr & GRID_ATTR_CHARSET)) {
|
2014-10-02 08:36:26 +00:00
|
|
|
s = tty_acs_get(NULL, ud.data[0]);
|
|
|
|
if (s != NULL && strlen(s) <= sizeof ud.data) {
|
|
|
|
ud.size = strlen(s);
|
2014-10-22 23:18:53 +00:00
|
|
|
memcpy(ud.data, s, ud.size);
|
2014-10-02 08:36:26 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-18 02:16:21 +00:00
|
|
|
|
2014-10-08 17:35:58 +00:00
|
|
|
*buf = xrealloc(*buf, (*off) + ud.size);
|
2013-01-18 02:16:21 +00:00
|
|
|
memcpy(*buf + *off, ud.data, ud.size);
|
|
|
|
*off += ud.size;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-08 15:57:49 +00:00
|
|
|
/* Only add a newline if the line wasn't wrapped. */
|
2010-02-17 20:58:24 +00:00
|
|
|
if (!wrapped || ex != xx) {
|
2014-10-08 17:35:58 +00:00
|
|
|
*buf = xrealloc(*buf, (*off) + 1);
|
2009-08-08 15:57:49 +00:00
|
|
|
(*buf)[(*off)++] = '\n';
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2010-02-22 20:28:21 +00:00
|
|
|
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);
|
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
data->cursordrag = CURSORDRAG_NONE;
|
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2010-02-22 20:28:21 +00:00
|
|
|
px = window_copy_find_length(wp, py);
|
|
|
|
if (data->cx > px)
|
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static int
|
2010-02-04 20:00:26 +00:00
|
|
|
window_copy_in_set(struct window_pane *wp, u_int px, u_int py, const char *set)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2010-04-06 21:35:44 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2015-11-13 08:09:28 +00:00
|
|
|
struct grid_cell gc;
|
|
|
|
const struct utf8_data *ud;
|
|
|
|
|
|
|
|
grid_get_cell(data->backing->grid, px, py, &gc);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2015-11-13 08:09:28 +00:00
|
|
|
ud = &gc.data;
|
|
|
|
if (ud->size != 1 || (gc.flags & GRID_FLAG_PADDING))
|
2009-06-01 22:58:49 +00:00
|
|
|
return (0);
|
2015-11-13 08:09:28 +00:00
|
|
|
if (*ud->data == 0x00 || *ud->data == 0x7f)
|
2009-06-01 22:58:49 +00:00
|
|
|
return (0);
|
2015-11-13 08:09:28 +00:00
|
|
|
return (strchr(set, *ud->data) != NULL);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static u_int
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_find_length(struct window_pane *wp, u_int py)
|
|
|
|
{
|
2010-04-06 21:35:44 +00:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = data->backing;
|
2015-11-13 08:09:28 +00:00
|
|
|
struct grid_cell gc;
|
2010-04-06 21:35:44 +00:00
|
|
|
u_int px;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-11 19:09:24 +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-06 21:35:44 +00:00
|
|
|
px = s->grid->linedata[py].cellsize;
|
|
|
|
if (px > screen_size_x(s))
|
|
|
|
px = screen_size_x(s);
|
2009-06-01 22:58:49 +00:00
|
|
|
while (px > 0) {
|
2015-11-13 08:09:28 +00:00
|
|
|
grid_get_cell(s->grid, px - 1, py, &gc);
|
|
|
|
if (gc.data.size != 1 || *gc.data.data != ' ')
|
2009-06-01 22:58:49 +00:00
|
|
|
break;
|
|
|
|
px--;
|
|
|
|
}
|
|
|
|
return (px);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-07-12 16:12:34 +00:00
|
|
|
window_copy_cursor_start_of_line(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-06-05 15:49:48 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2014-11-06 09:17:25 +00:00
|
|
|
struct screen *s = &data->screen;
|
2010-06-05 15:49:48 +00:00
|
|
|
struct grid *gd = back_s->grid;
|
|
|
|
u_int py;
|
2009-07-12 16:12:34 +00:00
|
|
|
|
2014-11-06 09:17:25 +00:00
|
|
|
if (data->cx == 0 && s->sel.lineflag == LINE_SEL_NONE) {
|
2010-06-05 15:49:48 +00:00
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
2014-11-06 09:17:25 +00:00
|
|
|
while (py > 0 &&
|
|
|
|
gd->linedata[py-1].flags & GRID_LINE_WRAPPED) {
|
2010-06-05 15:49:48 +00:00
|
|
|
window_copy_cursor_up(wp, 0);
|
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
|
|
|
}
|
|
|
|
}
|
2009-08-13 19:35:20 +00:00
|
|
|
window_copy_update_cursor(wp, 0, data->cy);
|
2013-11-08 12:39:20 +00:00
|
|
|
if (window_copy_update_selection(wp, 1))
|
2009-07-12 16:12:34 +00:00
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-07-12 16:15:34 +00:00
|
|
|
window_copy_cursor_back_to_indentation(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
u_int px, py, xx;
|
2015-11-13 08:09:28 +00:00
|
|
|
struct grid_cell gc;
|
2009-07-12 16:15:34 +00:00
|
|
|
|
|
|
|
px = 0;
|
2010-04-06 21:35:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2009-07-12 16:15:34 +00:00
|
|
|
xx = window_copy_find_length(wp, py);
|
|
|
|
|
|
|
|
while (px < xx) {
|
2015-11-13 08:09:28 +00:00
|
|
|
grid_get_cell(data->backing->grid, px, py, &gc);
|
|
|
|
if (gc.data.size != 1 || *gc.data.data != ' ')
|
2009-07-12 16:15:34 +00:00
|
|
|
break;
|
|
|
|
px++;
|
|
|
|
}
|
|
|
|
|
2009-08-13 19:35:20 +00:00
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
2013-11-08 12:39:20 +00:00
|
|
|
if (window_copy_update_selection(wp, 1))
|
2009-08-13 19:35:20 +00:00
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
2009-07-12 16:15:34 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-07-12 16:12:34 +00:00
|
|
|
window_copy_cursor_end_of_line(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2014-11-06 09:17:25 +00:00
|
|
|
struct screen *s = &data->screen;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct grid *gd = back_s->grid;
|
2009-07-12 16:12:34 +00:00
|
|
|
u_int px, py;
|
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
2009-07-12 16:12:34 +00:00
|
|
|
px = window_copy_find_length(wp, py);
|
|
|
|
|
2014-11-06 09:17:25 +00:00
|
|
|
if (data->cx == px && s->sel.lineflag == LINE_SEL_NONE) {
|
2010-03-01 23:53:27 +00:00
|
|
|
if (data->screen.sel.flag && data->rectflag)
|
2010-04-06 21:35:44 +00:00
|
|
|
px = screen_size_x(back_s);
|
2010-03-01 23:53:27 +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-06 21:35:44 +00:00
|
|
|
py = screen_hsize(back_s)
|
|
|
|
+ data->cy - data->oy;
|
2010-03-01 23:53:27 +00:00
|
|
|
}
|
|
|
|
px = window_copy_find_length(wp, py);
|
|
|
|
}
|
|
|
|
}
|
2009-08-13 19:35:20 +00:00
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
2010-03-01 23:53:27 +00:00
|
|
|
|
2013-11-08 12:39:20 +00:00
|
|
|
if (window_copy_update_selection(wp, 1))
|
2009-08-13 19:35:20 +00:00
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
2009-07-12 16:12:34 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2013-10-23 11:31:03 +00:00
|
|
|
window_copy_other_end(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
2016-11-24 13:38:44 +00:00
|
|
|
u_int selx, sely, cy, yy, hsize;
|
2013-10-23 11:31:03 +00:00
|
|
|
|
2014-11-06 09:17:25 +00:00
|
|
|
if (!s->sel.flag && s->sel.lineflag == LINE_SEL_NONE)
|
2013-10-23 11:31:03 +00:00
|
|
|
return;
|
|
|
|
|
2014-11-06 09:17:25 +00:00
|
|
|
if (s->sel.lineflag == LINE_SEL_LEFT_RIGHT)
|
|
|
|
s->sel.lineflag = LINE_SEL_RIGHT_LEFT;
|
|
|
|
else if (s->sel.lineflag == LINE_SEL_RIGHT_LEFT)
|
|
|
|
s->sel.lineflag = LINE_SEL_LEFT_RIGHT;
|
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
switch (data->cursordrag) {
|
|
|
|
case CURSORDRAG_NONE:
|
|
|
|
case CURSORDRAG_SEL:
|
|
|
|
data->cursordrag = CURSORDRAG_ENDSEL;
|
|
|
|
break;
|
|
|
|
case CURSORDRAG_ENDSEL:
|
|
|
|
data->cursordrag = CURSORDRAG_SEL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
selx = data->endselx;
|
|
|
|
sely = data->endsely;
|
|
|
|
if (data->cursordrag == CURSORDRAG_SEL) {
|
|
|
|
selx = data->selx;
|
|
|
|
sely = data->sely;
|
|
|
|
}
|
|
|
|
|
2013-10-23 11:31:03 +00:00
|
|
|
cy = data->cy;
|
|
|
|
yy = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
|
|
|
|
data->cx = selx;
|
|
|
|
|
2015-01-15 13:35:13 +00:00
|
|
|
hsize = screen_hsize(data->backing);
|
2016-11-24 13:38:44 +00:00
|
|
|
if (sely < hsize - data->oy) { /* above */
|
2015-01-15 13:35:13 +00:00
|
|
|
data->oy = hsize - sely;
|
2013-10-23 11:31:03 +00:00
|
|
|
data->cy = 0;
|
2016-11-24 13:38:44 +00:00
|
|
|
} else if (sely > hsize - data->oy + screen_size_y(s)) { /* below */
|
2015-01-15 13:35:13 +00:00
|
|
|
data->oy = hsize - sely + screen_size_y(s) - 1;
|
2013-10-23 11:31:03 +00:00
|
|
|
data->cy = screen_size_y(s) - 1;
|
|
|
|
} else
|
|
|
|
data->cy = cy + sely - yy;
|
|
|
|
|
2016-11-24 13:38:44 +00:00
|
|
|
window_copy_update_selection(wp, 1);
|
2013-10-23 11:31:03 +00:00
|
|
|
window_copy_redraw_screen(wp);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_cursor_left(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2017-03-08 20:05:25 +00:00
|
|
|
u_int py, cx;
|
|
|
|
struct grid_cell gc;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-02-05 10:20:06 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2017-03-08 20:05:25 +00:00
|
|
|
cx = data->cx;
|
|
|
|
while (cx > 0) {
|
|
|
|
grid_get_cell(data->backing->grid, cx, py, &gc);
|
|
|
|
if (~gc.flags & GRID_FLAG_PADDING)
|
|
|
|
break;
|
|
|
|
cx--;
|
|
|
|
}
|
|
|
|
if (cx == 0 && py > 0) {
|
2009-10-06 07:09:00 +00:00
|
|
|
window_copy_cursor_up(wp, 0);
|
2009-08-13 19:35:20 +00:00
|
|
|
window_copy_cursor_end_of_line(wp);
|
2017-03-08 20:05:25 +00:00
|
|
|
} else if (cx > 0) {
|
|
|
|
window_copy_update_cursor(wp, cx - 1, data->cy);
|
2013-11-08 12:39:20 +00:00
|
|
|
if (window_copy_update_selection(wp, 1))
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_cursor_right(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2017-03-08 20:05:25 +00:00
|
|
|
u_int px, py, yy, cx, cy;
|
|
|
|
struct grid_cell gc;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-02-05 10:20:06 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
yy = screen_hsize(data->backing) + screen_size_y(data->backing) - 1;
|
2010-02-22 20:28:21 +00:00
|
|
|
if (data->screen.sel.flag && data->rectflag)
|
|
|
|
px = screen_size_x(&data->screen);
|
2017-03-08 20:05:25 +00:00
|
|
|
else
|
2010-02-22 20:28:21 +00:00
|
|
|
px = window_copy_find_length(wp, py);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-02-05 10:20:06 +00:00
|
|
|
if (data->cx >= px && py < yy) {
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_cursor_start_of_line(wp);
|
2009-10-06 07:09:00 +00:00
|
|
|
window_copy_cursor_down(wp, 0);
|
2016-02-05 10:20:06 +00:00
|
|
|
} else if (data->cx < px) {
|
2017-03-08 20:05:25 +00:00
|
|
|
cx = data->cx + 1;
|
|
|
|
cy = screen_hsize(data->backing) + data->cy - data->oy;
|
|
|
|
while (cx < px) {
|
|
|
|
grid_get_cell(data->backing->grid, cx, cy, &gc);
|
|
|
|
if (~gc.flags & GRID_FLAG_PADDING)
|
|
|
|
break;
|
|
|
|
cx++;
|
|
|
|
}
|
|
|
|
window_copy_update_cursor(wp, cx, data->cy);
|
2013-11-08 12:39:20 +00:00
|
|
|
if (window_copy_update_selection(wp, 1))
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-10-06 07:09:00 +00:00
|
|
|
window_copy_cursor_up(struct window_pane *wp, int scroll_only)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-01-24 21:05:12 +00:00
|
|
|
struct screen *s = &data->screen;
|
2009-06-01 22:58:49 +00:00
|
|
|
u_int ox, oy, px, py;
|
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
2009-06-01 22:58:49 +00:00
|
|
|
ox = window_copy_find_length(wp, oy);
|
2012-03-11 23:01:19 +00:00
|
|
|
if (data->cx != ox) {
|
2009-08-21 07:33:58 +00:00
|
|
|
data->lastcx = data->cx;
|
|
|
|
data->lastsx = ox;
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2014-11-06 09:17:25 +00:00
|
|
|
if (s->sel.lineflag == LINE_SEL_LEFT_RIGHT && oy == data->sely)
|
|
|
|
window_copy_other_end(wp);
|
|
|
|
|
2009-08-21 07:33:58 +00:00
|
|
|
data->cx = data->lastcx;
|
2009-10-06 07:09:00 +00:00
|
|
|
if (scroll_only || data->cy == 0) {
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_scroll_down(wp, 1);
|
2010-01-24 21:05:12 +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 07:09:00 +00:00
|
|
|
} else {
|
2009-08-13 19:35:20 +00:00
|
|
|
window_copy_update_cursor(wp, data->cx, data->cy - 1);
|
2013-11-08 12:39:20 +00:00
|
|
|
if (window_copy_update_selection(wp, 1)) {
|
2010-01-24 21:05:12 +00:00
|
|
|
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-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2010-02-22 20:28:21 +00:00
|
|
|
if (!data->screen.sel.flag || !data->rectflag) {
|
2010-04-06 21:35:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2010-02-22 20:28:21 +00:00
|
|
|
px = window_copy_find_length(wp, py);
|
2010-03-01 23:53:27 +00:00
|
|
|
if ((data->cx >= data->lastsx && data->cx != px) ||
|
|
|
|
data->cx > px)
|
2010-02-22 20:28:21 +00:00
|
|
|
window_copy_cursor_end_of_line(wp);
|
|
|
|
}
|
2014-11-06 09:17:25 +00:00
|
|
|
|
|
|
|
if (s->sel.lineflag == LINE_SEL_LEFT_RIGHT)
|
|
|
|
window_copy_cursor_end_of_line(wp);
|
|
|
|
else if (s->sel.lineflag == LINE_SEL_RIGHT_LEFT)
|
|
|
|
window_copy_cursor_start_of_line(wp);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-10-06 07:09:00 +00:00
|
|
|
window_copy_cursor_down(struct window_pane *wp, int scroll_only)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
u_int ox, oy, px, py;
|
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
oy = screen_hsize(data->backing) + data->cy - data->oy;
|
2009-06-01 22:58:49 +00:00
|
|
|
ox = window_copy_find_length(wp, oy);
|
2012-03-11 23:01:19 +00:00
|
|
|
if (data->cx != ox) {
|
2009-08-21 07:33:58 +00:00
|
|
|
data->lastcx = data->cx;
|
|
|
|
data->lastsx = ox;
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2017-03-21 09:51:00 +00:00
|
|
|
if (s->sel.lineflag == LINE_SEL_RIGHT_LEFT && oy == data->endsely)
|
2014-11-06 09:17:25 +00:00
|
|
|
window_copy_other_end(wp);
|
|
|
|
|
2009-08-21 07:33:58 +00:00
|
|
|
data->cx = data->lastcx;
|
2009-10-06 07:09:00 +00:00
|
|
|
if (scroll_only || data->cy == screen_size_y(s) - 1) {
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_scroll_up(wp, 1);
|
2009-10-20 21:35:25 +00:00
|
|
|
if (scroll_only && data->cy > 0)
|
2009-10-06 07:09:00 +00:00
|
|
|
window_copy_redraw_lines(wp, data->cy - 1, 2);
|
|
|
|
} else {
|
2009-08-13 19:35:20 +00:00
|
|
|
window_copy_update_cursor(wp, data->cx, data->cy + 1);
|
2013-11-08 12:39:20 +00:00
|
|
|
if (window_copy_update_selection(wp, 1))
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_redraw_lines(wp, data->cy - 1, 2);
|
|
|
|
}
|
|
|
|
|
2010-02-22 20:28:21 +00:00
|
|
|
if (!data->screen.sel.flag || !data->rectflag) {
|
2010-04-06 21:35:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2010-02-22 20:28:21 +00:00
|
|
|
px = window_copy_find_length(wp, py);
|
2010-03-01 23:53:27 +00:00
|
|
|
if ((data->cx >= data->lastsx && data->cx != px) ||
|
|
|
|
data->cx > px)
|
2010-02-22 20:28:21 +00:00
|
|
|
window_copy_cursor_end_of_line(wp);
|
|
|
|
}
|
2014-11-06 09:17:25 +00:00
|
|
|
|
|
|
|
if (s->sel.lineflag == LINE_SEL_LEFT_RIGHT)
|
|
|
|
window_copy_cursor_end_of_line(wp);
|
|
|
|
else if (s->sel.lineflag == LINE_SEL_RIGHT_LEFT)
|
|
|
|
window_copy_cursor_start_of_line(wp);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2010-03-22 19:10:42 +00:00
|
|
|
window_copy_cursor_jump(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2015-11-13 08:09:28 +00:00
|
|
|
struct grid_cell gc;
|
2011-03-28 19:44:31 +00:00
|
|
|
u_int px, py, xx;
|
2010-03-22 19:10:42 +00:00
|
|
|
|
|
|
|
px = data->cx + 1;
|
2010-04-06 21:35:44 +00:00
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
2010-03-22 19:10:42 +00:00
|
|
|
xx = window_copy_find_length(wp, py);
|
|
|
|
|
|
|
|
while (px < xx) {
|
2015-11-13 08:09:28 +00:00
|
|
|
grid_get_cell(back_s->grid, px, py, &gc);
|
|
|
|
if (!(gc.flags & GRID_FLAG_PADDING) &&
|
|
|
|
gc.data.size == 1 && *gc.data.data == data->jumpchar) {
|
2010-03-22 19:10:42 +00:00
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
2013-11-08 12:39:20 +00:00
|
|
|
if (window_copy_update_selection(wp, 1))
|
2010-03-22 19:10:42 +00:00
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
px++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2010-03-22 19:10:42 +00:00
|
|
|
window_copy_cursor_jump_back(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2015-11-13 08:09:28 +00:00
|
|
|
struct grid_cell gc;
|
2011-03-28 19:44:31 +00:00
|
|
|
u_int px, py;
|
2010-03-22 19:10:42 +00:00
|
|
|
|
|
|
|
px = data->cx;
|
2010-04-06 21:35:44 +00:00
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
2010-03-22 19:10:42 +00:00
|
|
|
|
|
|
|
if (px > 0)
|
|
|
|
px--;
|
|
|
|
|
|
|
|
for (;;) {
|
2015-11-13 08:09:28 +00:00
|
|
|
grid_get_cell(back_s->grid, px, py, &gc);
|
|
|
|
if (!(gc.flags & GRID_FLAG_PADDING) &&
|
|
|
|
gc.data.size == 1 && *gc.data.data == data->jumpchar) {
|
2010-03-22 19:10:42 +00:00
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
2013-11-08 12:39:20 +00:00
|
|
|
if (window_copy_update_selection(wp, 1))
|
2010-03-22 19:10:42 +00:00
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (px == 0)
|
|
|
|
break;
|
|
|
|
px--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2015-04-20 09:39:21 +00:00
|
|
|
window_copy_cursor_jump_to(struct window_pane *wp, int jump_again)
|
2011-12-04 16:18:01 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *back_s = data->backing;
|
2015-11-13 08:09:28 +00:00
|
|
|
struct grid_cell gc;
|
2011-12-04 16:18:01 +00:00
|
|
|
u_int px, py, xx;
|
|
|
|
|
2015-04-20 09:39:21 +00:00
|
|
|
px = data->cx + 1 + jump_again;
|
2011-12-04 16:18:01 +00:00
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
|
|
|
xx = window_copy_find_length(wp, py);
|
|
|
|
|
|
|
|
while (px < xx) {
|
2015-11-13 08:09:28 +00:00
|
|
|
grid_get_cell(back_s->grid, px, py, &gc);
|
|
|
|
if (!(gc.flags & GRID_FLAG_PADDING) &&
|
|
|
|
gc.data.size == 1 && *gc.data.data == data->jumpchar) {
|
2011-12-04 16:18:01 +00:00
|
|
|
window_copy_update_cursor(wp, px - 1, data->cy);
|
2013-11-08 12:39:20 +00:00
|
|
|
if (window_copy_update_selection(wp, 1))
|
2011-12-04 16:18:01 +00:00
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
px++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2015-04-20 09:39:21 +00:00
|
|
|
window_copy_cursor_jump_to_back(struct window_pane *wp, int jump_again)
|
2011-12-04 16:18:01 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *back_s = data->backing;
|
2015-11-13 08:09:28 +00:00
|
|
|
struct grid_cell gc;
|
2011-12-04 16:18:01 +00:00
|
|
|
u_int px, py;
|
|
|
|
|
|
|
|
px = data->cx;
|
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
|
|
|
|
|
|
|
if (px > 0)
|
|
|
|
px--;
|
|
|
|
|
2015-04-20 09:39:21 +00:00
|
|
|
if (jump_again && px > 0)
|
|
|
|
px--;
|
|
|
|
|
2011-12-04 16:18:01 +00:00
|
|
|
for (;;) {
|
2015-11-13 08:09:28 +00:00
|
|
|
grid_get_cell(back_s->grid, px, py, &gc);
|
|
|
|
if (!(gc.flags & GRID_FLAG_PADDING) &&
|
|
|
|
gc.data.size == 1 && *gc.data.data == data->jumpchar) {
|
2011-12-04 16:18:01 +00:00
|
|
|
window_copy_update_cursor(wp, px + 1, data->cy);
|
2013-11-08 12:39:20 +00:00
|
|
|
if (window_copy_update_selection(wp, 1))
|
2011-12-04 16:18:01 +00:00
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (px == 0)
|
|
|
|
break;
|
|
|
|
px--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2010-02-04 20:00:26 +00:00
|
|
|
window_copy_cursor_next_word(struct window_pane *wp, const char *separators)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2010-01-25 22:34:11 +00:00
|
|
|
u_int px, py, xx, yy;
|
2010-02-22 20:41:16 +00:00
|
|
|
int expected = 0;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-08-13 19:35:20 +00:00
|
|
|
px = data->cx;
|
2010-04-06 21:35:44 +00:00
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
2009-06-01 22:58:49 +00:00
|
|
|
xx = window_copy_find_length(wp, py);
|
2010-04-06 21:35:44 +00:00
|
|
|
yy = screen_hsize(back_s) + screen_size_y(back_s) - 1;
|
2010-01-25 22:34:11 +00:00
|
|
|
|
2010-02-22 20:41:16 +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-06 21:35:44 +00:00
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
2010-02-22 20:41:16 +00:00
|
|
|
xx = window_copy_find_length(wp, py);
|
|
|
|
} else
|
|
|
|
px++;
|
|
|
|
}
|
|
|
|
expected = !expected;
|
|
|
|
} while (expected == 1);
|
2010-01-27 20:18:52 +00:00
|
|
|
|
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
2013-11-08 12:39:20 +00:00
|
|
|
if (window_copy_update_selection(wp, 1))
|
2010-01-27 20:18:52 +00:00
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2014-04-17 14:45:49 +00:00
|
|
|
window_copy_cursor_next_word_end(struct window_pane *wp,
|
|
|
|
const char *separators)
|
2010-01-27 20:18:52 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2015-10-27 15:58:42 +00:00
|
|
|
struct options *oo = wp->window->options;
|
2010-04-06 21:35:44 +00:00
|
|
|
struct screen *back_s = data->backing;
|
2010-01-27 20:18:52 +00:00
|
|
|
u_int px, py, xx, yy;
|
2013-07-12 09:52:36 +00:00
|
|
|
int keys, expected = 1;
|
2010-01-27 20:18:52 +00:00
|
|
|
|
|
|
|
px = data->cx;
|
2010-04-06 21:35:44 +00:00
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
2010-01-27 20:18:52 +00:00
|
|
|
xx = window_copy_find_length(wp, py);
|
2010-04-06 21:35:44 +00:00
|
|
|
yy = screen_hsize(back_s) + screen_size_y(back_s) - 1;
|
2010-01-27 20:18:52 +00:00
|
|
|
|
2013-07-12 09:52:36 +00:00
|
|
|
keys = options_get_number(oo, "mode-keys");
|
|
|
|
if (keys == MODEKEY_VI && !window_copy_in_set(wp, px, py, separators))
|
|
|
|
px++;
|
|
|
|
|
2010-02-22 20:41:16 +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-06 21:35:44 +00:00
|
|
|
py = screen_hsize(back_s) + data->cy - data->oy;
|
2010-02-22 20:41:16 +00:00
|
|
|
xx = window_copy_find_length(wp, py);
|
|
|
|
} else
|
|
|
|
px++;
|
|
|
|
}
|
|
|
|
expected = !expected;
|
|
|
|
} while (expected == 0);
|
2010-01-25 22:34:11 +00:00
|
|
|
|
2013-07-12 09:52:36 +00:00
|
|
|
if (keys == MODEKEY_VI && px != 0)
|
2013-07-05 14:44:06 +00:00
|
|
|
px--;
|
|
|
|
|
2009-08-13 19:35:20 +00:00
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
2013-11-08 12:39:20 +00:00
|
|
|
if (window_copy_update_selection(wp, 1))
|
2009-08-13 19:35:20 +00:00
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 07:42:45 +00:00
|
|
|
/* Move to the previous place where a word begins. */
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2014-04-17 14:45:49 +00:00
|
|
|
window_copy_cursor_previous_word(struct window_pane *wp,
|
|
|
|
const char *separators)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2009-07-27 07:42:45 +00:00
|
|
|
u_int px, py;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-08-13 19:35:20 +00:00
|
|
|
px = data->cx;
|
2010-04-06 21:35:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-27 07:42:45 +00:00
|
|
|
/* Move back to the previous word character. */
|
2009-06-01 22:58:49 +00:00
|
|
|
for (;;) {
|
2009-07-27 07:42:45 +00:00
|
|
|
if (px > 0) {
|
|
|
|
px--;
|
2010-02-04 20:00:26 +00:00
|
|
|
if (!window_copy_in_set(wp, px, py, separators))
|
2009-06-01 22:58:49 +00:00
|
|
|
break;
|
|
|
|
} else {
|
2009-07-27 07:42:45 +00:00
|
|
|
if (data->cy == 0 &&
|
2010-04-06 21:35:44 +00:00
|
|
|
(screen_hsize(data->backing) == 0 ||
|
|
|
|
data->oy >= screen_hsize(data->backing) - 1))
|
2009-07-27 07:42:45 +00:00
|
|
|
goto out;
|
2009-10-06 07:09:00 +00:00
|
|
|
window_copy_cursor_up(wp, 0);
|
2009-07-27 07:42:45 +00:00
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2009-07-27 07:42:45 +00:00
|
|
|
px = window_copy_find_length(wp, py);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2009-07-27 07:42:45 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-27 07:42:45 +00:00
|
|
|
/* Move back to the beginning of this word. */
|
2010-02-04 20:00:26 +00:00
|
|
|
while (px > 0 && !window_copy_in_set(wp, px - 1, py, separators))
|
2009-06-01 22:58:49 +00:00
|
|
|
px--;
|
|
|
|
|
2009-07-27 07:42:45 +00:00
|
|
|
out:
|
2009-08-13 19:35:20 +00:00
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
2013-11-08 12:39:20 +00:00
|
|
|
if (window_copy_update_selection(wp, 1))
|
2009-08-13 19:35:20 +00:00
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-06-01 22:58:49 +00:00
|
|
|
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;
|
|
|
|
|
2013-11-08 12:39:20 +00:00
|
|
|
window_copy_update_selection(wp, 0);
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
screen_write_start(&ctx, wp, NULL);
|
|
|
|
screen_write_cursormove(&ctx, 0, 0);
|
2016-10-13 20:27:27 +00:00
|
|
|
screen_write_deleteline(&ctx, ny, 8);
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_write_lines(wp, &ctx, screen_size_y(s) - ny, ny);
|
|
|
|
window_copy_write_line(wp, &ctx, 0);
|
2009-10-20 21:35:25 +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);
|
2013-11-08 12:39:20 +00:00
|
|
|
if (s->sel.flag && screen_size_y(s) > ny)
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_write_line(wp, &ctx, screen_size_y(s) - ny - 1);
|
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_scroll_down(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;
|
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
if (ny > screen_hsize(data->backing))
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
if (data->oy > screen_hsize(data->backing) - ny)
|
|
|
|
ny = screen_hsize(data->backing) - data->oy;
|
2009-06-01 22:58:49 +00:00
|
|
|
if (ny == 0)
|
|
|
|
return;
|
|
|
|
data->oy += ny;
|
|
|
|
|
2013-11-08 12:39:20 +00:00
|
|
|
window_copy_update_selection(wp, 0);
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
screen_write_start(&ctx, wp, NULL);
|
|
|
|
screen_write_cursormove(&ctx, 0, 0);
|
2016-10-13 20:27:27 +00:00
|
|
|
screen_write_insertline(&ctx, ny, 8);
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_write_lines(wp, &ctx, 0, ny);
|
2013-11-08 12:39:20 +00:00
|
|
|
if (s->sel.flag && screen_size_y(s) > ny)
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_write_line(wp, &ctx, ny);
|
2013-11-08 12:39:20 +00:00
|
|
|
else if (ny == 1) /* nuke position */
|
2009-06-01 22:58:49 +00:00
|
|
|
window_copy_write_line(wp, &ctx, 1);
|
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|
2010-02-06 17:35:01 +00:00
|
|
|
|
2017-08-02 11:10:48 +00:00
|
|
|
void
|
|
|
|
window_copy_add_formats(struct window_pane *wp, struct format_tree *ft)
|
2015-10-23 16:02:21 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2017-08-02 11:10:48 +00:00
|
|
|
struct screen *s = &data->screen;
|
2015-10-23 16:02:21 +00:00
|
|
|
|
|
|
|
if (wp->mode != &window_copy_mode)
|
2017-08-02 11:10:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
format_add(ft, "selection_present", "%d", s->sel.flag);
|
|
|
|
format_add(ft, "scroll_position", "%d", data->oy);
|
2015-10-23 16:02:21 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2010-02-06 17:35:01 +00:00
|
|
|
window_copy_rectangle_toggle(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2010-02-22 20:28:21 +00:00
|
|
|
u_int px, py;
|
2010-02-06 17:35:01 +00:00
|
|
|
|
|
|
|
data->rectflag = !data->rectflag;
|
|
|
|
|
2010-04-06 21:35:44 +00:00
|
|
|
py = screen_hsize(data->backing) + data->cy - data->oy;
|
2010-02-22 20:28:21 +00:00
|
|
|
px = window_copy_find_length(wp, py);
|
|
|
|
if (data->cx > px)
|
|
|
|
window_copy_update_cursor(wp, px, data->cy);
|
|
|
|
|
2013-11-08 12:39:20 +00:00
|
|
|
window_copy_update_selection(wp, 1);
|
2010-02-06 17:35:01 +00:00
|
|
|
window_copy_redraw_screen(wp);
|
|
|
|
}
|
2015-04-19 21:34:21 +00:00
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2016-10-11 09:30:36 +00:00
|
|
|
window_copy_move_mouse(struct mouse_event *m)
|
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
|
|
|
u_int x, y;
|
|
|
|
|
|
|
|
wp = cmd_mouse_pane(m, NULL, NULL);
|
|
|
|
if (wp == NULL || wp->mode != &window_copy_mode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (cmd_mouse_at(wp, m, &x, &y, 1) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window_copy_update_cursor(wp, x, y);
|
|
|
|
}
|
|
|
|
|
2015-04-19 21:34:21 +00:00
|
|
|
void
|
2015-11-18 14:27:44 +00:00
|
|
|
window_copy_start_drag(struct client *c, struct mouse_event *m)
|
2015-04-19 21:34:21 +00:00
|
|
|
{
|
2015-04-20 15:41:32 +00:00
|
|
|
struct window_pane *wp;
|
|
|
|
u_int x, y;
|
2015-04-19 21:34:21 +00:00
|
|
|
|
2016-10-11 07:23:34 +00:00
|
|
|
if (c == NULL)
|
|
|
|
return;
|
|
|
|
|
2015-04-19 21:34:21 +00:00
|
|
|
wp = cmd_mouse_pane(m, NULL, NULL);
|
2015-04-21 15:16:06 +00:00
|
|
|
if (wp == NULL || wp->mode != &window_copy_mode)
|
2015-04-19 21:34:21 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (cmd_mouse_at(wp, m, &x, &y, 1) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
c->tty.mouse_drag_update = window_copy_drag_update;
|
2016-10-11 07:23:34 +00:00
|
|
|
c->tty.mouse_drag_release = NULL; /* will fire MouseDragEnd key */
|
2015-04-19 21:34:21 +00:00
|
|
|
|
|
|
|
window_copy_update_cursor(wp, x, y);
|
|
|
|
window_copy_start_selection(wp);
|
|
|
|
window_copy_redraw_screen(wp);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2015-11-18 14:27:44 +00:00
|
|
|
window_copy_drag_update(__unused struct client *c, struct mouse_event *m)
|
2015-04-19 21:34:21 +00:00
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
|
|
|
struct window_copy_mode_data *data;
|
|
|
|
u_int x, y, old_cy;
|
|
|
|
|
|
|
|
wp = cmd_mouse_pane(m, NULL, NULL);
|
2015-04-21 15:16:06 +00:00
|
|
|
if (wp == NULL || wp->mode != &window_copy_mode)
|
2015-04-19 21:34:21 +00:00
|
|
|
return;
|
|
|
|
data = wp->modedata;
|
|
|
|
|
|
|
|
if (cmd_mouse_at(wp, m, &x, &y, 0) != 0)
|
|
|
|
return;
|
|
|
|
old_cy = data->cy;
|
|
|
|
|
|
|
|
window_copy_update_cursor(wp, x, y);
|
|
|
|
if (window_copy_update_selection(wp, 1))
|
|
|
|
window_copy_redraw_selection(wp, old_cy);
|
|
|
|
}
|