mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-08 09:14:22 +01:00
6c0728fe07
Split grid into two arrays, one containing grid attributes/flags/colours (keeps the name grid_cell for now) and a separate with the character data (called text). The text is stored as a u_short but is treated as a uint64_t elsewhere; eventually the grid will have two arrays. I'm not happy with the naming so that might change. Still need to decide where to go from here. I'm not sure whether to combine the peek/set functions together, and also whether to continue to treat the text as a uint64_t (and convert to/from Unicode) or make it a char array (of size one when UTF-8 disabled, eight when enabled) and keep everything as UTF-8. Also since UTF-8 will eventually become an attribute of the grid itself it might be nice to move all the padding crap into grid.c.
217 lines
5.0 KiB
C
217 lines
5.0 KiB
C
/* $Id: grid-view.c,v 1.8 2009-03-28 16:30:05 nicm Exp $ */
|
|
|
|
/*
|
|
* 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 *
|
|
grid_view_peek_cell(struct grid *gd, u_int px, u_int py)
|
|
{
|
|
return (grid_peek_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py)));
|
|
}
|
|
|
|
/* Get cell text. */
|
|
uint64_t
|
|
grid_view_peek_text(struct grid *gd, u_int px, u_int py)
|
|
{
|
|
return (grid_peek_text(gd, grid_view_x(gd, px), grid_view_y(gd, py)));
|
|
}
|
|
|
|
/* Get cell for writing. */
|
|
struct grid_cell *
|
|
grid_view_get_cell(struct grid *gd, u_int px, u_int py)
|
|
{
|
|
return (grid_get_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py)));
|
|
}
|
|
|
|
/* Set cell. */
|
|
void
|
|
grid_view_set_cell(
|
|
struct grid *gd, u_int px, u_int py, const struct grid_cell *gc)
|
|
{
|
|
grid_set_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py), gc);
|
|
}
|
|
|
|
/* Set text. */
|
|
void
|
|
grid_view_set_text(struct grid *gd, u_int px, u_int py, uint64_t text)
|
|
{
|
|
grid_set_text(gd, grid_view_x(gd, px), grid_view_y(gd, py), text);
|
|
}
|
|
|
|
/* Clear area. */
|
|
void
|
|
grid_view_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny)
|
|
{
|
|
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);
|
|
}
|
|
|
|
/* Fill area. */
|
|
void
|
|
grid_view_fill(struct grid *gd,
|
|
const struct grid_cell *gc, u_int px, u_int py, u_int nx, u_int ny)
|
|
{
|
|
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_fill(gd, gc, px, py, nx, ny);
|
|
}
|
|
|
|
/* Scroll region up. */
|
|
void
|
|
grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower)
|
|
{
|
|
GRID_DEBUG(gd, "rupper=%u, rlower=%u", rupper, rlower);
|
|
|
|
if (rupper == 0 && rlower == gd->sy - 1) {
|
|
grid_scroll_line(gd);
|
|
return;
|
|
}
|
|
|
|
rupper = grid_view_y(gd, rupper);
|
|
rlower = grid_view_y(gd, rlower);
|
|
|
|
grid_move_lines(gd, rupper, rupper + 1, rlower - rupper);
|
|
}
|
|
|
|
/* Scroll region down. */
|
|
void
|
|
grid_view_scroll_region_down(struct grid *gd, u_int rupper, u_int rlower)
|
|
{
|
|
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
|
|
grid_view_insert_lines(struct grid *gd, u_int py, u_int ny)
|
|
{
|
|
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
|
|
grid_view_insert_lines_region(
|
|
struct grid *gd, u_int rupper, u_int rlower, u_int py, u_int ny)
|
|
{
|
|
GRID_DEBUG(
|
|
gd, "rupper=%u, rlower=%u, py=%u, ny=%u", rupper, rlower, py, ny);
|
|
|
|
rlower = grid_view_y(gd, rlower);
|
|
|
|
py = grid_view_y(gd, py);
|
|
|
|
grid_move_lines(gd, py + ny, py, (rlower + 1) - py - ny);
|
|
}
|
|
|
|
/* Delete lines. */
|
|
void
|
|
grid_view_delete_lines(struct grid *gd, u_int py, u_int ny)
|
|
{
|
|
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);
|
|
}
|
|
|
|
/* Delete lines inside scroll region. */
|
|
void
|
|
grid_view_delete_lines_region(
|
|
struct grid *gd, u_int rupper, u_int rlower, u_int py, u_int ny)
|
|
{
|
|
GRID_DEBUG(
|
|
gd, "rupper=%u, rlower=%u, py=%u, ny=%u", rupper, rlower, py, ny);
|
|
|
|
rlower = grid_view_y(gd, rlower);
|
|
|
|
py = grid_view_y(gd, py);
|
|
|
|
grid_move_lines(gd, py, py + ny, (rlower + 1) - py - ny);
|
|
}
|
|
|
|
/* Insert characters. */
|
|
void
|
|
grid_view_insert_cells(struct grid *gd, u_int px, u_int py, u_int nx)
|
|
{
|
|
u_int sx;
|
|
|
|
GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
|
|
|
|
px = grid_view_x(gd, px);
|
|
py = grid_view_y(gd, py);
|
|
|
|
sx = grid_view_x(gd, gd->sx);
|
|
|
|
if (px == sx - 1)
|
|
grid_clear(gd, px, py, 1, 1);
|
|
else
|
|
grid_move_cells(gd, px + nx, px, py, (sx - 1) - (px + nx));
|
|
}
|
|
|
|
/* Delete characters. */
|
|
void
|
|
grid_view_delete_cells(struct grid *gd, u_int px, u_int py, u_int nx)
|
|
{
|
|
u_int sx;
|
|
|
|
GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
|
|
|
|
px = grid_view_x(gd, px);
|
|
py = grid_view_y(gd, py);
|
|
|
|
sx = grid_view_x(gd, gd->sx);
|
|
|
|
grid_move_cells(gd, px, px + nx, py, (sx - 1) - (px + nx));
|
|
}
|