2011-07-09 11:42:33 +02:00
|
|
|
/* $Id$ */
|
2008-09-25 22:08:57 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2008 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"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grid view functions. These work using coordinates relative to the visible
|
|
|
|
* screen area.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define grid_view_x(gd, x) (x)
|
|
|
|
#define grid_view_y(gd, y) ((gd)->hsize + (y))
|
|
|
|
|
|
|
|
/* Get cell for reading. */
|
|
|
|
const struct grid_cell *
|
2009-03-28 16:43:41 +01:00
|
|
|
grid_view_peek_cell(struct grid *gd, u_int px, u_int py)
|
2008-09-25 22:08:57 +02:00
|
|
|
{
|
|
|
|
return (grid_peek_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get cell for writing. */
|
|
|
|
struct grid_cell *
|
2009-03-28 16:43:41 +01:00
|
|
|
grid_view_get_cell(struct grid *gd, u_int px, u_int py)
|
2008-09-25 22:08:57 +02:00
|
|
|
{
|
|
|
|
return (grid_get_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set cell. */
|
|
|
|
void
|
|
|
|
grid_view_set_cell(
|
2009-03-28 16:43:41 +01:00
|
|
|
struct grid *gd, u_int px, u_int py, const struct grid_cell *gc)
|
2008-09-25 22:08:57 +02:00
|
|
|
{
|
|
|
|
grid_set_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py), gc);
|
|
|
|
}
|
|
|
|
|
2011-02-15 16:10:47 +01:00
|
|
|
/* Clear into history. */
|
|
|
|
void
|
|
|
|
grid_view_clear_history(struct grid *gd)
|
|
|
|
{
|
|
|
|
struct grid_line *gl;
|
|
|
|
u_int yy, last;
|
|
|
|
|
|
|
|
GRID_DEBUG(gd, "");
|
|
|
|
|
|
|
|
/* Find the last used line. */
|
|
|
|
last = 0;
|
|
|
|
for (yy = 0; yy < gd->sy; yy++) {
|
|
|
|
gl = &gd->linedata[grid_view_y(gd, yy)];
|
2013-01-18 03:16:21 +01:00
|
|
|
if (gl->cellsize != 0)
|
2011-02-15 16:10:47 +01:00
|
|
|
last = yy + 1;
|
|
|
|
}
|
|
|
|
if (last == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Scroll the lines into the history. */
|
2012-01-31 12:58:55 +01:00
|
|
|
for (yy = 0; yy < last; yy++) {
|
|
|
|
grid_collect_history(gd);
|
2011-02-15 16:10:47 +01:00
|
|
|
grid_scroll_history(gd);
|
2012-01-31 12:58:55 +01:00
|
|
|
}
|
2011-02-15 16:10:47 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Clear area. */
|
|
|
|
void
|
2009-03-28 16:43:41 +01:00
|
|
|
grid_view_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny)
|
2008-09-25 22:08:57 +02:00
|
|
|
{
|
|
|
|
GRID_DEBUG(gd, "px=%u, py=%u, nx=%u, ny=%u", px, py, nx, ny);
|
|
|
|
|
|
|
|
px = grid_view_x(gd, px);
|
|
|
|
py = grid_view_y(gd, py);
|
|
|
|
|
|
|
|
grid_clear(gd, px, py, nx, ny);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scroll region up. */
|
|
|
|
void
|
2009-03-28 16:43:41 +01:00
|
|
|
grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower)
|
2008-09-25 22:08:57 +02:00
|
|
|
{
|
|
|
|
GRID_DEBUG(gd, "rupper=%u, rlower=%u", rupper, rlower);
|
|
|
|
|
2009-10-15 03:55:12 +02:00
|
|
|
if (gd->flags & GRID_HISTORY) {
|
|
|
|
grid_collect_history(gd);
|
|
|
|
if (rupper == 0 && rlower == gd->sy - 1)
|
|
|
|
grid_scroll_history(gd);
|
|
|
|
else {
|
|
|
|
rupper = grid_view_y(gd, rupper);
|
|
|
|
rlower = grid_view_y(gd, rlower);
|
|
|
|
grid_scroll_history_region(gd, rupper, rlower);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rupper = grid_view_y(gd, rupper);
|
|
|
|
rlower = grid_view_y(gd, rlower);
|
|
|
|
grid_move_lines(gd, rupper, rupper + 1, rlower - rupper);
|
2008-09-25 22:08:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scroll region down. */
|
|
|
|
void
|
2009-03-28 16:43:41 +01:00
|
|
|
grid_view_scroll_region_down(struct grid *gd, u_int rupper, u_int rlower)
|
2008-09-25 22:08:57 +02:00
|
|
|
{
|
|
|
|
GRID_DEBUG(gd, "rupper=%u, rlower=%u", rupper, rlower);
|
|
|
|
|
|
|
|
rupper = grid_view_y(gd, rupper);
|
|
|
|
rlower = grid_view_y(gd, rlower);
|
|
|
|
|
|
|
|
grid_move_lines(gd, rupper + 1, rupper, rlower - rupper);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert lines. */
|
|
|
|
void
|
2009-03-28 16:43:41 +01:00
|
|
|
grid_view_insert_lines(struct grid *gd, u_int py, u_int ny)
|
2008-09-25 22:08:57 +02:00
|
|
|
{
|
|
|
|
u_int sy;
|
|
|
|
|
|
|
|
GRID_DEBUG(gd, "py=%u, ny=%u", py, ny);
|
|
|
|
|
|
|
|
py = grid_view_y(gd, py);
|
|
|
|
|
|
|
|
sy = grid_view_y(gd, gd->sy);
|
|
|
|
|
|
|
|
grid_move_lines(gd, py + ny, py, sy - py - ny);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert lines in region. */
|
|
|
|
void
|
2009-07-09 20:04:17 +02:00
|
|
|
grid_view_insert_lines_region(struct grid *gd, u_int rlower, u_int py, u_int ny)
|
2008-09-25 22:08:57 +02:00
|
|
|
{
|
2009-07-09 20:04:53 +02:00
|
|
|
u_int ny2;
|
|
|
|
|
2009-07-09 20:04:17 +02:00
|
|
|
GRID_DEBUG(gd, "rlower=%u, py=%u, ny=%u", rlower, py, ny);
|
2008-09-25 22:08:57 +02:00
|
|
|
|
|
|
|
rlower = grid_view_y(gd, rlower);
|
|
|
|
|
|
|
|
py = grid_view_y(gd, py);
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2009-07-09 20:04:53 +02:00
|
|
|
ny2 = rlower + 1 - py - ny;
|
|
|
|
grid_move_lines(gd, rlower + 1 - ny2, py, ny2);
|
2009-12-04 23:14:47 +01:00
|
|
|
grid_clear(gd, 0, py + ny2, gd->sx, ny - ny2);
|
2008-09-25 22:08:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete lines. */
|
|
|
|
void
|
2009-03-28 16:43:41 +01:00
|
|
|
grid_view_delete_lines(struct grid *gd, u_int py, u_int ny)
|
2008-09-25 22:08:57 +02:00
|
|
|
{
|
|
|
|
u_int sy;
|
|
|
|
|
|
|
|
GRID_DEBUG(gd, "py=%u, ny=%u", py, ny);
|
|
|
|
|
|
|
|
py = grid_view_y(gd, py);
|
|
|
|
|
|
|
|
sy = grid_view_y(gd, gd->sy);
|
|
|
|
|
|
|
|
grid_move_lines(gd, py, py + ny, sy - py - ny);
|
2009-12-04 23:14:47 +01:00
|
|
|
grid_clear(gd, 0, sy - ny, gd->sx, py + ny - (sy - ny));
|
2008-09-25 22:08:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete lines inside scroll region. */
|
|
|
|
void
|
2009-07-09 20:04:17 +02:00
|
|
|
grid_view_delete_lines_region(struct grid *gd, u_int rlower, u_int py, u_int ny)
|
2008-09-25 22:08:57 +02:00
|
|
|
{
|
2009-07-09 20:04:53 +02:00
|
|
|
u_int ny2;
|
|
|
|
|
2009-07-09 20:04:17 +02:00
|
|
|
GRID_DEBUG(gd, "rlower=%u, py=%u, ny=%u", rlower, py, ny);
|
2008-09-25 22:08:57 +02:00
|
|
|
|
|
|
|
rlower = grid_view_y(gd, rlower);
|
|
|
|
|
|
|
|
py = grid_view_y(gd, py);
|
|
|
|
|
2009-07-09 20:04:53 +02:00
|
|
|
ny2 = rlower + 1 - py - ny;
|
|
|
|
grid_move_lines(gd, py, py + ny, ny2);
|
2009-12-04 23:14:47 +01:00
|
|
|
grid_clear(gd, 0, py + ny2, gd->sx, ny - ny2);
|
2008-09-25 22:08:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert characters. */
|
|
|
|
void
|
2009-03-28 16:43:41 +01:00
|
|
|
grid_view_insert_cells(struct grid *gd, u_int px, u_int py, u_int nx)
|
2008-09-25 22:08:57 +02:00
|
|
|
{
|
|
|
|
u_int sx;
|
|
|
|
|
|
|
|
GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
|
|
|
|
|
|
|
|
px = grid_view_x(gd, px);
|
2008-09-28 22:34:22 +02:00
|
|
|
py = grid_view_y(gd, py);
|
2008-09-25 22:08:57 +02:00
|
|
|
|
2008-09-26 08:45:28 +02:00
|
|
|
sx = grid_view_x(gd, gd->sx);
|
2009-01-10 02:51:22 +01:00
|
|
|
|
2008-12-11 18:06:28 +01:00
|
|
|
if (px == sx - 1)
|
|
|
|
grid_clear(gd, px, py, 1, 1);
|
|
|
|
else
|
2009-07-01 21:14:33 +02:00
|
|
|
grid_move_cells(gd, px + nx, px, py, sx - px - nx);
|
2008-09-25 22:08:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete characters. */
|
|
|
|
void
|
2009-03-28 16:43:41 +01:00
|
|
|
grid_view_delete_cells(struct grid *gd, u_int px, u_int py, u_int nx)
|
2008-09-25 22:08:57 +02:00
|
|
|
{
|
|
|
|
u_int sx;
|
|
|
|
|
|
|
|
GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
|
|
|
|
|
|
|
|
px = grid_view_x(gd, px);
|
2008-09-28 22:34:22 +02:00
|
|
|
py = grid_view_y(gd, py);
|
2008-09-25 22:08:57 +02:00
|
|
|
|
2008-09-26 08:45:28 +02:00
|
|
|
sx = grid_view_x(gd, gd->sx);
|
2008-09-25 22:08:57 +02:00
|
|
|
|
2009-07-01 21:14:33 +02:00
|
|
|
grid_move_cells(gd, px, px + nx, py, sx - px - nx);
|
|
|
|
grid_clear(gd, sx - nx, py, px + nx - (sx - nx), 1);
|
2008-09-25 22:08:57 +02:00
|
|
|
}
|
2009-06-25 18:02:37 +02:00
|
|
|
|
|
|
|
/* Convert cells into a string. */
|
|
|
|
char *
|
|
|
|
grid_view_string_cells(struct grid *gd, u_int px, u_int py, u_int nx)
|
|
|
|
{
|
|
|
|
GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
|
|
|
|
|
|
|
|
px = grid_view_x(gd, px);
|
|
|
|
py = grid_view_y(gd, py);
|
|
|
|
|
2013-02-19 10:55:02 +01:00
|
|
|
return (grid_string_cells(gd, px, py, nx, NULL, 0));
|
2009-06-25 18:02:37 +02:00
|
|
|
}
|