/* $Id: window-copy.c,v 1.25 2008-06-27 17:41:48 nicm Exp $ */
/*
* 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 *);
void window_copy_free(struct window *);
void window_copy_resize(struct window *, u_int, u_int);
void window_copy_key(struct window *, struct client *, int);
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 *);
void window_copy_copy_selection(struct window *, struct client *);
void window_copy_copy_line(
struct window *, char **, size_t *, size_t *, u_int, u_int, u_int);
u_int window_copy_find_length(struct window *, u_int);
void window_copy_cursor_start_of_line(struct window *);
void window_copy_cursor_end_of_line(struct window *);
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 *);
void window_copy_cursor_next_word(struct window *);
void window_copy_cursor_previous_word(struct window *);
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);
const char *space_characters = " -_@";
#define window_copy_is_space(w, x, y) \
(strchr(space_characters, (w)->base.grid_data[y][x]) != NULL)
const struct window_mode window_copy_mode = {
window_copy_init,
window_copy_free,
window_copy_resize,
window_copy_key
};
struct window_copy_mode_data {
struct screen screen;
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 *w)
{
struct window_copy_mode_data *data;
struct screen *s;
struct screen_write_ctx ctx;
u_int i;
w->modedata = data = xmalloc(sizeof *data);
data->ox = 0;
data->oy = 0;
data->cx = w->base.cx;
data->cy = w->base.cy;
s = &data->screen;
screen_create(s, screen_size_x(&w->base), screen_size_y(&w->base), 0);
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);
return (s);
}
void
window_copy_free(struct window *w)
{
struct window_copy_mode_data *data = w->modedata;
screen_destroy(&data->screen);
xfree(data);
}
void
window_copy_resize(struct window *w, u_int sx, u_int sy)
{
struct window_copy_mode_data *data = w->modedata;
struct screen *s = &data->screen;
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);
}
void
window_copy_key(struct window *w, struct client *c, int key)
{
struct window_copy_mode_data *data = w->modedata;
struct screen *s = &data->screen;
switch (key) {
case