2008-09-08 17:40:51 +00:00
|
|
|
/* $Id: window-copy.c,v 1.29 2008-09-08 17:40:51 nicm Exp $ */
|
2007-11-22 18:09:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2007-12-06 10:04:43 +00:00
|
|
|
struct screen *window_copy_init(struct window *);
|
2007-12-06 09:46:23 +00:00
|
|
|
void window_copy_free(struct window *);
|
2007-11-22 18:09:43 +00:00
|
|
|
void window_copy_resize(struct window *, u_int, u_int);
|
2008-06-20 17:31:48 +00:00
|
|
|
void window_copy_key(struct window *, struct client *, int);
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
void window_copy_redraw_lines(struct window *, u_int, u_int);
|
|
|
|
void window_copy_redraw_screen(struct window *);
|
|
|
|
void window_copy_write_line(
|
|
|
|
struct window *, struct screen_write_ctx *, u_int);
|
|
|
|
void window_copy_write_lines(
|
|
|
|
struct window *, struct screen_write_ctx *, u_int, u_int);
|
|
|
|
void window_copy_write_column(
|
|
|
|
struct window *, struct screen_write_ctx *, u_int);
|
|
|
|
void window_copy_write_columns(
|
|
|
|
struct window *, struct screen_write_ctx *, u_int, u_int);
|
|
|
|
|
|
|
|
void window_copy_update_cursor(struct window *);
|
|
|
|
void window_copy_start_selection(struct window *);
|
|
|
|
int window_copy_update_selection(struct window *);
|
2008-06-20 17:31:48 +00:00
|
|
|
void window_copy_copy_selection(struct window *, struct client *);
|
2007-11-23 17:52:54 +00:00
|
|
|
void window_copy_copy_line(
|
2008-08-07 20:20:52 +00:00
|
|
|
struct window *, char **, size_t *, u_int, u_int, u_int);
|
2007-11-23 17:52:54 +00:00
|
|
|
u_int window_copy_find_length(struct window *, u_int);
|
2007-12-06 09:46:23 +00:00
|
|
|
void window_copy_cursor_start_of_line(struct window *);
|
|
|
|
void window_copy_cursor_end_of_line(struct window *);
|
2007-11-22 18:09:43 +00:00
|
|
|
void window_copy_cursor_left(struct window *);
|
|
|
|
void window_copy_cursor_right(struct window *);
|
|
|
|
void window_copy_cursor_up(struct window *);
|
|
|
|
void window_copy_cursor_down(struct window *);
|
2008-06-24 07:00:39 +00:00
|
|
|
void window_copy_cursor_next_word(struct window *);
|
|
|
|
void window_copy_cursor_previous_word(struct window *);
|
2007-11-22 18:09:43 +00:00
|
|
|
void window_copy_scroll_left(struct window *, u_int);
|
|
|
|
void window_copy_scroll_right(struct window *, u_int);
|
|
|
|
void window_copy_scroll_up(struct window *, u_int);
|
|
|
|
void window_copy_scroll_down(struct window *, u_int);
|
|
|
|
|
2008-06-24 07:00:39 +00:00
|
|
|
const char *space_characters = " -_@";
|
|
|
|
#define window_copy_is_space(w, x, y) \
|
|
|
|
(strchr(space_characters, (w)->base.grid_data[y][x]) != NULL)
|
|
|
|
|
2007-11-22 18:09:43 +00:00
|
|
|
const struct window_mode window_copy_mode = {
|
|
|
|
window_copy_init,
|
2007-12-06 09:46:23 +00:00
|
|
|
window_copy_free,
|
2007-11-22 18:09:43 +00:00
|
|
|
window_copy_resize,
|
|
|
|
window_copy_key
|
|
|
|
};
|
|
|
|
|
|
|
|
struct window_copy_mode_data {
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen screen;
|
|
|
|
|
2007-11-22 18:09:43 +00:00
|
|
|
u_int ox;
|
|
|
|
u_int oy;
|
2007-11-22 19:17:01 +00:00
|
|
|
|
2007-11-22 19:40:17 +00:00
|
|
|
u_int selx;
|
|
|
|
u_int sely;
|
2008-06-18 22:21:51 +00:00
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
u_int cx;
|
|
|
|
u_int cy;
|
2007-11-22 18:09:43 +00:00
|
|
|
};
|
|
|
|
|
2007-12-06 10:04:43 +00:00
|
|
|
struct screen *
|
2007-11-22 18:09:43 +00:00
|
|
|
window_copy_init(struct window *w)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s;
|
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
u_int i;
|
2007-11-22 18:09:43 +00:00
|
|
|
|
|
|
|
w->modedata = data = xmalloc(sizeof *data);
|
2007-12-06 09:46:23 +00:00
|
|
|
data->ox = 0;
|
|
|
|
data->oy = 0;
|
|
|
|
data->cx = w->base.cx;
|
|
|
|
data->cy = w->base.cy;
|
|
|
|
|
|
|
|
s = &data->screen;
|
2008-06-03 21:42:37 +00:00
|
|
|
screen_create(s, screen_size_x(&w->base), screen_size_y(&w->base), 0);
|
2007-12-06 09:46:23 +00:00
|
|
|
s->cx = data->cx;
|
|
|
|
s->cy = data->cy;
|
|
|
|
|
|
|
|
screen_write_start(&ctx, s, NULL, NULL);
|
|
|
|
for (i = 0; i < screen_size_y(s); i++)
|
|
|
|
window_copy_write_line(w, &ctx, i);
|
|
|
|
screen_write_move_cursor(&ctx, data->cx, data->cy);
|
|
|
|
screen_write_stop(&ctx);
|
2007-12-06 10:04:43 +00:00
|
|
|
|
|
|
|
return (s);
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-12-06 09:46:23 +00:00
|
|
|
window_copy_free(struct window *w)
|
2007-11-22 18:09:43 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
screen_destroy(&data->screen);
|
2007-12-06 10:04:43 +00:00
|
|
|
xfree(data);
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-12-06 09:46:23 +00:00
|
|
|
window_copy_resize(struct window *w, u_int sx, u_int sy)
|
2007-11-22 18:09:43 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s = &data->screen;
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
screen_resize(s, sx, sy);
|
|
|
|
screen_display_copy_area(&data->screen, &w->base,
|
|
|
|
0, 0, screen_size_x(s), screen_size_y(s), data->ox, data->oy);
|
|
|
|
window_copy_update_selection(w);
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-20 17:31:48 +00:00
|
|
|
window_copy_key(struct window *w, struct client *c, int key)
|
2007-11-22 18:09:43 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s = &data->screen;
|
2008-07-02 21:22:57 +00:00
|
|
|
int table;
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2008-07-02 21:22:57 +00:00
|
|
|
table = options_get_number(&c->session->options, "mode-keys");
|
|
|
|
switch (mode_key_lookup(table, key)) {
|
|
|
|
case MODEKEY_QUIT:
|
2007-12-06 10:04:43 +00:00
|
|
|
window_reset_mode(w);
|
2007-12-06 09:46:23 +00:00
|
|
|
break;
|
2008-07-02 21:22:57 +00:00
|
|
|
case MODEKEY_LEFT:
|
2007-11-22 18:09:43 +00:00
|
|
|
window_copy_cursor_left(w);
|
|
|
|
return;
|
2008-07-02 21:22:57 +00:00
|
|
|
case MODEKEY_RIGHT:
|
2007-11-22 18:09:43 +00:00
|
|
|
window_copy_cursor_right(w);
|
|
|
|
return;
|
2008-07-02 21:22:57 +00:00
|
|
|
case MODEKEY_UP:
|
2007-11-22 18:09:43 +00:00
|
|
|
window_copy_cursor_up(w);
|
|
|
|
return;
|
2008-07-02 21:22:57 +00:00
|
|
|
case MODEKEY_DOWN:
|
2007-11-22 18:09:43 +00:00
|
|
|
window_copy_cursor_down(w);
|
|
|
|
return;
|
2008-07-02 21:22:57 +00:00
|
|
|
case MODEKEY_PPAGE:
|
2007-12-06 09:46:23 +00:00
|
|
|
if (data->oy + screen_size_y(s) > w->base.hsize)
|
|
|
|
data->oy = w->base.hsize;
|
2007-11-22 18:09:43 +00:00
|
|
|
else
|
2007-12-06 09:46:23 +00:00
|
|
|
data->oy += screen_size_y(s);
|
|
|
|
window_copy_update_selection(w);
|
|
|
|
window_copy_redraw_screen(w);
|
2007-11-22 18:09:43 +00:00
|
|
|
break;
|
2008-07-02 21:22:57 +00:00
|
|
|
case MODEKEY_NPAGE:
|
2007-12-06 09:46:23 +00:00
|
|
|
if (data->oy < screen_size_y(s))
|
2007-11-22 18:09:43 +00:00
|
|
|
data->oy = 0;
|
|
|
|
else
|
2007-12-06 09:46:23 +00:00
|
|
|
data->oy -= screen_size_y(s);
|
|
|
|
window_copy_update_selection(w);
|
|
|
|
window_copy_redraw_screen(w);
|
2007-11-22 18:09:43 +00:00
|
|
|
break;
|
2008-07-02 21:22:57 +00:00
|
|
|
case MODEKEY_STARTSEL:
|
2007-12-06 09:46:23 +00:00
|
|
|
window_copy_start_selection(w);
|
2007-11-22 19:17:01 +00:00
|
|
|
break;
|
2008-07-02 21:22:57 +00:00
|
|
|
case MODEKEY_CLEARSEL:
|
2007-12-06 09:46:23 +00:00
|
|
|
screen_clear_selection(&data->screen);
|
2008-07-02 21:22:57 +00:00
|
|
|
window_copy_redraw_screen(w);
|
2007-12-06 09:46:23 +00:00
|
|
|
break;
|
2008-07-02 21:22:57 +00:00
|
|
|
case MODEKEY_COPYSEL:
|
2008-06-20 17:31:48 +00:00
|
|
|
if (c != NULL && c->session != NULL) {
|
|
|
|
window_copy_copy_selection(w, c);
|
|
|
|
window_reset_mode(w);
|
|
|
|
}
|
2007-12-06 09:46:23 +00:00
|
|
|
break;
|
2008-07-02 21:22:57 +00:00
|
|
|
case MODEKEY_BOL:
|
2007-12-06 09:46:23 +00:00
|
|
|
window_copy_cursor_start_of_line(w);
|
|
|
|
break;
|
2008-07-02 21:22:57 +00:00
|
|
|
case MODEKEY_EOL:
|
2007-12-06 09:46:23 +00:00
|
|
|
window_copy_cursor_end_of_line(w);
|
|
|
|
break;
|
2008-07-02 21:22:57 +00:00
|
|
|
case MODEKEY_NWORD:
|
2008-06-24 07:00:39 +00:00
|
|
|
window_copy_cursor_next_word(w);
|
|
|
|
break;
|
2008-07-02 21:22:57 +00:00
|
|
|
case MODEKEY_PWORD:
|
2008-06-24 07:00:39 +00:00
|
|
|
window_copy_cursor_previous_word(w);
|
|
|
|
break;
|
2008-07-02 21:22:57 +00:00
|
|
|
default:
|
|
|
|
break;
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
2007-12-06 09:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_write_line(
|
|
|
|
struct window *w, struct screen_write_ctx *ctx, u_int py)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
if (py == 0) {
|
2008-06-03 21:42:37 +00:00
|
|
|
screen_write_set_attributes(
|
2008-09-08 17:40:51 +00:00
|
|
|
ctx, ATTR_BRIGHT|ATTR_REVERSE, 8, 8);
|
2007-12-06 09:46:23 +00:00
|
|
|
screen_write_move_cursor(ctx, 0, 0);
|
|
|
|
size = screen_write_put_string_rjust(
|
|
|
|
ctx, "[%u,%u/%u]", data->ox, data->oy, w->base.hsize);
|
2008-09-08 17:40:51 +00:00
|
|
|
screen_write_set_attributes(ctx, 0, 8, 8);
|
2007-12-06 09:46:23 +00:00
|
|
|
} else
|
|
|
|
size = 0;
|
|
|
|
screen_write_move_cursor(ctx, 0, py);
|
|
|
|
screen_write_copy_area(
|
|
|
|
ctx, &w->base, screen_size_x(s) - size, 1, data->ox, data->oy);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_write_lines(
|
|
|
|
struct window *w, struct screen_write_ctx *ctx, u_int py, u_int ny)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
|
|
|
|
if (py == 0) {
|
|
|
|
window_copy_write_line(w, ctx, 0);
|
|
|
|
if (ny == 1)
|
|
|
|
return;
|
|
|
|
py++;
|
|
|
|
ny--;
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
2007-12-06 09:46:23 +00:00
|
|
|
screen_write_move_cursor(ctx, 0, py);
|
|
|
|
screen_write_copy_area(
|
|
|
|
ctx, &w->base, screen_size_x(s), ny, data->ox, data->oy);
|
|
|
|
}
|
2007-11-23 17:52:54 +00:00
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
void
|
|
|
|
window_copy_write_column(
|
|
|
|
struct window *w, struct screen_write_ctx *ctx, u_int px)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
|
|
|
|
screen_write_move_cursor(ctx, px, 0);
|
|
|
|
screen_write_copy_area(
|
|
|
|
ctx, &w->base, 1, screen_size_y(s), data->ox, data->oy);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_write_columns(
|
|
|
|
struct window *w, struct screen_write_ctx *ctx, u_int px, u_int nx)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
|
|
|
|
screen_write_move_cursor(ctx, px, 0);
|
|
|
|
screen_write_copy_area(
|
|
|
|
ctx, &w->base, nx, screen_size_y(s), data->ox, data->oy);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_redraw_lines(struct window *w, u_int py, u_int ny)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
screen_write_start_window(&ctx, w);
|
|
|
|
for (i = py; i < py + ny; i++)
|
|
|
|
window_copy_write_line(w, &ctx, i);
|
|
|
|
screen_write_move_cursor(&ctx, data->cx, data->cy);
|
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_redraw_screen(struct window *w)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
|
|
|
|
|
|
|
window_copy_redraw_lines(w, 0, screen_size_x(&data->screen));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_update_cursor(struct window *w)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
|
|
|
struct screen_write_ctx ctx;
|
|
|
|
|
|
|
|
screen_write_start_window(&ctx, w);
|
|
|
|
screen_write_move_cursor(&ctx, data->cx, data->cy);
|
|
|
|
screen_write_stop(&ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_start_selection(struct window *w)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
|
|
|
|
data->selx = screen_x(&w->base, data->cx) + data->ox;
|
|
|
|
data->sely = screen_y(&w->base, data->cy) - data->oy;
|
|
|
|
|
|
|
|
s->sel.flag = 1;
|
|
|
|
window_copy_update_selection(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
window_copy_update_selection(struct window *w)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
u_int sx, sy, tx, ty;
|
|
|
|
|
|
|
|
if (!s->sel.flag)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* Find top-left of screen. */
|
|
|
|
tx = screen_x(&w->base, 0) + data->ox;
|
|
|
|
ty = screen_y(&w->base, 0) - data->oy;
|
|
|
|
|
|
|
|
/* Adjust the selection. */
|
|
|
|
sx = data->selx;
|
|
|
|
sy = data->sely;
|
|
|
|
if (sy < ty) {
|
|
|
|
/* Above it. */
|
|
|
|
sx = 0;
|
|
|
|
sy = 0;
|
|
|
|
} else if (sy > ty + screen_last_y(s)) {
|
|
|
|
/* Below it. */
|
|
|
|
sx = screen_last_x(s);
|
|
|
|
sy = screen_last_y(s);
|
|
|
|
} else if (sx < tx) {
|
|
|
|
/* To the left. */
|
|
|
|
sx = 0;
|
|
|
|
} else if (sx > tx + screen_last_x(s)) {
|
|
|
|
/* To the right. */
|
|
|
|
sx = 0;
|
|
|
|
sy++;
|
|
|
|
if (sy > screen_last_y(s))
|
|
|
|
sy = screen_last_y(s);
|
|
|
|
} else {
|
|
|
|
sx -= tx;
|
|
|
|
sy -= ty;
|
|
|
|
}
|
|
|
|
sx = screen_x(s, sx);
|
|
|
|
sy = screen_x(s, sy);
|
|
|
|
|
|
|
|
screen_set_selection(
|
|
|
|
s, sx, sy, screen_x(s, data->cx), screen_y(s, data->cy));
|
|
|
|
return (1);
|
2007-11-23 17:52:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-20 17:31:48 +00:00
|
|
|
window_copy_copy_selection(struct window *w, struct client *c)
|
2007-11-23 17:52:54 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
2007-12-07 09:49:18 +00:00
|
|
|
struct screen *s = &data->screen;
|
2007-11-23 17:52:54 +00:00
|
|
|
char *buf;
|
2008-08-07 20:20:52 +00:00
|
|
|
size_t off;
|
2008-06-20 18:45:35 +00:00
|
|
|
u_int i, xx, yy, sx, sy, ex, ey, limit;
|
2007-11-23 17:52:54 +00:00
|
|
|
|
2007-12-07 09:49:18 +00:00
|
|
|
if (!s->sel.flag)
|
|
|
|
return;
|
|
|
|
|
2008-08-07 20:20:52 +00:00
|
|
|
buf = xmalloc(1);
|
2007-11-23 17:52:54 +00:00
|
|
|
off = 0;
|
|
|
|
|
|
|
|
*buf = '\0';
|
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
/*
|
|
|
|
* The selection extends from selx,sely to (adjusted) cx,cy on
|
|
|
|
* the base screen.
|
|
|
|
*/
|
|
|
|
|
2007-11-23 17:52:54 +00:00
|
|
|
/* Find start and end. */
|
2007-12-06 09:46:23 +00:00
|
|
|
xx = screen_x(&w->base, data->cx) + data->ox;
|
|
|
|
yy = screen_y(&w->base, data->cy) - data->oy;
|
2007-11-23 17:52:54 +00: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. */
|
|
|
|
xx = window_copy_find_length(w, ey);
|
|
|
|
if (ex > xx)
|
|
|
|
ex = xx;
|
|
|
|
|
|
|
|
/* Copy the lines. */
|
|
|
|
if (sy == ey)
|
2008-08-07 20:20:52 +00:00
|
|
|
window_copy_copy_line(w, &buf, &off, sy, sx, ex);
|
2007-11-23 17:52:54 +00:00
|
|
|
else {
|
|
|
|
xx = window_copy_find_length(w, sy);
|
2008-08-07 20:20:52 +00:00
|
|
|
window_copy_copy_line(w, &buf, &off, sy, sx, xx);
|
2007-11-23 17:52:54 +00:00
|
|
|
if (ey - sy > 1) {
|
|
|
|
for (i = sy + 1; i < ey - 1; i++) {
|
|
|
|
xx = window_copy_find_length(w, i);
|
2008-08-07 20:20:52 +00:00
|
|
|
window_copy_copy_line(w, &buf, &off, i, 0, xx);
|
2007-11-23 17:52:54 +00:00
|
|
|
}
|
|
|
|
}
|
2008-08-07 20:20:52 +00:00
|
|
|
window_copy_copy_line(w, &buf, &off, ey, 0, ex);
|
2007-11-23 17:52:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Terminate buffer, overwriting final \n. */
|
|
|
|
if (off != 0)
|
|
|
|
buf[off - 1] = '\0';
|
|
|
|
|
2008-06-20 17:31:48 +00:00
|
|
|
/* Add the buffer to the stack. */
|
2008-06-20 18:45:35 +00:00
|
|
|
limit = options_get_number(&c->session->options, "buffer-limit");
|
|
|
|
paste_add(&c->session->buffers, buf, limit);
|
2008-06-20 17:31:48 +00:00
|
|
|
xfree(buf);
|
2007-11-23 17:52:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-08-07 20:20:52 +00:00
|
|
|
window_copy_copy_line(
|
|
|
|
struct window *w, char **buf, size_t *off, u_int sy, u_int sx, u_int ex)
|
2007-11-23 17:52:54 +00:00
|
|
|
{
|
2007-12-06 09:46:23 +00:00
|
|
|
u_char i, xx;
|
2007-11-23 17:52:54 +00:00
|
|
|
|
|
|
|
if (sx > ex)
|
|
|
|
return;
|
|
|
|
|
|
|
|
xx = window_copy_find_length(w, sy);
|
|
|
|
if (ex > xx)
|
|
|
|
ex = xx;
|
|
|
|
if (sx > xx)
|
|
|
|
sx = xx;
|
|
|
|
|
|
|
|
if (sx < ex) {
|
|
|
|
for (i = sx; i < ex; i++) {
|
2008-08-07 20:20:52 +00:00
|
|
|
*buf = xrealloc(*buf, 1, (*off) + 1);
|
2007-12-06 09:46:23 +00:00
|
|
|
(*buf)[*off] = w->base.grid_data[sy][i];
|
2007-11-23 17:52:54 +00:00
|
|
|
(*off)++;
|
|
|
|
}
|
|
|
|
}
|
2007-12-06 09:46:23 +00:00
|
|
|
|
2008-08-07 20:20:52 +00:00
|
|
|
*buf = xrealloc(*buf, 1, (*off) + 1);
|
2007-11-23 17:52:54 +00:00
|
|
|
(*buf)[*off] = '\n';
|
|
|
|
(*off)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
u_int
|
|
|
|
window_copy_find_length(struct window *w, u_int py)
|
|
|
|
{
|
2007-12-06 09:46:23 +00:00
|
|
|
u_int px;
|
2007-11-23 17:52:54 +00:00
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
px = w->base.grid_size[py];
|
2008-07-24 21:42:40 +00:00
|
|
|
while (px > 0 && w->base.grid_data[py][px - 1] == ' ')
|
2007-11-23 17:52:54 +00:00
|
|
|
px--;
|
|
|
|
return (px);
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-12-06 09:46:23 +00:00
|
|
|
window_copy_cursor_start_of_line(struct window *w)
|
2007-11-26 20:36:30 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
|
|
|
|
|
|
|
if (data->ox != 0)
|
|
|
|
window_copy_scroll_right(w, data->ox);
|
|
|
|
data->cx = 0;
|
2007-11-26 20:45:13 +00:00
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
if (window_copy_update_selection(w))
|
|
|
|
window_copy_redraw_lines(w, data->cy, 1);
|
|
|
|
else
|
|
|
|
window_copy_update_cursor(w);
|
2007-11-26 20:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-12-06 09:46:23 +00:00
|
|
|
window_copy_cursor_end_of_line(struct window *w)
|
2007-11-26 20:36:30 +00:00
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
u_int px, py;
|
2007-11-26 20:36:30 +00:00
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
py = screen_y(&w->base, data->cy) - data->oy;
|
|
|
|
px = window_copy_find_length(w, py);
|
2007-11-26 20:36:30 +00:00
|
|
|
|
|
|
|
/* On screen. */
|
2007-12-07 09:49:18 +00:00
|
|
|
if (px > data->ox && px <= data->ox + screen_last_x(s))
|
2007-12-06 09:46:23 +00:00
|
|
|
data->cx = px - data->ox;
|
2007-11-26 20:36:30 +00:00
|
|
|
|
|
|
|
/* Off right of screen. */
|
2007-12-06 09:46:23 +00:00
|
|
|
if (px > data->ox + screen_last_x(s)) {
|
2007-11-26 20:36:30 +00:00
|
|
|
/* Move cursor to last and scroll screen. */
|
|
|
|
window_copy_scroll_left(w,
|
2007-12-06 09:46:23 +00:00
|
|
|
px - data->ox - screen_last_x(s));
|
2007-11-26 20:36:30 +00:00
|
|
|
data->cx = screen_last_x(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Off left of screen. */
|
2007-12-06 09:46:23 +00:00
|
|
|
if (px <= data->ox) {
|
|
|
|
if (px < screen_last_x(s)) {
|
2007-11-26 20:36:30 +00:00
|
|
|
/* Short enough to fit on screen. */
|
|
|
|
window_copy_scroll_right(w, data->ox);
|
2007-12-06 09:46:23 +00:00
|
|
|
data->cx = px;
|
2007-11-26 20:36:30 +00:00
|
|
|
} else {
|
|
|
|
/* Too long to fit on screen. */
|
|
|
|
window_copy_scroll_right(
|
2007-12-06 09:46:23 +00:00
|
|
|
w, data->ox - (px - screen_last_x(s)));
|
2007-11-26 20:36:30 +00:00
|
|
|
data->cx = screen_last_x(s);
|
|
|
|
}
|
2008-06-24 07:00:39 +00:00
|
|
|
}
|
2007-11-26 20:36:30 +00:00
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
if (window_copy_update_selection(w))
|
|
|
|
window_copy_redraw_lines(w, data->cy, 1);
|
|
|
|
else
|
|
|
|
window_copy_update_cursor(w);
|
2007-11-26 20:36:30 +00:00
|
|
|
}
|
|
|
|
|
2007-11-22 18:09:43 +00:00
|
|
|
void
|
|
|
|
window_copy_cursor_left(struct window *w)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
if (data->cx == 0) {
|
|
|
|
if (data->ox > 0)
|
|
|
|
window_copy_scroll_right(w, 1);
|
|
|
|
else {
|
|
|
|
window_copy_cursor_up(w);
|
|
|
|
window_copy_cursor_end_of_line(w);
|
|
|
|
}
|
|
|
|
} else {
|
2007-11-22 18:09:43 +00:00
|
|
|
data->cx--;
|
2007-12-06 09:46:23 +00:00
|
|
|
if (window_copy_update_selection(w))
|
|
|
|
window_copy_redraw_lines(w, data->cy, 1);
|
|
|
|
else
|
|
|
|
window_copy_update_cursor(w);
|
2007-11-22 19:17:01 +00:00
|
|
|
}
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_cursor_right(struct window *w)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
u_int px, py;
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
py = screen_y(&w->base, data->cy) - data->oy;
|
|
|
|
px = window_copy_find_length(w, py);
|
|
|
|
|
|
|
|
if (data->cx >= px) {
|
|
|
|
window_copy_cursor_start_of_line(w);
|
|
|
|
window_copy_cursor_down(w);
|
|
|
|
} else {
|
2007-11-22 18:09:43 +00:00
|
|
|
data->cx++;
|
2007-12-06 09:46:23 +00:00
|
|
|
if (window_copy_update_selection(w))
|
|
|
|
window_copy_redraw_lines(w, data->cy, 1);
|
|
|
|
else
|
|
|
|
window_copy_update_cursor(w);
|
2007-11-22 19:17:01 +00:00
|
|
|
}
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_cursor_up(struct window *w)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
u_int ox, oy, px, py;
|
|
|
|
|
|
|
|
oy = screen_y(&w->base, data->cy) - data->oy;
|
|
|
|
ox = window_copy_find_length(w, oy);
|
2007-11-22 18:09:43 +00:00
|
|
|
|
|
|
|
if (data->cy == 0)
|
|
|
|
window_copy_scroll_down(w, 1);
|
2007-11-22 19:17:01 +00:00
|
|
|
else {
|
2007-11-22 18:09:43 +00:00
|
|
|
data->cy--;
|
2007-12-06 09:46:23 +00:00
|
|
|
if (window_copy_update_selection(w))
|
|
|
|
window_copy_redraw_lines(w, data->cy, 2);
|
|
|
|
else
|
|
|
|
window_copy_update_cursor(w);
|
2007-11-22 19:17:01 +00:00
|
|
|
}
|
2007-12-06 09:46:23 +00:00
|
|
|
|
|
|
|
py = screen_y(&w->base, data->cy) - data->oy;
|
|
|
|
px = window_copy_find_length(w, py);
|
|
|
|
|
2007-12-07 09:49:18 +00:00
|
|
|
if (data->cx + data->ox >= px || data->cx + data->ox >= ox)
|
2007-12-06 09:46:23 +00:00
|
|
|
window_copy_cursor_end_of_line(w);
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_cursor_down(struct window *w)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
u_int ox, oy, px, py;
|
|
|
|
|
|
|
|
oy = screen_y(&w->base, data->cy) - data->oy;
|
|
|
|
ox = window_copy_find_length(w, oy);
|
2007-11-22 18:09:43 +00:00
|
|
|
|
|
|
|
if (data->cy == screen_last_y(s))
|
|
|
|
window_copy_scroll_up(w, 1);
|
2007-11-22 19:17:01 +00:00
|
|
|
else {
|
2007-11-22 18:09:43 +00:00
|
|
|
data->cy++;
|
2007-12-06 09:46:23 +00:00
|
|
|
if (window_copy_update_selection(w))
|
|
|
|
window_copy_redraw_lines(w, data->cy - 1, 2);
|
|
|
|
else
|
|
|
|
window_copy_update_cursor(w);
|
2007-11-22 19:17:01 +00:00
|
|
|
}
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
py = screen_y(&w->base, data->cy) - data->oy;
|
|
|
|
px = window_copy_find_length(w, py);
|
2007-11-22 19:17:01 +00:00
|
|
|
|
2007-12-07 09:49:18 +00:00
|
|
|
if (data->cx + data->ox >= px || data->cx + data->ox >= ox)
|
2007-12-06 09:46:23 +00:00
|
|
|
window_copy_cursor_end_of_line(w);
|
2007-11-22 19:17:01 +00:00
|
|
|
}
|
|
|
|
|
2008-06-24 07:00:39 +00:00
|
|
|
void
|
|
|
|
window_copy_cursor_next_word(struct window *w)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
|
|
|
u_int px, py, xx, skip;
|
|
|
|
|
|
|
|
px = data->ox + data->cx;
|
|
|
|
py = screen_y(&w->base, data->cy) - data->oy;
|
|
|
|
xx = window_copy_find_length(w, py);
|
|
|
|
|
|
|
|
skip = 1;
|
|
|
|
if (px < xx) {
|
|
|
|
/* If currently on a space, skip space. */
|
|
|
|
if (window_copy_is_space(w, px, py))
|
|
|
|
skip = 0;
|
|
|
|
} else
|
|
|
|
skip = 0;
|
|
|
|
for (;;) {
|
|
|
|
if (px >= xx) {
|
|
|
|
if (skip) {
|
|
|
|
px = xx;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (px >= xx) {
|
|
|
|
if (data->cy == screen_last_y(s)) {
|
|
|
|
if (data->oy == 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
px = 0;
|
|
|
|
window_copy_cursor_down(w);
|
|
|
|
|
|
|
|
py = screen_y(&w->base, data->cy) - data->oy;
|
|
|
|
xx = window_copy_find_length(w, py);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skip) {
|
|
|
|
/* Currently skipping non-space (until space). */
|
|
|
|
if (window_copy_is_space(w, px, py))
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
/* Currently skipping space (until non-space). */
|
|
|
|
if (!window_copy_is_space(w, px, py))
|
|
|
|
skip = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
px++;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
|
|
|
|
/* On screen. */
|
|
|
|
if (px > data->ox && px <= data->ox + screen_last_x(s))
|
|
|
|
data->cx = px - data->ox;
|
|
|
|
|
|
|
|
/* Off right of screen. */
|
|
|
|
if (px > data->ox + screen_last_x(s)) {
|
|
|
|
/* Move cursor to last and scroll screen. */
|
|
|
|
window_copy_scroll_left(w,
|
|
|
|
px - data->ox - screen_last_x(s));
|
|
|
|
data->cx = screen_last_x(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Off left of screen. */
|
|
|
|
if (px <= data->ox) {
|
|
|
|
if (px < screen_last_x(s)) {
|
|
|
|
/* Short enough to fit on screen. */
|
|
|
|
window_copy_scroll_right(w, data->ox);
|
|
|
|
data->cx = px;
|
|
|
|
} else {
|
|
|
|
/* Too long to fit on screen. */
|
|
|
|
window_copy_scroll_right(
|
|
|
|
w, data->ox - (px - screen_last_x(s)));
|
|
|
|
data->cx = screen_last_x(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window_copy_update_selection(w))
|
|
|
|
window_copy_redraw_lines(w, data->cy, 1);
|
|
|
|
else
|
|
|
|
window_copy_update_cursor(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_cursor_previous_word(struct window *w)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
|
|
|
struct screen *s = &data->screen;
|
2008-06-27 17:41:48 +00:00
|
|
|
u_int ox, px, py, skip;
|
2008-06-24 07:00:39 +00:00
|
|
|
|
2008-06-27 17:41:48 +00:00
|
|
|
ox = px = data->ox + data->cx;
|
2008-06-24 07:00:39 +00:00
|
|
|
py = screen_y(&w->base, data->cy) - data->oy;
|
|
|
|
|
|
|
|
skip = 1;
|
|
|
|
if (px != 0) {
|
|
|
|
/* If currently on a space, skip space. */
|
|
|
|
if (window_copy_is_space(w, px - 1, py))
|
|
|
|
skip = 0;
|
|
|
|
}
|
|
|
|
for (;;) {
|
2008-06-27 17:41:48 +00:00
|
|
|
if (px == 0) {
|
|
|
|
if (ox != 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
while (px == 0) {
|
|
|
|
if (data->cy == 0 && (w->base.hsize == 0 ||
|
|
|
|
data->oy >= w->base.hsize - 1))
|
2008-06-24 07:00:39 +00:00
|
|
|
goto out;
|
2008-06-27 17:41:48 +00:00
|
|
|
|
|
|
|
window_copy_cursor_up(w);
|
|
|
|
|
|
|
|
py = screen_y(&w->base, data->cy) - data->oy;
|
|
|
|
px = window_copy_find_length(w, py);
|
2008-06-24 07:00:39 +00:00
|
|
|
}
|
2008-06-27 17:41:48 +00:00
|
|
|
goto out;
|
2008-06-24 07:00:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (skip) {
|
|
|
|
/* Currently skipping non-space (until space). */
|
|
|
|
if (window_copy_is_space(w, px - 1, py))
|
|
|
|
skip = 0;
|
|
|
|
} else {
|
|
|
|
/* Currently skipping space (until non-space). */
|
|
|
|
if (!window_copy_is_space(w, px - 1, py))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
px--;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
|
|
|
|
/* On screen. */
|
|
|
|
if (px > data->ox && px <= data->ox + screen_last_x(s))
|
|
|
|
data->cx = px - data->ox;
|
|
|
|
|
|
|
|
/* Off right of screen. */
|
|
|
|
if (px > data->ox + screen_last_x(s)) {
|
|
|
|
/* Move cursor to last and scroll screen. */
|
|
|
|
window_copy_scroll_left(w,
|
|
|
|
px - data->ox - screen_last_x(s));
|
|
|
|
data->cx = screen_last_x(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Off left of screen. */
|
|
|
|
if (px <= data->ox) {
|
|
|
|
if (px < screen_last_x(s)) {
|
|
|
|
/* Short enough to fit on screen. */
|
|
|
|
window_copy_scroll_right(w, data->ox);
|
|
|
|
data->cx = px;
|
|
|
|
} else {
|
|
|
|
/* Too long to fit on screen. */
|
|
|
|
window_copy_scroll_right(
|
|
|
|
w, data->ox - (px - screen_last_x(s)));
|
|
|
|
data->cx = screen_last_x(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window_copy_update_selection(w))
|
|
|
|
window_copy_redraw_lines(w, data->cy, 1);
|
|
|
|
else
|
|
|
|
window_copy_update_cursor(w);
|
|
|
|
}
|
|
|
|
|
2007-11-22 18:09:43 +00:00
|
|
|
void
|
|
|
|
window_copy_scroll_left(struct window *w, u_int nx)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
struct screen_write_ctx ctx;
|
2007-11-27 19:23:34 +00:00
|
|
|
u_int i;
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2007-11-23 16:43:04 +00:00
|
|
|
if (data->ox > SHRT_MAX - nx)
|
2007-11-22 18:09:43 +00:00
|
|
|
nx = SHRT_MAX - data->ox;
|
|
|
|
if (nx == 0)
|
|
|
|
return;
|
|
|
|
data->ox += nx;
|
2007-12-06 09:46:23 +00:00
|
|
|
window_copy_update_selection(w);
|
|
|
|
|
|
|
|
screen_write_start_window(&ctx, w);
|
|
|
|
for (i = 1; i < screen_size_y(s); i++) {
|
|
|
|
screen_write_move_cursor(&ctx, 0, i);
|
|
|
|
screen_write_delete_characters(&ctx, nx);
|
|
|
|
}
|
|
|
|
window_copy_write_columns(w, &ctx, screen_size_x(s) - nx, nx);
|
|
|
|
window_copy_write_line(w, &ctx, 0);
|
|
|
|
if (s->sel.flag) {
|
|
|
|
window_copy_update_selection(w);
|
|
|
|
window_copy_write_lines(w, &ctx, data->cy, 1);
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
2007-12-06 09:46:23 +00:00
|
|
|
screen_write_move_cursor(&ctx, data->cx, data->cy);
|
|
|
|
screen_write_stop(&ctx);
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_scroll_right(struct window *w, u_int nx)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
struct screen_write_ctx ctx;
|
2007-11-27 19:23:34 +00:00
|
|
|
u_int i;
|
2007-11-22 18:09:43 +00:00
|
|
|
|
|
|
|
if (data->ox < nx)
|
|
|
|
nx = data->ox;
|
|
|
|
if (nx == 0)
|
|
|
|
return;
|
|
|
|
data->ox -= nx;
|
2007-12-06 09:46:23 +00:00
|
|
|
window_copy_update_selection(w);
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
screen_write_start_window(&ctx, w);
|
|
|
|
for (i = 1; i < screen_size_y(s); i++) {
|
|
|
|
screen_write_move_cursor(&ctx, 0, i);
|
|
|
|
screen_write_insert_characters(&ctx, nx);
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
2007-12-06 09:46:23 +00:00
|
|
|
window_copy_write_columns(w, &ctx, 0, nx);
|
|
|
|
window_copy_write_line(w, &ctx, 0);
|
|
|
|
if (s->sel.flag)
|
|
|
|
window_copy_write_lines(w, &ctx, data->cy, 1);
|
|
|
|
screen_write_move_cursor(&ctx, data->cx, data->cy);
|
|
|
|
screen_write_stop(&ctx);
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_scroll_up(struct window *w, u_int ny)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
struct screen_write_ctx ctx;
|
2007-11-22 18:09:43 +00:00
|
|
|
|
|
|
|
if (data->oy < ny)
|
|
|
|
ny = data->oy;
|
|
|
|
if (ny == 0)
|
|
|
|
return;
|
|
|
|
data->oy -= ny;
|
2007-12-06 09:46:23 +00:00
|
|
|
window_copy_update_selection(w);
|
|
|
|
|
|
|
|
screen_write_start_window(&ctx, w);
|
|
|
|
screen_write_move_cursor(&ctx, 0, 0);
|
|
|
|
screen_write_delete_lines(&ctx, ny);
|
|
|
|
window_copy_write_lines(w, &ctx, screen_size_y(s) - ny, ny);
|
|
|
|
window_copy_write_line(w, &ctx, 0);
|
|
|
|
if (s->sel.flag && screen_size_y(s) > ny)
|
|
|
|
window_copy_write_lines(w, &ctx, screen_size_y(s) - ny - 1, 1);
|
|
|
|
screen_write_move_cursor(&ctx, data->cx, data->cy);
|
|
|
|
screen_write_stop(&ctx);
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_copy_scroll_down(struct window *w, u_int ny)
|
|
|
|
{
|
|
|
|
struct window_copy_mode_data *data = w->modedata;
|
2007-12-06 09:46:23 +00:00
|
|
|
struct screen *s = &data->screen;
|
|
|
|
struct screen_write_ctx ctx;
|
2007-11-22 18:09:43 +00:00
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
if (ny > w->base.hsize)
|
2007-11-23 16:43:04 +00:00
|
|
|
return;
|
|
|
|
|
2007-12-06 09:46:23 +00:00
|
|
|
if (data->oy > w->base.hsize - ny)
|
|
|
|
ny = w->base.hsize - data->oy;
|
2007-11-22 18:09:43 +00:00
|
|
|
if (ny == 0)
|
|
|
|
return;
|
|
|
|
data->oy += ny;
|
2007-12-06 09:46:23 +00:00
|
|
|
window_copy_update_selection(w);
|
|
|
|
|
|
|
|
screen_write_start_window(&ctx, w);
|
|
|
|
screen_write_move_cursor(&ctx, 0, 0);
|
|
|
|
screen_write_insert_lines(&ctx, ny);
|
|
|
|
window_copy_write_lines(w, &ctx, 0, ny);
|
|
|
|
if (s->sel.flag && screen_size_y(s) > ny)
|
|
|
|
window_copy_write_lines(w, &ctx, ny, 1);
|
|
|
|
else if (ny == 1) /* nuke position */
|
|
|
|
window_copy_write_line(w, &ctx, 1);
|
|
|
|
screen_write_move_cursor(&ctx, data->cx, data->cy);
|
|
|
|
screen_write_stop(&ctx);
|
2007-11-22 18:09:43 +00:00
|
|
|
}
|