[BACK]Return to grid-view.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/grid-view.c, Revision 1.27

1.27    ! nicm        1: /* $OpenBSD: grid-view.c,v 1.26 2016/10/13 20:27:27 nicm Exp $ */
1.1       nicm        2:
                      3: /*
1.24      nicm        4:  * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1       nicm        5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
                      9:  *
                     10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
                     15:  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
                     16:  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:  */
                     18:
                     19: #include <sys/types.h>
                     20:
                     21: #include <string.h>
                     22:
                     23: #include "tmux.h"
                     24:
                     25: /*
                     26:  * Grid view functions. These work using coordinates relative to the visible
                     27:  * screen area.
                     28:  */
                     29:
                     30: #define grid_view_x(gd, x) (x)
                     31: #define grid_view_y(gd, y) ((gd)->hsize + (y))
                     32:
1.23      nicm       33: /* Get cell. */
1.22      nicm       34: void
                     35: grid_view_get_cell(struct grid *gd, u_int px, u_int py, struct grid_cell *gc)
1.1       nicm       36: {
1.22      nicm       37:        grid_get_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py), gc);
1.1       nicm       38: }
                     39:
                     40: /* Set cell. */
                     41: void
1.22      nicm       42: grid_view_set_cell(struct grid *gd, u_int px, u_int py,
                     43:     const struct grid_cell *gc)
1.1       nicm       44: {
                     45:        grid_set_cell(gd, grid_view_x(gd, px), grid_view_y(gd, py), gc);
1.27    ! nicm       46: }
        !            47:
        !            48: /* Set cells. */
        !            49: void
        !            50: grid_view_set_cells(struct grid *gd, u_int px, u_int py,
        !            51:     const struct grid_cell *gc, const char *s, size_t slen)
        !            52: {
        !            53:        grid_set_cells(gd, grid_view_x(gd, px), grid_view_y(gd, py), gc, s,
        !            54:            slen);
1.1       nicm       55: }
                     56:
1.9       nicm       57: /* Clear into history. */
                     58: void
1.26      nicm       59: grid_view_clear_history(struct grid *gd, u_int bg)
1.9       nicm       60: {
                     61:        struct grid_line        *gl;
                     62:        u_int                    yy, last;
                     63:
                     64:        /* Find the last used line. */
                     65:        last = 0;
                     66:        for (yy = 0; yy < gd->sy; yy++) {
                     67:                gl = &gd->linedata[grid_view_y(gd, yy)];
1.26      nicm       68:                if (gl->cellused != 0)
1.9       nicm       69:                        last = yy + 1;
                     70:        }
1.26      nicm       71:        if (last == 0) {
                     72:                grid_view_clear(gd, 0, 0, gd->sx, gd->sy, bg);
1.9       nicm       73:                return;
1.26      nicm       74:        }
1.9       nicm       75:
                     76:        /* Scroll the lines into the history. */
1.10      nicm       77:        for (yy = 0; yy < last; yy++) {
1.26      nicm       78:                grid_collect_history(gd, bg);
                     79:                grid_scroll_history(gd, bg);
1.10      nicm       80:        }
1.26      nicm       81:        if (last < gd->sy)
                     82:                grid_view_clear(gd, 0, 0, gd->sx, gd->sy - last, bg);
1.25      nicm       83:        gd->hscrolled = 0;
1.1       nicm       84: }
                     85:
                     86: /* Clear area. */
                     87: void
1.26      nicm       88: grid_view_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny,
                     89:     u_int bg)
1.1       nicm       90: {
                     91:        px = grid_view_x(gd, px);
                     92:        py = grid_view_y(gd, py);
                     93:
1.26      nicm       94:        grid_clear(gd, px, py, nx, ny, bg);
1.1       nicm       95: }
                     96:
                     97: /* Scroll region up. */
                     98: void
                     99: grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower)
                    100: {
1.7       nicm      101:        if (gd->flags & GRID_HISTORY) {
1.26      nicm      102:                grid_collect_history(gd, 8);
1.7       nicm      103:                if (rupper == 0 && rlower == gd->sy - 1)
1.26      nicm      104:                        grid_scroll_history(gd, 8);
1.7       nicm      105:                else {
                    106:                        rupper = grid_view_y(gd, rupper);
                    107:                        rlower = grid_view_y(gd, rlower);
                    108:                        grid_scroll_history_region(gd, rupper, rlower);
                    109:                }
                    110:        } else {
                    111:                rupper = grid_view_y(gd, rupper);
                    112:                rlower = grid_view_y(gd, rlower);
1.26      nicm      113:                grid_move_lines(gd, rupper, rupper + 1, rlower - rupper, 8);
1.1       nicm      114:        }
                    115: }
                    116:
                    117: /* Scroll region down. */
                    118: void
                    119: grid_view_scroll_region_down(struct grid *gd, u_int rupper, u_int rlower)
                    120: {
                    121:        rupper = grid_view_y(gd, rupper);
                    122:        rlower = grid_view_y(gd, rlower);
                    123:
1.26      nicm      124:        grid_move_lines(gd, rupper + 1, rupper, rlower - rupper, 8);
1.1       nicm      125: }
                    126:
                    127: /* Insert lines. */
                    128: void
