2009-03-31 17:10:43 +02:00
|
|
|
/* $Id: window-copy.c,v 1.59 2009-03-31 15:10:43 nicm Exp $ */
|
2007-11-22 19:09:43 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
struct screen *window_copy_init(struct window_pane *);
|
|
|
|
void window_copy_free(struct window_pane *);
|
|
|
|
void window_copy_resize(struct window_pane *, u_int, u_int);
|
|
|
|
void window_copy_key(struct window_pane *, struct client *, int);
|
2009-01-28 23:00:22 +01:00
|
|
|
void window_copy_mouse(
|
|
|
|
struct window_pane *, struct client *, u_char, u_char, u_char);
|
2007-11-22 19:09:43 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
void window_copy_redraw_lines(struct window_pane *, u_int, u_int);
|
|
|
|
void window_copy_redraw_screen(struct window_pane *);
|
2007-12-06 10:46:23 +01:00
|
|
|
void window_copy_write_line(
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_pane *, struct screen_write_ctx *, u_int);
|
2007-12-06 10:46:23 +01:00
|
|
|
void window_copy_write_lines(
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_pane *, struct screen_write_ctx *, u_int, u_int);
|
2007-12-06 10:46:23 +01:00
|
|
|
void window_copy_write_column(
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_pane *, struct screen_write_ctx *, u_int);
|
2007-12-06 10:46:23 +01:00
|
|
|
void window_copy_write_columns(
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_pane *, struct screen_write_ctx *, u_int, u_int);
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
void window_copy_update_cursor(struct window_pane *);
|
|
|
|
void window_copy_start_selection(struct window_pane *);
|
|
|
|
int window_copy_update_selection(struct window_pane *);
|
|
|
|
void window_copy_copy_selection(struct window_pane *, struct client *);
|
2007-11-23 18:52:54 +01:00
|
|
|
void window_copy_copy_line(
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_pane *, char **, size_t *, u_int, u_int, u_int);
|
|
|
|
int window_copy_is_space(struct window_pane *, u_int, u_int);
|
|
|
|
u_int window_copy_find_length(struct window_pane *, u_int);
|
|
|
|
void window_copy_cursor_start_of_line(struct window_pane *);
|
|
|
|
void window_copy_cursor_end_of_line(struct window_pane *);
|
|
|
|
void window_copy_cursor_left(struct window_pane *);
|
|
|
|
void window_copy_cursor_right(struct window_pane *);
|
|
|
|
void window_copy_cursor_up(struct window_pane *);
|
|
|
|
void window_copy_cursor_down(struct window_pane *);
|
|
|
|
void window_copy_cursor_next_word(struct window_pane *);
|
|
|
|
void window_copy_cursor_previous_word(struct window_pane *);
|
|
|
|
void window_copy_scroll_left(struct window_pane *, u_int);
|
|
|
|
void window_copy_scroll_right(struct window_pane *, u_int);
|
|
|
|
void window_copy_scroll_up(struct window_pane *, u_int);
|
|
|
|
void window_copy_scroll_down(struct window_pane *, u_int);
|
2007-11-22 19:09:43 +01:00
|
|
|
|
|
|
|
const struct window_mode window_copy_mode = {
|
|
|
|
window_copy_init,
|
2007-12-06 10:46:23 +01:00
|
|
|
window_copy_free,
|
2007-11-22 19:09:43 +01:00
|
|
|
window_copy_resize,
|
2009-01-10 20:35:40 +01:00
|
|
|
window_copy_key,
|
2009-01-28 23:00:22 +01:00
|
|
|
window_copy_mouse,
|
2009-01-28 20:52:21 +01:00
|
|
|
NULL,
|
2007-11-22 19:09:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct window_copy_mode_data {
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen screen;
|
|
|
|
|
2009-02-13 22:39:45 +01:00
|
|
|
struct mode_key_data mdata;
|
|
|
|
|
2007-11-22 19:09:43 +01:00
|
|
|
u_int ox;
|
|
|
|
u_int oy;
|
2007-11-22 20:17:01 +01:00
|
|
|
|
2007-11-22 20:40:17 +01:00
|
|
|
u_int selx;
|
|
|
|
u_int sely;
|
2008-06-19 00:21:51 +02:00
|
|
|
|
2007-12-06 10:46:23 +01:00
|
|
|
u_int cx;
|
|
|
|
u_int cy;
|
2007-11-22 19:09:43 +01:00
|
|
|
};
|
|
|
|
|
2007-12-06 11:04:43 +01:00
|
|
|
struct screen *
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_init(struct window_pane *wp)
|
2007-11-22 19:09:43 +01:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data;
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s;
|
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
u_int i;
|
2007-11-22 19:09:43 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
wp->modedata = data = xmalloc(sizeof *data);
|
2007-12-06 10:46:23 +01:00
|
|
|
data->ox = 0;
|
|
|
|
data->oy = 0;
|
2009-01-12 00:31:46 +01:00
|
|
|
data->cx = wp->base.cx;
|
|
|
|
data->cy = wp->base.cy;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
|
|
|
s = &data->screen;
|
2009-01-12 00:31:46 +01:00
|
|
|
screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
|
2009-01-28 23:00:22 +01:00
|
|
|
s->mode |= MODE_MOUSE;
|
|
|
|
|
2009-02-13 22:39:45 +01:00
|
|
|
mode_key_init(&data->mdata,
|
|
|
|
options_get_number(&wp->window->options, "mode-keys"), 0);
|
|
|
|
|
2007-12-06 10:46:23 +01:00
|
|
|
s->cx = data->cx;
|
|
|
|
s->cy = data->cy;
|
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
screen_write_start(&ctx, NULL, s);
|
2007-12-06 10:46:23 +01:00
|
|
|
for (i = 0; i < screen_size_y(s); i++)
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_write_line(wp, &ctx, i);
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
2007-12-06 10:46:23 +01:00
|
|
|
screen_write_stop(&ctx);
|
2007-12-06 11:04:43 +01:00
|
|
|
|
|
|
|
return (s);
|
2007-11-22 19:09:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_free(struct window_pane *wp)
|
2007-11-22 19:09:43 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-11-22 19:09:43 +01:00
|
|
|
|
2009-02-13 22:39:45 +01:00
|
|
|
mode_key_free(&data->mdata);
|
|
|
|
|
2008-09-10 21:15:06 +02:00
|
|
|
screen_free(&data->screen);
|
2007-12-06 11:04:43 +01:00
|
|
|
xfree(data);
|
2007-11-22 19:09:43 +01:00
|
|
|
}
|
|
|
|
|
2009-01-28 00:35:44 +01:00
|
|
|
void
|
|
|
|
window_copy_pageup(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
|
|
|
|
if (data->oy + screen_size_y(s) > screen_hsize(&wp->base))
|
|
|
|
data->oy = screen_hsize(&wp->base);
|
|
|
|
else
|
|
|
|
data->oy += screen_size_y(s);
|
|
|
|
window_copy_update_selection(wp);
|
|
|
|
window_copy_redraw_screen(wp);
|
|
|
|
}
|
|
|
|
|
2007-11-22 19:09:43 +01:00
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_resize(struct window_pane *wp, u_int sx, u_int sy)
|
2007-11-22 19:09:43 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = &data->screen;
|
2008-09-25 22:08:57 +02:00
|
|
|
struct screen_write_ctx ctx;
|
2007-11-22 19:09:43 +01:00
|
|
|
|
2007-12-06 10:46:23 +01:00
|
|
|
screen_resize(s, sx, sy);
|
2009-01-12 00:31:46 +01:00
|
|
|
screen_write_start(&ctx, NULL, s);
|
|
|
|
window_copy_write_lines(wp, &ctx, 0, screen_size_y(s) - 1);
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_stop(&ctx);
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_selection(wp);
|
2007-11-22 19:09:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_key(struct window_pane *wp, struct client *c, int key)
|
2007-11-22 19:09:43 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = &data->screen;
|
2007-11-22 19:09:43 +01:00
|
|
|
|
2009-02-13 22:39:45 +01:00
|
|
|
switch (mode_key_lookup(&data->mdata, key)) {
|
|
|
|
case MODEKEYCMD_QUIT:
|
2009-01-12 00:31:46 +01:00
|
|
|
window_pane_reset_mode(wp);
|
2007-12-06 10:46:23 +01:00
|
|
|
break;
|
2009-02-13 22:39:45 +01:00
|
|
|
case MODEKEYCMD_LEFT:
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_left(wp);
|
2007-11-22 19:09:43 +01:00
|
|
|
return;
|
2009-02-13 22:39:45 +01:00
|
|
|
case MODEKEYCMD_RIGHT:
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_right(wp);
|
2007-11-22 19:09:43 +01:00
|
|
|
return;
|
2009-02-13 22:39:45 +01:00
|
|
|
case MODEKEYCMD_UP:
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_up(wp);
|
2007-11-22 19:09:43 +01:00
|
|
|
return;
|
2009-02-13 22:39:45 +01:00
|
|
|
case MODEKEYCMD_DOWN:
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_down(wp);
|
2007-11-22 19:09:43 +01:00
|
|
|
return;
|
2009-02-13 22:39:45 +01:00
|
|
|
case MODEKEYCMD_PREVIOUSPAGE:
|
2009-01-28 00:35:44 +01:00
|
|
|
window_copy_pageup(wp);
|
2007-11-22 19:09:43 +01:00
|
|
|
break;
|
2009-02-13 22:39:45 +01:00
|
|
|
case MODEKEYCMD_NEXTPAGE:
|
2007-12-06 10:46:23 +01:00
|
|
|
if (data->oy < screen_size_y(s))
|
2007-11-22 19:09:43 +01:00
|
|
|
data->oy = 0;
|
|
|
|
else
|
2007-12-06 10:46:23 +01:00
|
|
|
data->oy -= screen_size_y(s);
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_selection(wp);
|
|
|
|
window_copy_redraw_screen(wp);
|
2007-11-22 19:09:43 +01:00
|
|
|
break;
|
2009-02-13 22:39:45 +01:00
|
|
|
case MODEKEYCMD_STARTSELECTION:
|
2009-01-28 23:00:22 +01:00
|
|
|
window_copy_start_selection(wp);
|
2007-11-22 20:17:01 +01:00
|
|
|
break;
|
2009-02-13 22:39:45 +01:00
|
|
|
case MODEKEYCMD_CLEARSELECTION:
|
2007-12-06 10:46:23 +01:00
|
|
|
screen_clear_selection(&data->screen);
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_redraw_screen(wp);
|
2007-12-06 10:46:23 +01:00
|
|
|
break;
|
2009-02-13 22:39:45 +01:00
|
|
|
case MODEKEYCMD_COPYSELECTION:
|
2008-06-20 19:31:48 +02:00
|
|
|
if (c != NULL && c->session != NULL) {
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_copy_selection(wp, c);
|
|
|
|
window_pane_reset_mode(wp);
|
2008-06-20 19:31:48 +02:00
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
break;
|
2009-02-13 22:39:45 +01:00
|
|
|
case MODEKEYCMD_STARTOFLINE:
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_start_of_line(wp);
|
2007-12-06 10:46:23 +01:00
|
|
|
break;
|
2009-02-13 22:39:45 +01:00
|
|
|
case MODEKEYCMD_ENDOFLINE:
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_end_of_line(wp);
|
2007-12-06 10:46:23 +01:00
|
|
|
break;
|
2009-02-13 22:39:45 +01:00
|
|
|
case MODEKEYCMD_NEXTWORD:
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_next_word(wp);
|
2008-06-24 09:00:39 +02:00
|
|
|
break;
|
2009-02-13 22:39:45 +01:00
|
|
|
case MODEKEYCMD_PREVIOUSWORD:
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_previous_word(wp);
|
2008-06-24 09:00:39 +02:00
|
|
|
break;
|
2008-07-02 23:22:57 +02:00
|
|
|
default:
|
|
|
|
break;
|
2007-11-22 19:09:43 +01:00
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2009-01-28 23:00:22 +01:00
|
|
|
void
|
|
|
|
window_copy_mouse(struct window_pane *wp,
|
|
|
|
unused struct client *c, u_char b, u_char x, u_char y)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
|
|
|
|
if ((b & 3) == 3)
|
|
|
|
return;
|
|
|
|
if (x >= screen_size_x(s))
|
|
|
|
return;
|
|
|
|
if (y >= screen_size_y(s))
|
|
|
|
return;
|
|
|
|
|
|
|
|
data->cx = x;
|
|
|
|
data->cy = y;
|
|
|
|
|
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_screen(wp);
|
|
|
|
window_copy_update_cursor(wp);
|
|
|
|
}
|
|
|
|
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_write_line(struct window_pane *wp, struct screen_write_ctx *ctx, u_int py)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = &data->screen;
|
2008-09-25 22:08:57 +02:00
|
|
|
struct grid_cell gc;
|
|
|
|
char hdr[32];
|
2007-12-06 10:46:23 +01:00
|
|
|
size_t size;
|
|
|
|
|
|
|
|
if (py == 0) {
|
2008-09-25 22:08:57 +02:00
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
|
|
|
size = xsnprintf(hdr, sizeof hdr,
|
2009-01-12 00:31:46 +01:00
|
|
|
"[%u,%u/%u]", data->ox, data->oy, screen_hsize(&wp->base));
|
2009-01-23 21:49:01 +01:00
|
|
|
gc.bg = options_get_number(&wp->window->options, "mode-fg");
|
|
|
|
gc.fg = options_get_number(&wp->window->options, "mode-bg");
|
Allow status, mode and message attributes to be changed by three new options: status-attr, mode-attr, message-attr. A comma-separataed list is accepted containing: bright, dim, underscore, blink, reverse, hidden, italics, for example: set -g status-attr bright,blink
From Josh Elsasser, thanks!
2009-01-27 21:22:33 +01:00
|
|
|
gc.attr |= options_get_number(&wp->window->options, "mode-attr");
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(ctx, screen_size_x(s) - size, 0);
|
|
|
|
screen_write_puts(ctx, &gc, "%s", hdr);
|
2007-12-06 10:46:23 +01:00
|
|
|
} else
|
|
|
|
size = 0;
|
2008-09-25 22:08:57 +02:00
|
|
|
|
|
|
|
screen_write_cursormove(ctx, 0, py);
|
2009-01-12 00:31:46 +01:00
|
|
|
screen_write_copy(ctx, &wp->base, data->ox, (screen_hsize(&wp->base) -
|
2008-09-25 22:08:57 +02:00
|
|
|
data->oy) + py, screen_size_x(s) - size, 1);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_write_lines(
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_pane *wp, struct screen_write_ctx *ctx, u_int py, u_int ny)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2008-09-25 22:08:57 +02:00
|
|
|
u_int yy;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
for (yy = py; yy < py + ny; yy++)
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_write_line(wp, ctx, py);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
2007-11-23 18:52:54 +01:00
|
|
|
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
|
|
|
window_copy_write_column(
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_pane *wp, struct screen_write_ctx *ctx, u_int px)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(ctx, px, 0);
|
2009-01-12 00:31:46 +01:00
|
|
|
screen_write_copy(ctx, &wp->base,
|
2009-03-30 23:08:04 +02:00
|
|
|
data->ox + px, screen_hsize(&wp->base) - data->oy, 1, screen_size_y(s));
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_write_columns(
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_pane *wp, struct screen_write_ctx *ctx, u_int px, u_int nx)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2008-09-25 22:08:57 +02:00
|
|
|
u_int xx;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
for (xx = px; xx < px + nx; xx++)
|
2009-03-30 23:08:04 +02:00
|
|
|
window_copy_write_column(wp, ctx, xx);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_redraw_lines(struct window_pane *wp, u_int py, u_int ny)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
u_int i;
|
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
screen_write_start(&ctx, wp, NULL);
|
2007-12-06 10:46:23 +01:00
|
|
|
for (i = py; i < py + ny; i++)
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_write_line(wp, &ctx, i);
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
2007-12-06 10:46:23 +01:00
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_redraw_screen(struct window_pane *wp)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_redraw_lines(wp, 0, screen_size_y(&data->screen));
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_cursor(struct window_pane *wp)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
screen_write_start(&ctx, wp, NULL);
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
2007-12-06 10:46:23 +01:00
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_start_selection(struct window_pane *wp)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
data->selx = data->cx + data->ox;
|
2009-01-12 00:31:46 +01:00
|
|
|
data->sely = screen_hsize(&wp->base) + data->cy - data->oy;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
|
|
|
s->sel.flag = 1;
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_selection(wp);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_selection(struct window_pane *wp)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = &data->screen;
|
2008-12-08 17:19:51 +01:00
|
|
|
struct grid_cell gc;
|
2007-12-06 10:46:23 +01:00
|
|
|
u_int sx, sy, tx, ty;
|
|
|
|
|
|
|
|
if (!s->sel.flag)
|
|
|
|
return (0);
|
|
|
|
|
2008-12-08 17:19:51 +01:00
|
|
|
/* Set colours. */
|
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
2009-01-23 21:50:58 +01:00
|
|
|
gc.bg = options_get_number(&wp->window->options, "mode-fg");
|
|
|
|
gc.fg = options_get_number(&wp->window->options, "mode-bg");
|
Allow status, mode and message attributes to be changed by three new options: status-attr, mode-attr, message-attr. A comma-separataed list is accepted containing: bright, dim, underscore, blink, reverse, hidden, italics, for example: set -g status-attr bright,blink
From Josh Elsasser, thanks!
2009-01-27 21:22:33 +01:00
|
|
|
gc.attr |= options_get_number(&wp->window->options, "mode-attr");
|
2008-12-08 17:19:51 +01:00
|
|
|
|
2007-12-06 10:46:23 +01:00
|
|
|
/* Find top-left of screen. */
|
2008-09-25 22:08:57 +02:00
|
|
|
tx = data->ox;
|
2009-01-12 00:31:46 +01:00
|
|
|
ty = screen_hsize(&wp->base) - data->oy;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
|
|
|
/* Adjust the selection. */
|
|
|
|
sx = data->selx;
|
|
|
|
sy = data->sely;
|
|
|
|
if (sy < ty) {
|
|
|
|
/* Above it. */
|
|
|
|
sx = 0;
|
|
|
|
sy = 0;
|
2008-09-25 22:08:57 +02:00
|
|
|
} else if (sy > ty + screen_size_y(s) - 1) {
|
2007-12-06 10:46:23 +01:00
|
|
|
/* Below it. */
|
2008-09-25 22:08:57 +02:00
|
|
|
sx = screen_size_x(s) - 1;
|
|
|
|
sy = screen_size_y(s) - 1;
|
2007-12-06 10:46:23 +01:00
|
|
|
} else if (sx < tx) {
|
|
|
|
/* To the left. */
|
|
|
|
sx = 0;
|
2008-09-25 22:08:57 +02:00
|
|
|
} else if (sx > tx + screen_size_x(s) - 1) {
|
2007-12-06 10:46:23 +01:00
|
|
|
/* To the right. */
|
|
|
|
sx = 0;
|
|
|
|
sy++;
|
2008-09-25 22:08:57 +02:00
|
|
|
if (sy > screen_size_y(s) - 1)
|
|
|
|
sy = screen_size_y(s) - 1;
|
2007-12-06 10:46:23 +01:00
|
|
|
} else {
|
|
|
|
sx -= tx;
|
|
|
|
sy -= ty;
|
|
|
|
}
|
2008-09-25 22:08:57 +02:00
|
|
|
sy = screen_hsize(s) + sy;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-12-08 17:19:51 +01:00
|
|
|
screen_set_selection(
|
|
|
|
s, sx, sy, data->cx, screen_hsize(s) + data->cy, &gc);
|
2007-12-06 10:46:23 +01:00
|
|
|
return (1);
|
2007-11-23 18:52:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_copy_selection(struct window_pane *wp, struct client *c)
|
2007-11-23 18:52:54 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-07 10:49:18 +01:00
|
|
|
struct screen *s = &data->screen;
|
2007-11-23 18:52:54 +01:00
|
|
|
char *buf;
|
2008-08-07 22:20:52 +02:00
|
|
|
size_t off;
|
2008-06-20 20:45:35 +02:00
|
|
|
u_int i, xx, yy, sx, sy, ex, ey, limit;
|
2007-11-23 18:52:54 +01:00
|
|
|
|
2007-12-07 10:49:18 +01:00
|
|
|
if (!s->sel.flag)
|
|
|
|
return;
|
|
|
|
|
2008-08-07 22:20:52 +02:00
|
|
|
buf = xmalloc(1);
|
2007-11-23 18:52:54 +01:00
|
|
|
off = 0;
|
|
|
|
|
|
|
|
*buf = '\0';
|
|
|
|
|
2007-12-06 10:46:23 +01:00
|
|
|
/*
|
|
|
|
* The selection extends from selx,sely to (adjusted) cx,cy on
|
|
|
|
* the base screen.
|
|
|
|
*/
|
|
|
|
|
2007-11-23 18:52:54 +01:00
|
|
|
/* Find start and end. */
|
2008-09-25 22:08:57 +02:00
|
|
|
xx = data->cx + data->ox;
|
2009-01-12 00:31:46 +01:00
|
|
|
yy = screen_hsize(&wp->base) + data->cy - data->oy;
|
2007-11-23 18:52:54 +01:00
|
|
|
if (xx < data->selx || (yy == data->sely && xx < data->selx)) {
|
|
|
|
sx = xx; sy = yy;
|
|
|
|
ex = data->selx; ey = data->sely;
|
|
|
|
} else {
|
|
|
|
sx = data->selx; sy = data->sely;
|
|
|
|
ex = xx; ey = yy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Trim ex to end of line. */
|
2009-01-12 00:31:46 +01:00
|
|
|
xx = window_copy_find_length(wp, ey);
|
2007-11-23 18:52:54 +01:00
|
|
|
if (ex > xx)
|
|
|
|
ex = xx;
|
|
|
|
|
|
|
|
/* Copy the lines. */
|
|
|
|
if (sy == ey)
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_copy_line(wp, &buf, &off, sy, sx, ex);
|
2007-11-23 18:52:54 +01:00
|
|
|
else {
|
2009-01-12 00:31:46 +01:00
|
|
|
xx = window_copy_find_length(wp, sy);
|
|
|
|
window_copy_copy_line(wp, &buf, &off, sy, sx, xx);
|
2007-11-23 18:52:54 +01:00
|
|
|
if (ey - sy > 1) {
|
|
|
|
for (i = sy + 1; i < ey - 1; i++) {
|
2009-01-12 00:31:46 +01:00
|
|
|
xx = window_copy_find_length(wp, i);
|
|
|
|
window_copy_copy_line(wp, &buf, &off, i, 0, xx);
|
2007-11-23 18:52:54 +01:00
|
|
|
}
|
|
|
|
}
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_copy_line(wp, &buf, &off, ey, 0, ex);
|
2007-11-23 18:52:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Terminate buffer, overwriting final \n. */
|
|
|
|
if (off != 0)
|
|
|
|
buf[off - 1] = '\0';
|
|
|
|
|
2008-06-20 19:31:48 +02:00
|
|
|
/* Add the buffer to the stack. */
|
2008-06-20 20:45:35 +02:00
|
|
|
limit = options_get_number(&c->session->options, "buffer-limit");
|
|
|
|
paste_add(&c->session->buffers, buf, limit);
|
2007-11-23 18:52:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-28 21:17:29 +01:00
|
|
|
window_copy_copy_line(struct window_pane *wp,
|
|
|
|
char **buf, size_t *off, u_int sy, u_int sx, u_int ex)
|
2007-11-23 18:52:54 +01:00
|
|
|
{
|
2009-03-28 21:17:29 +01:00
|
|
|
const struct grid_cell *gc;
|
|
|
|
const struct grid_utf8 *gu;
|
|
|
|
u_int i, j, xx;
|
2007-11-23 18:52:54 +01:00
|
|
|
|
|
|
|
if (sx > ex)
|
|
|
|
return;
|
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
xx = window_copy_find_length(wp, sy);
|
2007-11-23 18:52:54 +01:00
|
|
|
if (ex > xx)
|
|
|
|
ex = xx;
|
|
|
|
if (sx > xx)
|
|
|
|
sx = xx;
|
|
|
|
|
|
|
|
if (sx < ex) {
|
|
|
|
for (i = sx; i < ex; i++) {
|
2009-03-28 21:17:29 +01:00
|
|
|
gc = grid_peek_cell(wp->base.grid, i, sy);
|
2009-03-30 21:57:02 +02:00
|
|
|
if (gc->flags & GRID_FLAG_PADDING)
|
|
|
|
continue;
|
2009-03-30 22:14:50 +02:00
|
|
|
if (!(gc->flags & GRID_FLAG_UTF8)) {
|
2009-03-28 21:17:29 +01:00
|
|
|
*buf = xrealloc(*buf, 1, (*off) + 1);
|
|
|
|
(*buf)[(*off)++] = gc->data;
|
|
|
|
} else {
|
|
|
|
gu = grid_peek_utf8(wp->base.grid, i, sy);
|
2009-03-31 14:28:45 +02:00
|
|
|
*buf = xrealloc(*buf, 1, (*off) + UTF8_SIZE);
|
2009-03-29 13:18:28 +02:00
|
|
|
for (j = 0; j < UTF8_SIZE; j++) {
|
2009-03-31 17:10:43 +02:00
|
|
|
if (gu->data[j] == 0xff)
|
2009-03-28 21:17:29 +01:00
|
|
|
break;
|
2009-03-31 17:10:43 +02:00
|
|
|
(*buf)[(*off)++] = gu->data[j];
|
2009-03-28 21:17:29 +01:00
|
|
|
}
|
2008-09-25 22:08:57 +02:00
|
|
|
}
|
2007-11-23 18:52:54 +01:00
|
|
|
}
|
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-08-07 22:20:52 +02:00
|
|
|
*buf = xrealloc(*buf, 1, (*off) + 1);
|
2007-11-23 18:52:54 +01:00
|
|
|
(*buf)[*off] = '\n';
|
|
|
|
(*off)++;
|
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
int
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_is_space(struct window_pane *wp, u_int px, u_int py)
|
2008-09-25 22:08:57 +02:00
|
|
|
{
|
|
|
|
const struct grid_cell *gc;
|
2009-03-28 17:30:05 +01:00
|
|
|
const char *spaces = " -_@";
|
2008-09-25 22:08:57 +02:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
gc = grid_peek_cell(wp->base.grid, px, py);
|
2009-03-28 21:17:29 +01:00
|
|
|
if (gc->flags & (GRID_FLAG_PADDING|GRID_FLAG_UTF8))
|
2008-09-25 22:08:57 +02:00
|
|
|
return (0);
|
2009-03-28 21:17:29 +01:00
|
|
|
if (gc->data == 0x00 || gc->data == 0x7f)
|
2008-09-25 22:08:57 +02:00
|
|
|
return (0);
|
2009-03-28 21:17:29 +01:00
|
|
|
return (strchr(spaces, gc->data) != NULL);
|
2008-09-25 22:08:57 +02:00
|
|
|
}
|
|
|
|
|
2007-11-23 18:52:54 +01:00
|
|
|
u_int
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_find_length(struct window_pane *wp, u_int py)
|
2007-11-23 18:52:54 +01:00
|
|
|
{
|
2009-03-28 21:17:29 +01:00
|
|
|
const struct grid_cell *gc;
|
|
|
|
u_int px;
|
2008-09-25 22:08:57 +02:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
px = wp->base.grid->size[py];
|
2008-09-25 22:08:57 +02:00
|
|
|
while (px > 0) {
|
2009-03-28 21:17:29 +01:00
|
|
|
gc = grid_peek_cell(wp->base.grid, px - 1, py);
|
2009-03-30 21:57:02 +02:00
|
|
|
if (gc->flags & GRID_FLAG_UTF8)
|
|
|
|
break;
|
|
|
|
if (gc->data != ' ')
|
2008-09-25 22:08:57 +02:00
|
|
|
break;
|
2007-11-23 18:52:54 +01:00
|
|
|
px--;
|
2008-09-25 22:08:57 +02:00
|
|
|
}
|
2007-11-23 18:52:54 +01:00
|
|
|
return (px);
|
2007-11-22 19:09:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_start_of_line(struct window_pane *wp)
|
2007-11-26 21:36:30 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-11-26 21:36:30 +01:00
|
|
|
|
|
|
|
if (data->ox != 0)
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_scroll_right(wp, data->ox);
|
2007-11-26 21:36:30 +01:00
|
|
|
data->cx = 0;
|
2007-11-26 21:45:13 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
2007-12-06 10:46:23 +01:00
|
|
|
else
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_cursor(wp);
|
2007-11-26 21:36:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_end_of_line(struct window_pane *wp)
|
2007-11-26 21:36:30 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
u_int px, py;
|
2007-11-26 21:36:30 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
py = screen_hsize(&wp->base) + data->cy - data->oy;
|
|
|
|
px = window_copy_find_length(wp, py);
|
2007-11-26 21:36:30 +01:00
|
|
|
|
|
|
|
/* On screen. */
|
2008-09-25 22:08:57 +02:00
|
|
|
if (px > data->ox && px <= data->ox + screen_size_x(s) - 1)
|
2007-12-06 10:46:23 +01:00
|
|
|
data->cx = px - data->ox;
|
2007-11-26 21:36:30 +01:00
|
|
|
|
|
|
|
/* Off right of screen. */
|
2008-09-25 22:08:57 +02:00
|
|
|
if (px > data->ox + screen_size_x(s) - 1) {
|
2007-11-26 21:36:30 +01:00
|
|
|
/* Move cursor to last and scroll screen. */
|
2008-09-25 22:08:57 +02:00
|
|
|
window_copy_scroll_left(
|
2009-01-12 00:31:46 +01:00
|
|
|
wp, px - data->ox - (screen_size_x(s) - 1));
|
2008-09-25 22:08:57 +02:00
|
|
|
data->cx = screen_size_x(s) - 1;
|
2007-11-26 21:36:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Off left of screen. */
|
2007-12-06 10:46:23 +01:00
|
|
|
if (px <= data->ox) {
|
2008-09-25 22:08:57 +02:00
|
|
|
if (px < screen_size_x(s) - 1) {
|
2007-11-26 21:36:30 +01:00
|
|
|
/* Short enough to fit on screen. */
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_scroll_right(wp, data->ox);
|
2007-12-06 10:46:23 +01:00
|
|
|
data->cx = px;
|
2007-11-26 21:36:30 +01:00
|
|
|
} else {
|
|
|
|
/* Too long to fit on screen. */
|
|
|
|
window_copy_scroll_right(
|
2009-01-12 00:31:46 +01:00
|
|
|
wp, data->ox - (px - (screen_size_x(s) - 1)));
|
2008-09-25 22:08:57 +02:00
|
|
|
data->cx = screen_size_x(s) - 1;
|
2007-11-26 21:36:30 +01:00
|
|
|
}
|
2008-06-24 09:00:39 +02:00
|
|
|
}
|
2007-11-26 21:36:30 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
2007-12-06 10:46:23 +01:00
|
|
|
else
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_cursor(wp);
|
2007-11-26 21:36:30 +01:00
|
|
|
}
|
|
|
|
|
2007-11-22 19:09:43 +01:00
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_left(struct window_pane *wp)
|
2007-11-22 19:09:43 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-11-22 19:09:43 +01:00
|
|
|
|
2007-12-06 10:46:23 +01:00
|
|
|
if (data->cx == 0) {
|
|
|
|
if (data->ox > 0)
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_scroll_right(wp, 1);
|
2007-12-06 10:46:23 +01:00
|
|
|
else {
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_up(wp);
|
|
|
|
window_copy_cursor_end_of_line(wp);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
} else {
|
2007-11-22 19:09:43 +01:00
|
|
|
data->cx--;
|
2009-01-12 00:31:46 +01:00
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
2007-12-06 10:46:23 +01:00
|
|
|
else
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_cursor(wp);
|
2007-11-22 20:17:01 +01:00
|
|
|
}
|
2007-11-22 19:09:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_right(struct window_pane *wp)
|
2007-11-22 19:09:43 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
u_int px, py;
|
2007-11-22 19:09:43 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
py = screen_hsize(&wp->base) + data->cy - data->oy;
|
|
|
|
px = window_copy_find_length(wp, py);
|
2007-12-06 10:46:23 +01:00
|
|
|
|
|
|
|
if (data->cx >= px) {
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_start_of_line(wp);
|
|
|
|
window_copy_cursor_down(wp);
|
2007-12-06 10:46:23 +01:00
|
|
|
} else {
|
2007-11-22 19:09:43 +01:00
|
|
|
data->cx++;
|
2009-01-12 00:31:46 +01:00
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
2007-12-06 10:46:23 +01:00
|
|
|
else
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_cursor(wp);
|
2007-11-22 20:17:01 +01:00
|
|
|
}
|
2007-11-22 19:09:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_up(struct window_pane *wp)
|
2007-11-22 19:09:43 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
u_int ox, oy, px, py;
|
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
oy = screen_hsize(&wp->base) + data->cy - data->oy;
|
|
|
|
ox = window_copy_find_length(wp, oy);
|
2007-11-22 19:09:43 +01:00
|
|
|
|
|
|
|
if (data->cy == 0)
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_scroll_down(wp, 1);
|
2007-11-22 20:17:01 +01:00
|
|
|
else {
|
2007-11-22 19:09:43 +01:00
|
|
|
data->cy--;
|
2009-01-12 00:31:46 +01:00
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 2);
|
2007-12-06 10:46:23 +01:00
|
|
|
else
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_cursor(wp);
|
2007-11-22 20:17:01 +01:00
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
py = screen_hsize(&wp->base) + data->cy - data->oy;
|
|
|
|
px = window_copy_find_length(wp, py);
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2007-12-07 10:49:18 +01:00
|
|
|
if (data->cx + data->ox >= px || data->cx + data->ox >= ox)
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_end_of_line(wp);
|
2007-11-22 19:09:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_down(struct window_pane *wp)
|
2007-11-22 19:09:43 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
u_int ox, oy, px, py;
|
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
oy = screen_hsize(&wp->base) + data->cy - data->oy;
|
|
|
|
ox = window_copy_find_length(wp, oy);
|
2007-11-22 19:09:43 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (data->cy == screen_size_y(s) - 1)
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_scroll_up(wp, 1);
|
2007-11-22 20:17:01 +01:00
|
|
|
else {
|
2007-11-22 19:09:43 +01:00
|
|
|
data->cy++;
|
2009-01-12 00:31:46 +01:00
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy - 1, 2);
|
2007-12-06 10:46:23 +01:00
|
|
|
else
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_cursor(wp);
|
2007-11-22 20:17:01 +01:00
|
|
|
}
|
2007-11-22 19:09:43 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
py = screen_hsize(&wp->base) + data->cy - data->oy;
|
|
|
|
px = window_copy_find_length(wp, py);
|
2007-11-22 20:17:01 +01:00
|
|
|
|
2007-12-07 10:49:18 +01:00
|
|
|
if (data->cx + data->ox >= px || data->cx + data->ox >= ox)
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_end_of_line(wp);
|
2007-11-22 20:17:01 +01:00
|
|
|
}
|
|
|
|
|
2008-06-24 09:00:39 +02:00
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_next_word(struct window_pane *wp)
|
2008-06-24 09:00:39 +02:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2008-06-24 09:00:39 +02:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
u_int px, py, xx, skip;
|
|
|
|
|
|
|
|
px = data->ox + data->cx;
|
2009-01-12 00:31:46 +01:00
|
|
|
py = screen_hsize(&wp->base) + data->cy - data->oy;
|
|
|
|
xx = window_copy_find_length(wp, py);
|
2008-06-24 09:00:39 +02:00
|
|
|
|
|
|
|
skip = 1;
|
|
|
|
if (px < xx) {
|
|
|
|
/* If currently on a space, skip space. */
|
2009-01-12 00:31:46 +01:00
|
|
|
if (window_copy_is_space(wp, px, py))
|
2008-06-24 09:00:39 +02:00
|
|
|
skip = 0;
|
|
|
|
} else
|
|
|
|
skip = 0;
|
|
|
|
for (;;) {
|
|
|
|
if (px >= xx) {
|
|
|
|
if (skip) {
|
|
|
|
px = xx;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (px >= xx) {
|
2008-09-25 22:08:57 +02:00
|
|
|
if (data->cy == screen_size_y(s) - 1) {
|
2008-06-24 09:00:39 +02:00
|
|
|
if (data->oy == 0)
|
|
|
|
goto out;
|
|
|
|
}
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-06-24 09:00:39 +02:00
|
|
|
px = 0;
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_down(wp);
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
py =screen_hsize(
|
2009-01-12 00:31:46 +01:00
|
|
|
&wp->base) + data->cy - data->oy;
|
|
|
|
xx = window_copy_find_length(wp, py);
|
2008-06-24 09:00:39 +02:00
|
|
|
}
|
|
|
|
}
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-06-24 09:00:39 +02:00
|
|
|
if (skip) {
|
|
|
|
/* Currently skipping non-space (until space). */
|
2009-01-12 00:31:46 +01:00
|
|
|
if (window_copy_is_space(wp, px, py))
|
2008-06-24 09:00:39 +02:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
/* Currently skipping space (until non-space). */
|
2009-01-12 00:31:46 +01:00
|
|
|
if (!window_copy_is_space(wp, px, py))
|
2008-06-24 09:00:39 +02:00
|
|
|
skip = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
px++;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
|
|
|
|
/* On screen. */
|
2008-09-25 22:08:57 +02:00
|
|
|
if (px > data->ox && px <= data->ox + screen_size_x(s) - 1)
|
2008-06-24 09:00:39 +02:00
|
|
|
data->cx = px - data->ox;
|
|
|
|
|
|
|
|
/* Off right of screen. */
|
2008-09-25 22:08:57 +02:00
|
|
|
if (px > data->ox + screen_size_x(s) - 1) {
|
2008-06-24 09:00:39 +02:00
|
|
|
/* Move cursor to last and scroll screen. */
|
2008-09-25 22:08:57 +02:00
|
|
|
window_copy_scroll_left(
|
2009-01-12 00:31:46 +01:00
|
|
|
wp, px - data->ox - (screen_size_x(s) - 1));
|
2008-09-25 22:08:57 +02:00
|
|
|
data->cx = screen_size_x(s) - 1;
|
2008-06-24 09:00:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Off left of screen. */
|
|
|
|
if (px <= data->ox) {
|
2008-09-25 22:08:57 +02:00
|
|
|
if (px < screen_size_x(s) - 1) {
|
2008-06-24 09:00:39 +02:00
|
|
|
/* Short enough to fit on screen. */
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_scroll_right(wp, data->ox);
|
2008-06-24 09:00:39 +02:00
|
|
|
data->cx = px;
|
|
|
|
} else {
|
|
|
|
/* Too long to fit on screen. */
|
|
|
|
window_copy_scroll_right(
|
2009-01-12 00:31:46 +01:00
|
|
|
wp, data->ox - (px - (screen_size_x(s) - 1)));
|
2008-09-25 22:08:57 +02:00
|
|
|
data->cx = screen_size_x(s) - 1;
|
2008-06-24 09:00:39 +02:00
|
|
|
}
|
|
|
|
}
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
2008-06-24 09:00:39 +02:00
|
|
|
else
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_cursor(wp);
|
2008-06-24 09:00:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_previous_word(struct window_pane *wp)
|
2008-06-24 09:00:39 +02:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2008-06-24 09:00:39 +02:00
|
|
|
struct screen *s = &data->screen;
|
2008-06-27 19:41:48 +02:00
|
|
|
u_int ox, px, py, skip;
|
2008-06-24 09:00:39 +02:00
|
|
|
|
2008-06-27 19:41:48 +02:00
|
|
|
ox = px = data->ox + data->cx;
|
2009-01-12 00:31:46 +01:00
|
|
|
py = screen_hsize(&wp->base) + data->cy - data->oy;
|
2008-06-24 09:00:39 +02:00
|
|
|
|
|
|
|
skip = 1;
|
|
|
|
if (px != 0) {
|
|
|
|
/* If currently on a space, skip space. */
|
2009-01-12 00:31:46 +01:00
|
|
|
if (window_copy_is_space(wp, px - 1, py))
|
2008-06-24 09:00:39 +02:00
|
|
|
skip = 0;
|
|
|
|
}
|
|
|
|
for (;;) {
|
2008-06-27 19:41:48 +02:00
|
|
|
if (px == 0) {
|
|
|
|
if (ox != 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
while (px == 0) {
|
2008-09-26 08:45:28 +02:00
|
|
|
if (data->cy == 0 &&
|
2009-01-12 00:31:46 +01:00
|
|
|
(screen_hsize(&wp->base) == 0 ||
|
|
|
|
data->oy >= screen_hsize(&wp->base) - 1))
|
2008-06-24 09:00:39 +02:00
|
|
|
goto out;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_cursor_up(wp);
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
py = screen_hsize(
|
2009-01-12 00:31:46 +01:00
|
|
|
&wp->base) + data->cy - data->oy;
|
|
|
|
px = window_copy_find_length(wp, py);
|
2008-06-24 09:00:39 +02:00
|
|
|
}
|
2008-06-27 19:41:48 +02:00
|
|
|
goto out;
|
2008-06-24 09:00:39 +02:00
|
|
|
}
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-06-24 09:00:39 +02:00
|
|
|
if (skip) {
|
|
|
|
/* Currently skipping non-space (until space). */
|
2009-01-12 00:31:46 +01:00
|
|
|
if (window_copy_is_space(wp, px - 1, py))
|
2008-06-24 09:00:39 +02:00
|
|
|
skip = 0;
|
|
|
|
} else {
|
|
|
|
/* Currently skipping space (until non-space). */
|
2009-01-12 00:31:46 +01:00
|
|
|
if (!window_copy_is_space(wp, px - 1, py))
|
2008-06-24 09:00:39 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-06-24 09:00:39 +02:00
|
|
|
px--;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
|
|
|
|
/* On screen. */
|
2008-09-25 22:08:57 +02:00
|
|
|
if (px > data->ox && px <= data->ox + screen_size_x(s) - 1)
|
2008-06-24 09:00:39 +02:00
|
|
|
data->cx = px - data->ox;
|
|
|
|
|
|
|
|
/* Off right of screen. */
|
2008-09-25 22:08:57 +02:00
|
|
|
if (px > data->ox + screen_size_x(s) - 1) {
|
2008-06-24 09:00:39 +02:00
|
|
|
/* Move cursor to last and scroll screen. */
|
2008-09-25 22:08:57 +02:00
|
|
|
window_copy_scroll_left(
|
2009-01-12 00:31:46 +01:00
|
|
|
wp, px - data->ox - (screen_size_x(s) - 1));
|
2008-09-25 22:08:57 +02:00
|
|
|
data->cx = screen_size_x(s) - 1;
|
2008-06-24 09:00:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Off left of screen. */
|
|
|
|
if (px <= data->ox) {
|
2008-09-25 22:08:57 +02:00
|
|
|
if (px < screen_size_x(s) - 1) {
|
2008-06-24 09:00:39 +02:00
|
|
|
/* Short enough to fit on screen. */
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_scroll_right(wp, data->ox);
|
2008-06-24 09:00:39 +02:00
|
|
|
data->cx = px;
|
|
|
|
} else {
|
|
|
|
/* Too long to fit on screen. */
|
|
|
|
window_copy_scroll_right(
|
2009-01-12 00:31:46 +01:00
|
|
|
wp, data->ox - (px - (screen_size_x(s) - 1)));
|
2008-09-25 22:08:57 +02:00
|
|
|
data->cx = screen_size_x(s) - 1;
|
2008-06-24 09:00:39 +02:00
|
|
|
}
|
|
|
|
}
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
if (window_copy_update_selection(wp))
|
|
|
|
window_copy_redraw_lines(wp, data->cy, 1);
|
2008-06-24 09:00:39 +02:00
|
|
|
else
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_cursor(wp);
|
2008-06-24 09:00:39 +02:00
|
|
|
}
|
|
|
|
|
2007-11-22 19:09:43 +01:00
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_scroll_left(struct window_pane *wp, u_int nx)
|
2007-11-22 19:09:43 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
struct screen_write_ctx ctx;
|
2007-11-27 20:23:34 +01:00
|
|
|
u_int i;
|
2007-11-22 19:09:43 +01:00
|
|
|
|
2007-11-23 17:43:04 +01:00
|
|
|
if (data->ox > SHRT_MAX - nx)
|
2007-11-22 19:09:43 +01:00
|
|
|
nx = SHRT_MAX - data->ox;
|
|
|
|
if (nx == 0)
|
|
|
|
return;
|
|
|
|
data->ox += nx;
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_selection(wp);
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
screen_write_start(&ctx, wp, NULL);
|
2007-12-06 10:46:23 +01:00
|
|
|
for (i = 1; i < screen_size_y(s); i++) {
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(&ctx, 0, i);
|
|
|
|
screen_write_deletecharacter(&ctx, nx);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_write_columns(wp, &ctx, screen_size_x(s) - nx, nx);
|
|
|
|
window_copy_write_line(wp, &ctx, 0);
|
2007-12-06 10:46:23 +01:00
|
|
|
if (s->sel.flag) {
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_selection(wp);
|
|
|
|
window_copy_write_lines(wp, &ctx, data->cy, 1);
|
2007-11-27 20:23:34 +01:00
|
|
|
}
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
2007-12-06 10:46:23 +01:00
|
|
|
screen_write_stop(&ctx);
|
2007-11-22 19:09:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_scroll_right(struct window_pane *wp, u_int nx)
|
2007-11-22 19:09:43 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
struct screen_write_ctx ctx;
|
2007-11-27 20:23:34 +01:00
|
|
|
u_int i;
|
2007-11-22 19:09:43 +01:00
|
|
|
|
|
|
|
if (data->ox < nx)
|
|
|
|
nx = data->ox;
|
|
|
|
if (nx == 0)
|
|
|
|
return;
|
|
|
|
data->ox -= nx;
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_selection(wp);
|
2007-11-22 19:09:43 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
screen_write_start(&ctx, wp, NULL);
|
2007-12-06 10:46:23 +01:00
|
|
|
for (i = 1; i < screen_size_y(s); i++) {
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(&ctx, 0, i);
|
|
|
|
screen_write_insertcharacter(&ctx, nx);
|
2007-11-27 20:23:34 +01:00
|
|
|
}
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_write_columns(wp, &ctx, 0, nx);
|
|
|
|
window_copy_write_line(wp, &ctx, 0);
|
2007-12-06 10:46:23 +01:00
|
|
|
if (s->sel.flag)
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_write_line(wp, &ctx, data->cy);
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
2007-12-06 10:46:23 +01:00
|
|
|
screen_write_stop(&ctx);
|
2007-11-22 19:09:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_scroll_up(struct window_pane *wp, u_int ny)
|
2007-11-22 19:09:43 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
struct screen_write_ctx ctx;
|
2007-11-22 19:09:43 +01:00
|
|
|
|
|
|
|
if (data->oy < ny)
|
|
|
|
ny = data->oy;
|
|
|
|
if (ny == 0)
|
|
|
|
return;
|
|
|
|
data->oy -= ny;
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_selection(wp);
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
screen_write_start(&ctx, wp, NULL);
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(&ctx, 0, 0);
|
|
|
|
screen_write_deleteline(&ctx, ny);
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_write_lines(wp, &ctx, screen_size_y(s) - ny, ny);
|
|
|
|
window_copy_write_line(wp, &ctx, 0);
|
|
|
|
window_copy_write_line(wp, &ctx, 1);
|
2007-12-06 10:46:23 +01:00
|
|
|
if (s->sel.flag && screen_size_y(s) > ny)
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_write_line(wp, &ctx, screen_size_y(s) - ny - 1);
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
2007-12-06 10:46:23 +01:00
|
|
|
screen_write_stop(&ctx);
|
2007-11-22 19:09:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_scroll_down(struct window_pane *wp, u_int ny)
|
2007-11-22 19:09:43 +01:00
|
|
|
{
|
2009-01-12 00:31:46 +01:00
|
|
|
struct window_copy_mode_data *data = wp->modedata;
|
2007-12-06 10:46:23 +01:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
struct screen_write_ctx ctx;
|
2007-11-22 19:09:43 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
if (ny > screen_hsize(&wp->base))
|
2007-11-23 17:43:04 +01:00
|
|
|
return;
|
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
if (data->oy > screen_hsize(&wp->base) - ny)
|
|
|
|
ny = screen_hsize(&wp->base) - data->oy;
|
2007-11-22 19:09:43 +01:00
|
|
|
if (ny == 0)
|
|
|
|
return;
|
|
|
|
data->oy += ny;
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_update_selection(wp);
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
screen_write_start(&ctx, wp, NULL);
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(&ctx, 0, 0);
|
|
|
|
screen_write_insertline(&ctx, ny);
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_write_lines(wp, &ctx, 0, ny);
|
2007-12-06 10:46:23 +01:00
|
|
|
if (s->sel.flag && screen_size_y(s) > ny)
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_write_line(wp, &ctx, ny);
|
2007-12-06 10:46:23 +01:00
|
|
|
else if (ny == 1) /* nuke position */
|
2009-01-12 00:31:46 +01:00
|
|
|
window_copy_write_line(wp, &ctx, 1);
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursormove(&ctx, data->cx, data->cy);
|
2007-12-06 10:46:23 +01:00
|
|
|
screen_write_stop(&ctx);
|
2007-11-22 19:09:43 +01:00
|
|
|
}
|