2009-06-01 22:58:49 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2009-06-01 22:58:49 +00:00
|
|
|
*
|
|
|
|
* 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))
|
|
|
|
|
2015-11-13 12:18:52 +00:00
|
|
|
/* Get cell. */
|
2015-11-13 08:09:28 +00:00
|
|
|
void
|
|
|
|
grid_view_get_cell(struct grid *gd, u_int px, u_int py, struct grid_cell *gc)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2015-11-13 08:09:28 +00:00
|
|
|
grid_get_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py), gc);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set cell. */
|
|
|
|
void
|
2015-11-13 08:09:28 +00:00
|
|
|
grid_view_set_cell(struct grid *gd, u_int px, u_int py,
|
|
|
|
const struct grid_cell *gc)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
grid_set_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py), gc);
|
|
|
|
}
|
|
|
|
|
2017-02-08 16:45:18 +00:00
|
|
|
/* Set cells. */
|
|
|
|
void
|
|
|
|
grid_view_set_cells(struct grid *gd, u_int px, u_int py,
|
|
|
|
const struct grid_cell *gc, const char *s, size_t slen)
|
|
|
|
{
|
|
|
|
grid_set_cells(gd, grid_view_x(gd, px), grid_view_y(gd, py), gc, s,
|
|
|
|
slen);
|
|
|
|
}
|
|
|
|
|
2011-01-25 23:40:26 +00:00
|
|
|
/* Clear into history. */
|
|
|
|
void
|
2016-10-13 20:27:27 +00:00
|
|
|
grid_view_clear_history(struct grid *gd, u_int bg)
|
2011-01-25 23:40:26 +00:00
|
|
|
{
|
|
|
|
struct grid_line *gl;
|
|
|
|
u_int yy, last;
|
|
|
|
|
|
|
|
/* Find the last used line. */
|
|
|
|
last = 0;
|
|
|
|
for (yy = 0; yy < gd->sy; yy++) {
|
2018-07-04 09:44:07 +00:00
|
|
|
gl = grid_get_line(gd, grid_view_y(gd, yy));
|
2016-10-13 20:27:27 +00:00
|
|
|
if (gl->cellused != 0)
|
2011-01-25 23:40:26 +00:00
|
|
|
last = yy + 1;
|
|
|
|
}
|
2016-10-13 20:27:27 +00:00
|
|
|
if (last == 0) {
|
|
|
|
grid_view_clear(gd, 0, 0, gd->sx, gd->sy, bg);
|
2011-01-25 23:40:26 +00:00
|
|
|
return;
|
2016-10-13 20:27:27 +00:00
|
|
|
}
|
2011-01-25 23:40:26 +00:00
|
|
|
|
|
|
|
/* Scroll the lines into the history. */
|
2012-01-29 21:31:11 +00:00
|
|
|
for (yy = 0; yy < last; yy++) {
|
2017-08-30 18:13:47 +00:00
|
|
|
grid_collect_history(gd);
|
2016-10-13 20:27:27 +00:00
|
|
|
grid_scroll_history(gd, bg);
|
2012-01-29 21:31:11 +00:00
|
|
|
}
|
2016-10-13 20:27:27 +00:00
|
|
|
if (last < gd->sy)
|
|
|
|
grid_view_clear(gd, 0, 0, gd->sx, gd->sy - last, bg);
|
2016-09-02 20:57:20 +00:00
|
|
|
gd->hscrolled = 0;
|
2011-01-25 23:40:26 +00:00
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
/* Clear area. */
|
|
|
|
void
|
2016-10-13 20:27:27 +00:00
|
|
|
grid_view_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny,
|
|
|
|
u_int bg)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
px = grid_view_x(gd, px);
|
|
|
|
py = grid_view_y(gd, py);
|
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
grid_clear(gd, px, py, nx, ny, bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Scroll region up. */
|
|
|
|
void
|
2017-05-12 13:00:56 +00:00
|
|
|
grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower,
|
|
|
|
u_int bg)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-10-13 15:38:37 +00:00
|
|
|
if (gd->flags & GRID_HISTORY) {
|
2017-08-30 18:13:47 +00:00
|
|
|
grid_collect_history(gd);
|
2009-10-13 15:38:37 +00:00
|
|
|
if (rupper == 0 && rlower == gd->sy - 1)
|
2017-05-12 13:00:56 +00:00
|
|
|
grid_scroll_history(gd, bg);
|
2009-10-13 15:38:37 +00:00
|
|
|
else {
|
|
|
|
rupper = grid_view_y(gd, rupper);
|
|
|
|
rlower = grid_view_y(gd, rlower);
|
2017-05-12 13:00:56 +00:00
|
|
|
grid_scroll_history_region(gd, rupper, rlower, bg);
|
2009-10-13 15:38:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rupper = grid_view_y(gd, rupper);
|
|
|
|
rlower = grid_view_y(gd, rlower);
|
2017-05-12 13:00:56 +00:00
|
|
|
grid_move_lines(gd, rupper, rupper + 1, rlower - rupper, bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scroll region down. */
|
|
|
|
void
|
2017-05-12 13:00:56 +00:00
|
|
|
grid_view_scroll_region_down(struct grid *gd, u_int rupper, u_int rlower,
|
|
|
|
u_int bg)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
rupper = grid_view_y(gd, rupper);
|
|
|
|
rlower = grid_view_y(gd, rlower);
|
|
|
|
|
2017-05-12 13:00:56 +00:00
|
|
|
grid_move_lines(gd, rupper + 1, rupper, rlower - rupper, bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert lines. */
|
|
|
|
void
|
2016-10-13 20:27:27 +00:00
|
|
|
grid_view_insert_lines(struct grid *gd, u_int py, u_int ny, u_int bg)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
u_int sy;
|
|
|
|
|
|
|
|
py = grid_view_y(gd, py);
|
|
|
|
|
|
|
|
sy = grid_view_y(gd, gd->sy);
|
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
grid_move_lines(gd, py + ny, py, sy - py - ny, bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert lines in region. */
|
|
|
|
void
|
2014-04-17 14:45:49 +00:00
|
|
|
grid_view_insert_lines_region(struct grid *gd, u_int rlower, u_int py,
|
2016-10-13 20:27:27 +00:00
|
|
|
u_int ny, u_int bg)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-07-09 07:58:14 +00:00
|
|
|
u_int ny2;
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
rlower = grid_view_y(gd, rlower);
|
|
|
|
|
|
|
|
py = grid_view_y(gd, py);
|
|
|
|
|
2009-07-09 07:58:14 +00:00
|
|
|
ny2 = rlower + 1 - py - ny;
|
2016-10-13 20:27:27 +00:00
|
|
|
grid_move_lines(gd, rlower + 1 - ny2, py, ny2, bg);
|
|
|
|
grid_clear(gd, 0, py + ny2, gd->sx, ny - ny2, bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete lines. */
|
|
|
|
void
|
2016-10-13 20:27:27 +00:00
|
|
|
grid_view_delete_lines(struct grid *gd, u_int py, u_int ny, u_int bg)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
u_int sy;
|
|
|
|
|
|
|
|
py = grid_view_y(gd, py);
|
|
|
|
|
|
|
|
sy = grid_view_y(gd, gd->sy);
|
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
grid_move_lines(gd, py, py + ny, sy - py - ny, bg);
|
|
|
|
grid_clear(gd, 0, sy - ny, gd->sx, py + ny - (sy - ny), bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete lines inside scroll region. */
|
|
|
|
void
|
2014-04-17 14:45:49 +00:00
|
|
|
grid_view_delete_lines_region(struct grid *gd, u_int rlower, u_int py,
|
2016-10-13 20:27:27 +00:00
|
|
|
u_int ny, u_int bg)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-07-09 07:58:14 +00:00
|
|
|
u_int ny2;
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
rlower = grid_view_y(gd, rlower);
|
|
|
|
|
|
|
|
py = grid_view_y(gd, py);
|
|
|
|
|
2009-07-09 07:58:14 +00:00
|
|
|
ny2 = rlower + 1 - py - ny;
|
2016-10-13 20:27:27 +00:00
|
|
|
grid_move_lines(gd, py, py + ny, ny2, bg);
|
|
|
|
grid_clear(gd, 0, py + ny2, gd->sx, ny - ny2, bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert characters. */
|
|
|
|
void
|
2016-10-13 20:27:27 +00:00
|
|
|
grid_view_insert_cells(struct grid *gd, u_int px, u_int py, u_int nx, u_int bg)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
u_int sx;
|
|
|
|
|
|
|
|
px = grid_view_x(gd, px);
|
|
|
|
py = grid_view_y(gd, py);
|
|
|
|
|
2015-01-06 21:14:42 +00:00
|
|
|
sx = grid_view_x(gd, gd->sx);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2017-02-16 12:43:08 +00:00
|
|
|
if (px >= sx - 1)
|
2016-10-13 20:27:27 +00:00
|
|
|
grid_clear(gd, px, py, 1, 1, bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
else
|
2016-10-13 20:27:27 +00:00
|
|
|
grid_move_cells(gd, px + nx, px, py, sx - px - nx, bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete characters. */
|
|
|
|
void
|
2016-10-13 20:27:27 +00:00
|
|
|
grid_view_delete_cells(struct grid *gd, u_int px, u_int py, u_int nx, u_int bg)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
u_int sx;
|
|
|
|
|
|
|
|
px = grid_view_x(gd, px);
|
|
|
|
py = grid_view_y(gd, py);
|
|
|
|
|
2015-01-06 21:14:42 +00:00
|
|
|
sx = grid_view_x(gd, gd->sx);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
grid_move_cells(gd, px, px + nx, py, sx - px - nx, bg);
|
2019-08-16 08:52:25 +00:00
|
|
|
grid_clear(gd, sx - nx, py, px + nx - (sx - nx), 1, bg);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2009-06-24 22:04:18 +00:00
|
|
|
|
|
|
|
/* Convert cells into a string. */
|
|
|
|
char *
|
|
|
|
grid_view_string_cells(struct grid *gd, u_int px, u_int py, u_int nx)
|
|
|
|
{
|
|
|
|
px = grid_view_x(gd, px);
|
|
|
|
py = grid_view_y(gd, py);
|
|
|
|
|
2013-03-25 10:05:35 +00:00
|
|
|
return (grid_string_cells(gd, px, py, nx, NULL, 0, 0, 0));
|
2009-06-24 22:04:18 +00:00
|
|
|
}
|