1.26      nicm      129: grid_view_insert_lines(struct grid *gd, u_int py, u_int ny, u_int bg)
1.1       nicm      130: {
                    131:        u_int   sy;
                    132:
                    133:        py = grid_view_y(gd, py);
                    134:
                    135:        sy = grid_view_y(gd, gd->sy);
                    136:
1.26      nicm      137:        grid_move_lines(gd, py + ny, py, sy - py - ny, bg);
1.1       nicm      138: }
                    139:
                    140: /* Insert lines in region. */
                    141: void
1.16      nicm      142: grid_view_insert_lines_region(struct grid *gd, u_int rlower, u_int py,
1.26      nicm      143:     u_int ny, u_int bg)
1.1       nicm      144: {
1.5       nicm      145:        u_int   ny2;
                    146:
1.1       nicm      147:        rlower = grid_view_y(gd, rlower);
                    148:
                    149:        py = grid_view_y(gd, py);
                    150:
1.5       nicm      151:        ny2 = rlower + 1 - py - ny;
1.26      nicm      152:        grid_move_lines(gd, rlower + 1 - ny2, py, ny2, bg);
                    153:        grid_clear(gd, 0, py + ny2, gd->sx, ny - ny2, bg);
1.1       nicm      154: }
                    155:
                    156: /* Delete lines. */
                    157: void
1.26      nicm      158: grid_view_delete_lines(struct grid *gd, u_int py, u_int ny, u_int bg)
1.1       nicm      159: {
                    160:        u_int   sy;
                    161:
                    162:        py = grid_view_y(gd, py);
                    163:
                    164:        sy = grid_view_y(gd, gd->sy);
                    165:
1.26      nicm      166:        grid_move_lines(gd, py, py + ny, sy - py - ny, bg);
                    167:        grid_clear(gd, 0, sy - ny, gd->sx, py + ny - (sy - ny), bg);
1.1       nicm      168: }
                    169:
                    170: /* Delete lines inside scroll region. */
                    171: void
1.16      nicm      172: grid_view_delete_lines_region(struct grid *gd, u_int rlower, u_int py,
1.26      nicm      173:     u_int ny, u_int bg)
1.1       nicm      174: {
1.5       nicm      175:        u_int   ny2;
                    176:
1.1       nicm      177:        rlower = grid_view_y(gd, rlower);
                    178:
                    179:        py = grid_view_y(gd, py);
                    180:
1.5       nicm      181:        ny2 = rlower + 1 - py - ny;
1.26      nicm      182:        grid_move_lines(gd, py, py + ny, ny2, bg);
                    183:        grid_clear(gd, 0, py + ny2, gd->sx, ny - ny2, bg);
1.1       nicm      184: }
                    185:
                    186: /* Insert characters. */
                    187: void
1.26      nicm      188: grid_view_insert_cells(struct grid *gd, u_int px, u_int py, u_int nx, u_int bg)
1.1       nicm      189: {
                    190:        u_int   sx;
                    191:
                    192:        px = grid_view_x(gd, px);
                    193:        py = grid_view_y(gd, py);
                    194:
1.21      nicm      195:        sx = grid_view_x(gd, gd->sx);
1.1       nicm      196:
                    197:        if (px == sx - 1)
1.26      nicm      198:                grid_clear(gd, px, py, 1, 1, bg);
1.1       nicm      199:        else
1.26      nicm      200:                grid_move_cells(gd, px + nx, px, py, sx - px - nx, bg);
1.1       nicm      201: }
                    202:
                    203: /* Delete characters. */
                    204: void
1.26      nicm      205: grid_view_delete_cells(struct grid *gd, u_int px, u_int py, u_int nx, u_int bg)
1.1       nicm      206: {
                    207:        u_int   sx;
                    208:
                    209:        px = grid_view_x(gd, px);
                    210:        py = grid_view_y(gd, py);
                    211:
1.21      nicm      212:        sx = grid_view_x(gd, gd->sx);
1.1       nicm      213:
1.26      nicm      214:        grid_move_cells(gd, px, px + nx, py, sx - px - nx, bg);
                    215:        grid_clear(gd, sx - nx, py, px + nx - (sx - nx), 1, bg);
1.2       nicm      216: }
                    217:
                    218: /* Convert cells into a string. */
                    219: char *
                    220: grid_view_string_cells(struct grid *gd, u_int px, u_int py, u_int nx)
                    221: {
                    222:        px = grid_view_x(gd, px);
                    223:        py = grid_view_y(gd, py);
                    224:
1.14      nicm      225:        return (grid_string_cells(gd, px, py, nx, NULL, 0, 0, 0));
1.1       nicm      226: }