diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-07-24 16:21:43 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-07-24 16:21:43 +0000 |
commit | e8c16511d349d48ac423c7c54e7ba728f0e28dac (patch) | |
tree | e9e3727edae13eb5c37c44a719fd8063307ee719 | |
parent | 02cec671346445cdccd783dbabd4785f8d12703e (diff) |
Simplify screen redrawing by drawing the border and background together rather
than border separately, and consolidating all the drawing characters into one
string.
-rw-r--r-- | usr.bin/tmux/screen-redraw.c | 102 |
1 files changed, 27 insertions, 75 deletions
diff --git a/usr.bin/tmux/screen-redraw.c b/usr.bin/tmux/screen-redraw.c index a610dc76388..e6e2b5c493b 100644 --- a/usr.bin/tmux/screen-redraw.c +++ b/usr.bin/tmux/screen-redraw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen-redraw.c,v 1.5 2009/07/14 19:11:58 nicm Exp $ */ +/* $OpenBSD: screen-redraw.c,v 1.6 2009/07/24 16:21:42 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -24,6 +24,13 @@ int screen_redraw_check_cell(struct client *, u_int, u_int); +#define CELL_INSIDE 0 +#define CELL_LEFT 1 +#define CELL_RIGHT 2 +#define CELL_TOP 3 +#define CELL_BOTTOM 4 +#define CELL_OUTSIDE 5 + /* Check if cell inside a pane. */ int screen_redraw_check_cell(struct client *c, u_int px, u_int py) @@ -32,7 +39,7 @@ screen_redraw_check_cell(struct client *c, u_int px, u_int py) struct window_pane *wp; if (px > w->sx || py > w->sy) - return (0); + return (CELL_OUTSIDE); TAILQ_FOREACH(wp, &w->panes, entry) { if (!window_pane_visible(wp)) @@ -41,26 +48,26 @@ screen_redraw_check_cell(struct client *c, u_int px, u_int py) /* Inside pane. */ if (px >= wp->xoff && px < wp->xoff + wp->sx && py >= wp->yoff && py < wp->yoff + wp->sy) - return (1); + return (CELL_INSIDE); /* Left/right borders. */ if (py >= wp->yoff && py < wp->yoff + wp->sy) { if (wp->xoff != 0 && px == wp->xoff - 1) - return (1); + return (CELL_LEFT); if (px == wp->xoff + wp->sx) - return (1); + return (CELL_RIGHT); } /* Top/bottom borders. */ if (px >= wp->xoff && px < wp->xoff + wp->sx) { if (wp->yoff != 0 && py == wp->yoff - 1) - return (1); + return (CELL_TOP); if (py == wp->yoff + wp->sy) - return (1); + return (CELL_BOTTOM); } } - return (0); + return (CELL_OUTSIDE); } /* Redraw entire screen. */ @@ -70,9 +77,9 @@ screen_redraw_screen(struct client *c, int status_only) struct window *w = c->session->curw->window; struct tty *tty = &c->tty; struct window_pane *wp; - u_int i, j, sx, sy; - int status, has_acs; - u_char choriz, cvert, cbackg; + u_int i, j, type; + int status; + const u_char *border; /* Get status line, er, status. */ if (c->message_string != NULL || c->prompt_string != NULL) @@ -86,85 +93,30 @@ screen_redraw_screen(struct client *c, int status_only) return; } - /* Work out ACS characters. */ - if (tty_term_has(tty->term, TTYC_ACSC)) { - has_acs = 1; - choriz = tty_get_acs(tty, 'q'); - cvert = tty_get_acs(tty, 'x'); - cbackg = tty_get_acs(tty, '~'); - } else { - has_acs = 0; - choriz = '-'; - cvert = '|'; - cbackg = '.'; - } - - /* Clear the screen. */ + /* Draw background and borders. */ tty_reset(tty); - if (has_acs) + if (tty_term_has(tty->term, TTYC_ACSC)) { + border = " xxqq~"; tty_putcode(tty, TTYC_SMACS); + } else + border = " ||--."; for (j = 0; j < tty->sy - status; j++) { if (status_only && j != tty->sy - 1) continue; for (i = 0; i < tty->sx; i++) { - if (!screen_redraw_check_cell(c, i, j)) { + type = screen_redraw_check_cell(c, i, j); + if (type != CELL_INSIDE) { tty_cursor(tty, i, j, 0, 0); - tty_putc(tty, cbackg); + tty_putc(tty, border[type]); } } } - if (has_acs) - tty_putcode(tty, TTYC_RMACS); + tty_putcode(tty, TTYC_RMACS); /* Draw the panes. */ TAILQ_FOREACH(wp, &w->panes, entry) { if (!window_pane_visible(wp)) continue; - - tty_reset(tty); - - sx = wp->sx; - sy = wp->sy; - - /* Draw left and right borders. */ - if (has_acs) - tty_putcode(tty, TTYC_SMACS); - if (wp->xoff > 0) { - for (i = wp->yoff; i < wp->yoff + sy; i++) { - if (status_only && i != tty->sy - 1) - continue; - tty_cursor(tty, wp->xoff - 1, i, 0, 0); - tty_putc(tty, cvert); - } - } - if (wp->xoff + sx < tty->sx) { - for (i = wp->yoff; i < wp->yoff + sy; i++) { - if (status_only && i != tty->sy - 1) - continue; - tty_cursor(tty, wp->xoff + sx, i, 0, 0); - tty_putc(&c->tty, cvert); - } - } - - /* Draw top and bottom borders. */ - if (wp->yoff > 0) { - if (!status_only || wp->yoff - 1 == tty->sy - 1) { - tty_cursor(tty, wp->xoff, wp->yoff - 1, 0, 0); - for (i = 0; i < sx; i++) - tty_putc(tty, choriz); - } - } - if (wp->yoff + sy < tty->sy - status) { - if (!status_only || wp->yoff + sy == tty->sy - 1) { - tty_cursor(tty, wp->xoff, wp->yoff + sy, 0, 0); - for (i = 0; i < sx; i++) - tty_putc(tty, choriz); - } - } - if (has_acs) - tty_putcode(tty, TTYC_RMACS); - - /* Draw the pane. */ for (i = 0; i < wp->sy; i++) { if (status_only && wp->yoff + i != tty->sy - 1) continue; |