/* $OpenBSD$ */
/*
* 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"
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);
void window_copy_mouse(
struct window_pane *, struct client *, u_char, u_char, u_char);
void window_copy_redraw_lines(struct window_pane *, u_int, u_int);
void window_copy_redraw_screen(struct window_pane *);
void window_copy_write_line(
struct window_pane *, struct screen_write_ctx *, u_int);
void window_copy_write_lines(
struct window_pane *, struct screen_write_ctx *, u_int, u_int);
void window_copy_write_column(
struct window_pane *, struct screen_write_ctx *, u_int);
void window_copy_write_columns(
struct window_pane *, struct screen_write_ctx *, u_int, u_int);
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 *);
void window_copy_copy_line(
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_set_cursor_x(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);
const struct window_mode window_copy_mode = {
window_copy_init,
window_copy_free,
window_copy_resize,
window_copy_key,
window_copy_mouse,
NULL,
};
struct window_copy_mode_data {
struct screen screen;
struct mode_key_data mdata;
u_int ox;
u_int oy;
u_int selx;
u_int sely;
u_int cx;
u_int cy;
};
struct screen *
window_copy_init(struct window_pane *wp)
{
struct window_copy_mode_data *data;
struct screen *s;
struct screen_write_ctx ctx;
u_int i;
wp->modedata = data = xmalloc(sizeof *data);
data->ox = 0;
data->oy = 0;
data->cx = wp->base.cx;
data->cy = wp->base.cy;
s = &data->screen;
screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
s->mode |= MODE_MOUSE;
mode_key_init(&data->mdata,
options_get_number(&wp->window->options, "mode-keys"), 0);
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);
return (s);
}
void
window_copy_free(struct window_pane *wp)
{
struct window_copy_mode_data *data = wp->modedata;
mode_key_free(&data->mdata);
screen_free(&data->screen);
xfree(data);
}
void
window_copy_pageup(struct window_pane *wp)
{
struct window_copy_mode_data *data = wp->modedata;
struct screen *s = &data->screen