=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/tty.c,v retrieving revision 1.209 retrieving revision 1.210 diff -u -r1.209 -r1.210 --- src/usr.bin/tmux/tty.c 2016/10/12 13:24:07 1.209 +++ src/usr.bin/tmux/tty.c 2016/10/13 20:27:27 1.210 @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.209 2016/10/12 13:24:07 nicm Exp $ */ +/* $OpenBSD: tty.c,v 1.210 2016/10/13 20:27:27 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -55,7 +55,8 @@ static void tty_region_pane(struct tty *, const struct tty_ctx *, u_int, u_int); static int tty_large_region(struct tty *, const struct tty_ctx *); -static int tty_fake_bce(const struct tty *, const struct window_pane *); +static int tty_fake_bce(const struct tty *, const struct window_pane *, + u_int); static void tty_redraw_region(struct tty *, const struct tty_ctx *); static void tty_emulate_repeat(struct tty *, enum tty_code_code, enum tty_code_code, u_int); @@ -64,6 +65,8 @@ const struct window_pane *); static void tty_default_colours(struct grid_cell *, const struct window_pane *); +static void tty_default_attributes(struct tty *, const struct window_pane *, + u_int); #define tty_use_acs(tty) \ (tty_term_has((tty)->term, TTYC_ACSC) && !((tty)->flags & TTY_UTF8)) @@ -604,17 +607,20 @@ * emulated. */ static int -tty_fake_bce(const struct tty *tty, const struct window_pane *wp) +tty_fake_bce(const struct tty *tty, const struct window_pane *wp, u_int bg) { struct grid_cell gc; + if (tty_term_flag(tty->term, TTYC_BCE)) + return (0); + memcpy(&gc, &grid_default_cell, sizeof gc); if (wp != NULL) tty_default_colours(&gc, wp); - if (gc.bg == 8) - return (0); - return (!tty_term_flag(tty->term, TTYC_BCE)); + if (bg != 8 || gc.bg != 8) + return (1); + return (0); } /* @@ -695,13 +701,13 @@ } if (sx < tty->sx) { - tty_attributes(tty, &grid_default_cell, wp); + tty_default_attributes(tty, wp, 8); tty_cursor(tty, ox + sx, oy + py); if (sx != screen_size_x(s) && ox + screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL) && - !tty_fake_bce(tty, wp)) + !tty_fake_bce(tty, wp, 8)) tty_putcode(tty, TTYC_EL); else tty_repeat_space(tty, screen_size_x(s) - sx); @@ -759,14 +765,15 @@ { struct window_pane *wp = ctx->wp; - if (!tty_pane_full_width(tty, ctx) || tty_fake_bce(tty, wp) || - (!tty_term_has(tty->term, TTYC_DCH) && - !tty_term_has(tty->term, TTYC_DCH1))) { + if (!tty_pane_full_width(tty, ctx) || + tty_fake_bce(tty, wp, ctx->bg) || + (!tty_term_has(tty->term, TTYC_ICH) && + !tty_term_has(tty->term, TTYC_ICH1))) { tty_draw_pane(tty, wp, ctx->ocy, ctx->xoff, ctx->yoff); return; } - tty_attributes(tty, &grid_default_cell, wp); + tty_default_attributes(tty, wp, ctx->bg); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); @@ -778,14 +785,15 @@ { struct window_pane *wp = ctx->wp; - if (!tty_pane_full_width(tty, ctx) || tty_fake_bce(tty, wp) || + if (!tty_pane_full_width(tty, ctx) || + tty_fake_bce(tty, wp, ctx->bg) || (!tty_term_has(tty->term, TTYC_DCH) && !tty_term_has(tty->term, TTYC_DCH1))) { tty_draw_pane(tty, wp, ctx->ocy, ctx->xoff, ctx->yoff); return; } - tty_attributes(tty, &grid_default_cell, wp); + tty_default_attributes(tty, wp, ctx->bg); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); @@ -801,7 +809,8 @@ tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); - if (tty_term_has(tty->term, TTYC_ECH) && !tty_fake_bce(tty, ctx->wp)) + if (tty_term_has(tty->term, TTYC_ECH) && + !tty_fake_bce(tty, ctx->wp, ctx->bg)) tty_putcode1(tty, TTYC_ECH, ctx->num); else { for (i = 0; i < ctx->num; i++) @@ -812,14 +821,15 @@ void tty_cmd_insertline(struct tty *tty, const struct tty_ctx *ctx) { - if (!tty_pane_full_width(tty, ctx) || tty_fake_bce(tty, ctx->wp) || + if (!tty_pane_full_width(tty, ctx) || + tty_fake_bce(tty, ctx->wp, ctx->bg) || !tty_term_has(tty->term, TTYC_CSR) || !tty_term_has(tty->term, TTYC_IL1)) { tty_redraw_region(tty, ctx); return; } - tty_attributes(tty, &grid_default_cell, ctx->wp); + tty_default_attributes(tty, ctx->wp, ctx->bg); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); @@ -830,14 +840,15 @@ void tty_cmd_deleteline(struct tty *tty, const struct tty_ctx *ctx) { - if (!tty_pane_full_width(tty, ctx) || tty_fake_bce(tty, ctx->wp) || + if (!tty_pane_full_width(tty, ctx) || + tty_fake_bce(tty, ctx->wp, ctx->bg) || !tty_term_has(tty->term, TTYC_CSR) || !tty_term_has(tty->term, TTYC_DL1)) { tty_redraw_region(tty, ctx); return; } - tty_attributes(tty, &grid_default_cell, ctx->wp); + tty_default_attributes(tty, ctx->wp, ctx->bg); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); @@ -851,11 +862,12 @@ struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; - tty_attributes(tty, &grid_default_cell, wp); + tty_default_attributes(tty, wp, ctx->bg); tty_cursor_pane(tty, ctx, 0, ctx->ocy); - if (tty_pane_full_width(tty, ctx) && !tty_fake_bce(tty, wp) && + if (tty_pane_full_width(tty, ctx) && + !tty_fake_bce(tty, wp, ctx->bg) && tty_term_has(tty->term, TTYC_EL)) tty_putcode(tty, TTYC_EL); else @@ -868,12 +880,13 @@ struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; - tty_attributes(tty, &grid_default_cell, wp); + tty_default_attributes(tty, wp, ctx->bg); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); if (tty_pane_full_width(tty, ctx) && - tty_term_has(tty->term, TTYC_EL) && !tty_fake_bce(tty, wp)) + tty_term_has(tty->term, TTYC_EL) && + !tty_fake_bce(tty, wp, ctx->bg)) tty_putcode(tty, TTYC_EL); else tty_repeat_space(tty, screen_size_x(s) - ctx->ocx); @@ -882,10 +895,13 @@ void tty_cmd_clearstartofline(struct tty *tty, const struct tty_ctx *ctx) { - tty_attributes(tty, &grid_default_cell, ctx->wp); + struct window_pane *wp = ctx->wp; - if (ctx->xoff == 0 && tty_term_has(tty->term, TTYC_EL1) && - !tty_fake_bce(tty, ctx->wp)) { + tty_default_attributes(tty, wp, ctx->bg); + + if (ctx->xoff == 0 && + tty_term_has(tty->term, TTYC_EL1) && + !tty_fake_bce(tty, ctx->wp, ctx->bg)) { tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); tty_putcode(tty, TTYC_EL1); } else { @@ -900,7 +916,8 @@ if (ctx->ocy != ctx->orupper) return; - if (!tty_pane_full_width(tty, ctx) || tty_fake_bce(tty, ctx->wp) || + if (!tty_pane_full_width(tty, ctx) || + tty_fake_bce(tty, ctx->wp, ctx->bg) || !tty_term_has(tty->term, TTYC_CSR) || !tty_term_has(tty->term, TTYC_RI)) { tty_redraw_region(tty, ctx); @@ -923,7 +940,8 @@ if (ctx->ocy != ctx->orlower) return; - if (!tty_pane_full_width(tty, ctx) || tty_fake_bce(tty, wp) || + if (!tty_pane_full_width(tty, ctx) || + tty_fake_bce(tty, wp, ctx->bg) || !tty_term_has(tty->term, TTYC_CSR)) { if (tty_large_region(tty, ctx)) wp->flags |= PANE_REDRAW; @@ -955,13 +973,14 @@ struct screen *s = wp->screen; u_int i, j; - tty_attributes(tty, &grid_default_cell, wp); + tty_default_attributes(tty, wp, ctx->bg); tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); if (tty_pane_full_width(tty, ctx) && - tty_term_has(tty->term, TTYC_EL) && !tty_fake_bce(tty, wp)) { + tty_term_has(tty->term, TTYC_EL) && + !tty_fake_bce(tty, wp, ctx->bg)) { tty_putcode(tty, TTYC_EL); if (ctx->ocy != screen_size_y(s) - 1) { tty_cursor_pane(tty, ctx, 0, ctx->ocy + 1); @@ -995,7 +1014,8 @@ tty_cursor_pane(tty, ctx, 0, 0); if (tty_pane_full_width(tty, ctx) && - tty_term_has(tty->term, TTYC_EL) && !tty_fake_bce(tty, wp)) { + tty_term_has(tty->term, TTYC_EL) && + !tty_fake_bce(tty, wp, ctx->bg)) { for (i = 0; i < ctx->ocy; i++) { tty_putcode(tty, TTYC_EL); tty_emulate_repeat(tty, TTYC_CUD, TTYC_CUD1, 1); @@ -1017,13 +1037,14 @@ struct screen *s = wp->screen; u_int i, j; - tty_attributes(tty, &grid_default_cell, wp); + tty_default_attributes(tty, wp, ctx->bg); tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1); tty_cursor_pane(tty, ctx, 0, 0); if (tty_pane_full_width(tty, ctx) && - tty_term_has(tty->term, TTYC_EL) && !tty_fake_bce(tty, wp)) { + tty_term_has(tty->term, TTYC_EL) && + !tty_fake_bce(tty, wp, ctx->bg)) { for (i = 0; i < screen_size_y(s); i++) { tty_putcode(tty, TTYC_EL); if (i != screen_size_y(s) - 1) { @@ -1720,4 +1741,14 @@ else gc->bg = wgc->bg; } +} + +static void +tty_default_attributes(struct tty *tty, const struct window_pane *wp, u_int bg) +{ + static struct grid_cell gc; + + memcpy(&gc, &grid_default_cell, sizeof gc); + gc.bg = bg; + tty_attributes(tty, &gc, wp); }