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

Annotation of src/usr.bin/tmux/screen-redraw.c, Revision 1.1

1.1     ! nicm        1: /* $OpenBSD$ */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
        !             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: int    screen_redraw_check_cell(struct client *, u_int, u_int);
        !            26:
        !            27: /* Check if cell inside a pane. */
        !            28: int
        !            29: screen_redraw_check_cell(struct client *c, u_int px, u_int py)
        !            30: {
        !            31:        struct window           *w = c->session->curw->window;
        !            32:        struct window_pane      *wp;
        !            33:
        !            34:        if (px > w->sx || py > w->sy)
        !            35:                return (0);
        !            36:
        !            37:        TAILQ_FOREACH(wp, &w->panes, entry) {
        !            38:                /* Inside pane. */
        !            39:                if (px >= wp->xoff && px < wp->xoff + wp->sx &&
        !            40:                    py >= wp->yoff && py < wp->yoff + wp->sy)
        !            41:                        return (1);
        !            42:
        !            43:                /* Left/right borders. */
        !            44:                if (py >= wp->yoff && py < wp->yoff + wp->sy) {
        !            45:                        if (wp->xoff != 0 && px == wp->xoff - 1)
        !            46:                                return (1);
        !            47:                        if (px == wp->xoff + wp->sx)
        !            48:                                return (1);
        !            49:                }
        !            50:
        !            51:                /* Top/bottom borders. */
        !            52:                if (px >= wp->xoff && px < wp->xoff + wp->sx) {
        !            53:                        if (wp->yoff != 0 && py == wp->yoff - 1)
        !            54:                                return (1);
        !            55:                        if (py == wp->yoff + wp->sy)
        !            56:                                return (1);
        !            57:                }
        !            58:        }
        !            59:
        !            60:        return (0);
        !            61: }
        !            62:
        !            63: /* Redraw entire screen.. */
        !            64: void
        !            65: screen_redraw_screen(struct client *c)
        !            66: {
        !            67:        struct window           *w = c->session->curw->window;
        !            68:        struct tty              *tty = &c->tty;
        !            69:        struct window_pane      *wp;
        !            70:        struct screen           *s;
        !            71:        u_int                    i, j, sx, sy;
        !            72:        int                      status, has_acs;
        !            73:        u_char                   choriz, cvert, cbackg;
        !            74:
        !            75:        /* Get status line, er, status. */
        !            76:        status = options_get_number(&c->session->options, "status");
        !            77:
        !            78:        /* Work out ACS characters. */
        !            79:        if (tty_term_has(tty->term, TTYC_ACSC)) {
        !            80:                has_acs = 1;
        !            81:                choriz = tty_get_acs(tty, 'q');
        !            82:                cvert = tty_get_acs(tty, 'x');
        !            83:                cbackg = tty_get_acs(tty, '~');
        !            84:        } else {
        !            85:                has_acs = 0;
        !            86:                choriz = '-';
        !            87:                cvert = '|';
        !            88:                cbackg = '.';
        !            89:        }
        !            90:
        !            91:        /* Clear the screen. */
        !            92:        tty_reset(tty);
        !            93:        if (has_acs)
        !            94:                tty_putcode(tty, TTYC_SMACS);
        !            95:        for (j = 0; j < tty->sy - status; j++) {
        !            96:                for (i = 0; i < tty->sx; i++) {
        !            97:                        if (!screen_redraw_check_cell(c, i, j)) {
        !            98:                                tty_cursor(tty, i, j, 0, 0);
        !            99:                                tty_putc(tty, cbackg);
        !           100:                        }
        !           101:                }
        !           102:        }
        !           103:        if (has_acs)
        !           104:                tty_putcode(tty, TTYC_RMACS);
        !           105:
        !           106:        /* Draw the panes. */
        !           107:        TAILQ_FOREACH(wp, &w->panes, entry) {
        !           108:                if (wp->flags & PANE_HIDDEN)
        !           109:                        continue;
        !           110:
        !           111:                tty_reset(tty);
        !           112:
        !           113:                s = wp->screen;
        !           114:                sx = wp->sx;
        !           115:                sy = wp->sy;
        !           116:
        !           117:                /* Draw left and right borders. */
        !           118:                if (has_acs)
        !           119:                        tty_putcode(tty, TTYC_SMACS);
        !           120:                if (wp->xoff > 0) {
        !           121:                        for (i = wp->yoff; i < wp->yoff + sy; i++) {
        !           122:                                tty_cursor(tty, wp->xoff - 1, i, 0, 0);
        !           123:                                tty_putc(tty, cvert);
        !           124:                        }
        !           125:                }
        !           126:                if (wp->xoff + sx < tty->sx) {
        !           127:                        for (i = wp->yoff; i < wp->yoff + sy; i++) {
        !           128:                                tty_cursor(tty, wp->xoff + sx, i, 0, 0);
        !           129:                                tty_putc(&c->tty, cvert);
        !           130:                        }
        !           131:                }
        !           132:
        !           133:                /* Draw top and bottom borders. */
        !           134:                if (wp->yoff > 0) {
        !           135:                        tty_cursor(tty, wp->xoff, wp->yoff - 1, 0, 0);
        !           136:                        for (i = 0; i < sx; i++)
        !           137:                                tty_putc(tty, choriz);
        !           138:                }
        !           139:                if (wp->yoff + sy < tty->sy - status) {
        !           140:                        tty_cursor(tty, wp->xoff, wp->yoff + sy, 0, 0);
        !           141:                        for (i = 0; i < sx; i++)
        !           142:                                tty_putc(tty, choriz);
        !           143:                }
        !           144:                if (has_acs)
        !           145:                        tty_putcode(tty, TTYC_RMACS);
        !           146:
        !           147:                /* Draw the pane. */
        !           148:                screen_redraw_pane(c, wp);
        !           149:        }
        !           150:
        !           151:        /* Draw the status line. */
        !           152:        screen_redraw_status(c);
        !           153: }
        !           154:
        !           155: /* Draw a single pane. */
        !           156: void
        !           157: screen_redraw_pane(struct client *c, struct window_pane *wp)
        !           158: {
        !           159:        u_int   i;
        !           160:
        !           161:        for (i = 0; i < wp->sy; i++)
        !           162:                tty_draw_line(&c->tty, wp->screen, i, wp->xoff, wp->yoff);
        !           163: }
        !           164:
        !           165:
        !           166: /* Draw the status line. */
        !           167: void
        !           168: screen_redraw_status(struct client *c)
        !           169: {
        !           170:        tty_draw_line(&c->tty, &c->status, 0, 0, c->tty.sy - 1);
        !           171: }