From 18bab3079228f5d7e85a615f57c12c16f9331568 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 12 May 2017 13:00:56 +0000 Subject: [PATCH] Scrolling needs to use background colour. --- grid-view.c | 16 +++++++++------- grid.c | 4 ++-- input.c | 11 ++++++----- screen-write.c | 33 +++++++++++++++++++++++++-------- server-fn.c | 2 +- tmux.h | 13 +++++++------ tty.c | 10 ++++++---- window-copy.c | 2 +- 8 files changed, 57 insertions(+), 34 deletions(-) diff --git a/grid-view.c b/grid-view.c index fe096252..033ec033 100644 --- a/grid-view.c +++ b/grid-view.c @@ -96,32 +96,34 @@ grid_view_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny, /* Scroll region up. */ void -grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower) +grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower, + u_int bg) { if (gd->flags & GRID_HISTORY) { - grid_collect_history(gd, 8); + grid_collect_history(gd, bg); if (rupper == 0 && rlower == gd->sy - 1) - grid_scroll_history(gd, 8); + grid_scroll_history(gd, bg); else { rupper = grid_view_y(gd, rupper); rlower = grid_view_y(gd, rlower); - grid_scroll_history_region(gd, rupper, rlower); + grid_scroll_history_region(gd, rupper, rlower, bg); } } else { rupper = grid_view_y(gd, rupper); rlower = grid_view_y(gd, rlower); - grid_move_lines(gd, rupper, rupper + 1, rlower - rupper, 8); + grid_move_lines(gd, rupper, rupper + 1, rlower - rupper, bg); } } /* Scroll region down. */ void -grid_view_scroll_region_down(struct grid *gd, u_int rupper, u_int rlower) +grid_view_scroll_region_down(struct grid *gd, u_int rupper, u_int rlower, + u_int bg) { rupper = grid_view_y(gd, rupper); rlower = grid_view_y(gd, rlower); - grid_move_lines(gd, rupper + 1, rupper, rlower - rupper, 8); + grid_move_lines(gd, rupper + 1, rupper, rlower - rupper, bg); } /* Insert lines. */ diff --git a/grid.c b/grid.c index 25b0d016..4f728dbe 100644 --- a/grid.c +++ b/grid.c @@ -284,7 +284,7 @@ grid_clear_history(struct grid *gd) /* Scroll a region up, moving the top line into the history. */ void -grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower) +grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower, u_int bg) { struct grid_line *gl_history, *gl_upper, *gl_lower; u_int yy; @@ -309,7 +309,7 @@ grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower) /* Then move the region up and clear the bottom line. */ memmove(gl_upper, gl_upper + 1, (lower - upper) * sizeof *gl_upper); - memset(gl_lower, 0, sizeof *gl_lower); + grid_empty_line(gd, lower, bg); /* Move the history offset down over the line. */ gd->hscrolled++; diff --git a/input.c b/input.c index 22dd1ee2..a6dd0fea 100644 --- a/input.c +++ b/input.c @@ -1123,7 +1123,7 @@ input_c0_dispatch(struct input_ctx *ictx) case '\012': /* LF */ case '\013': /* VT */ case '\014': /* FF */ - screen_write_linefeed(sctx, 0); + screen_write_linefeed(sctx, 0, ictx->cell.cell.bg); break; case '\015': /* CR */ screen_write_carriagereturn(sctx); @@ -1168,18 +1168,18 @@ input_esc_dispatch(struct input_ctx *ictx) screen_write_reset(sctx); break; case INPUT_ESC_IND: - screen_write_linefeed(sctx, 0); + screen_write_linefeed(sctx, 0, ictx->cell.cell.bg); break; case INPUT_ESC_NEL: screen_write_carriagereturn(sctx); - screen_write_linefeed(sctx, 0); + screen_write_linefeed(sctx, 0, ictx->cell.cell.bg); break; case INPUT_ESC_HTS: if (s->cx < screen_size_x(s)) bit_set(s->tabs, s->cx); break; case INPUT_ESC_RI: - screen_write_reverseindex(sctx); + screen_write_reverseindex(sctx, ictx->cell.cell.bg); break; case INPUT_ESC_DECKPAM: screen_write_mode_set(sctx, MODE_KKEYPAD); @@ -1417,7 +1417,8 @@ input_csi_dispatch(struct input_ctx *ictx) input_csi_dispatch_sm_private(ictx); break; case INPUT_CSI_SU: - screen_write_scrollup(sctx, input_get(ictx, 0, 1, 1)); + screen_write_scrollup(sctx, input_get(ictx, 0, 1, 1), + ictx->cell.cell.bg); break; case INPUT_CSI_TBC: switch (input_get(ictx, 0, 0, 0)) { diff --git a/screen-write.c b/screen-write.c index 7dace38a..9d710397 100644 --- a/screen-write.c +++ b/screen-write.c @@ -75,6 +75,9 @@ screen_write_start(struct screen_write_ctx *ctx, struct window_pane *wp, TAILQ_INIT(&ctx->list[y].items); ctx->item = xcalloc(1, sizeof *ctx->item); + ctx->scrolled = 0; + ctx->bg = 8; + if (wp != NULL) snprintf(tmp, sizeof tmp, "pane %%%u", wp->id); log_debug("%s: size %ux%u, %s", __func__, screen_size_x(ctx->s), @@ -810,15 +813,16 @@ screen_write_cursormove(struct screen_write_ctx *ctx, u_int px, u_int py) /* Reverse index (up with scroll). */ void -screen_write_reverseindex(struct screen_write_ctx *ctx) +screen_write_reverseindex(struct screen_write_ctx *ctx, u_int bg) { struct screen *s = ctx->s; struct tty_ctx ttyctx; screen_write_initctx(ctx, &ttyctx); + ttyctx.bg = bg; if (s->cy == s->rupper) - grid_view_scroll_region_down(s->grid, s->rupper, s->rlower); + grid_view_scroll_region_down(s->grid, s->rupper, s->rlower, bg); else if (s->cy > 0) s->cy--; @@ -852,7 +856,7 @@ screen_write_scrollregion(struct screen_write_ctx *ctx, u_int rupper, /* Line feed. */ void -screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped) +screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped, u_int bg) { struct screen *s = ctx->s; struct grid *gd = s->grid; @@ -867,8 +871,13 @@ screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped) log_debug("%s: at %u,%u (region %u-%u)", __func__, s->cx, s->cy, s->rupper, s->rlower); + if (bg != ctx->bg) { + screen_write_collect_flush(ctx, 1); + ctx->bg = bg; + } + if (s->cy == s->rlower) { - grid_view_scroll_region_up(gd, s->rupper, s->rlower); + grid_view_scroll_region_up(gd, s->rupper, s->rlower, bg); screen_write_collect_scroll(ctx); ctx->scrolled++; } else if (s->cy < screen_size_y(s) - 1) @@ -877,7 +886,7 @@ screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped) /* Scroll up. */ void -screen_write_scrollup(struct screen_write_ctx *ctx, u_int lines) +screen_write_scrollup(struct screen_write_ctx *ctx, u_int lines, u_int bg) { struct screen *s = ctx->s; struct grid *gd = s->grid; @@ -888,8 +897,13 @@ screen_write_scrollup(struct screen_write_ctx *ctx, u_int lines) else if (lines > s->rlower - s->rupper + 1) lines = s->rlower - s->rupper + 1; + if (bg != ctx->bg) { + screen_write_collect_flush(ctx, 1); + ctx->bg = bg; + } + for (i = 0; i < lines; i++) { - grid_view_scroll_region_up(gd, s->rupper, s->rlower); + grid_view_scroll_region_up(gd, s->rupper, s->rlower, bg); screen_write_collect_scroll(ctx); } ctx->scrolled += lines; @@ -1044,9 +1058,12 @@ screen_write_collect_flush(struct screen_write_ctx *ctx, int scroll_only) screen_write_initctx(ctx, &ttyctx); ttyctx.num = ctx->scrolled; + ttyctx.bg = ctx->bg; tty_write(tty_cmd_scrollup, &ttyctx); } ctx->scrolled = 0; + ctx->bg = 8; + if (scroll_only) return; @@ -1141,7 +1158,7 @@ screen_write_collect_add(struct screen_write_ctx *ctx, if (s->cx > sx - 1) { log_debug("%s: wrapped at %u,%u", __func__, s->cx, s->cy); ci->wrapped = 1; - screen_write_linefeed(ctx, 1); + screen_write_linefeed(ctx, 1, 8); s->cx = 0; } @@ -1202,7 +1219,7 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc) /* Check this will fit on the current line and wrap if not. */ if ((s->mode & MODE_WRAP) && s->cx > sx - width) { - screen_write_linefeed(ctx, 1); + screen_write_linefeed(ctx, 1, 8); s->cx = 0; } diff --git a/server-fn.c b/server-fn.c index 0e66ee34..b1e52aa8 100644 --- a/server-fn.c +++ b/server-fn.c @@ -299,7 +299,7 @@ server_destroy_pane(struct window_pane *wp, int notify) screen_write_start(&ctx, wp, &wp->base); screen_write_scrollregion(&ctx, 0, screen_size_y(ctx.s) - 1); screen_write_cursormove(&ctx, 0, screen_size_y(ctx.s) - 1); - screen_write_linefeed(&ctx, 1); + screen_write_linefeed(&ctx, 1, 8); memcpy(&gc, &grid_default_cell, sizeof gc); gc.attr |= GRID_ATTR_BRIGHT; screen_write_puts(&ctx, &gc, "Pane is dead"); diff --git a/tmux.h b/tmux.h index bfe7df3a..0373ba0e 100644 --- a/tmux.h +++ b/tmux.h @@ -672,6 +672,7 @@ struct screen_write_ctx { struct screen_write_collect_item *item; struct screen_write_collect_line *list; u_int scrolled; + u_int bg; u_int cells; u_int written; @@ -1931,7 +1932,7 @@ void grid_destroy(struct grid *); int grid_compare(struct grid *, struct grid *); void grid_collect_history(struct grid *, u_int); void grid_scroll_history(struct grid *, u_int); -void grid_scroll_history_region(struct grid *, u_int, u_int); +void grid_scroll_history_region(struct grid *, u_int, u_int, u_int); void grid_clear_history(struct grid *); const struct grid_line *grid_peek_line(struct grid *, u_int); void grid_get_cell(struct grid *, u_int, u_int, struct grid_cell *); @@ -1956,8 +1957,8 @@ void grid_view_set_cells(struct grid *, u_int, u_int, const struct grid_cell *, const char *, size_t); void grid_view_clear_history(struct grid *, u_int); void grid_view_clear(struct grid *, u_int, u_int, u_int, u_int, u_int); -void grid_view_scroll_region_up(struct grid *, u_int, u_int); -void grid_view_scroll_region_down(struct grid *, u_int, u_int); +void grid_view_scroll_region_up(struct grid *, u_int, u_int, u_int); +void grid_view_scroll_region_down(struct grid *, u_int, u_int, u_int); void grid_view_insert_lines(struct grid *, u_int, u_int, u_int); void grid_view_insert_lines_region(struct grid *, u_int, u_int, u_int, u_int); @@ -2004,10 +2005,10 @@ void screen_write_clearline(struct screen_write_ctx *, u_int); void screen_write_clearendofline(struct screen_write_ctx *, u_int); void screen_write_clearstartofline(struct screen_write_ctx *, u_int); void screen_write_cursormove(struct screen_write_ctx *, u_int, u_int); -void screen_write_reverseindex(struct screen_write_ctx *); +void screen_write_reverseindex(struct screen_write_ctx *, u_int); void screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int); -void screen_write_linefeed(struct screen_write_ctx *, int); -void screen_write_scrollup(struct screen_write_ctx *, u_int); +void screen_write_linefeed(struct screen_write_ctx *, int, u_int); +void screen_write_scrollup(struct screen_write_ctx *, u_int, u_int); void screen_write_carriagereturn(struct screen_write_ctx *); void screen_write_clearendofscreen(struct screen_write_ctx *, u_int); void screen_write_clearstartofscreen(struct screen_write_ctx *, u_int); diff --git a/tty.c b/tty.c index 00460574..a16fa474 100644 --- a/tty.c +++ b/tty.c @@ -1141,18 +1141,20 @@ tty_cmd_clearstartofline(struct tty *tty, const struct tty_ctx *ctx) void tty_cmd_reverseindex(struct tty *tty, const struct tty_ctx *ctx) { + struct window_pane *wp = ctx->wp; + if (ctx->ocy != ctx->orupper) return; if (!tty_pane_full_width(tty, ctx) || - tty_fake_bce(tty, ctx->wp, 8) || + tty_fake_bce(tty, wp, 8) || !tty_term_has(tty->term, TTYC_CSR) || !tty_term_has(tty->term, TTYC_RI)) { tty_redraw_region(tty, ctx); return; } - tty_attributes(tty, &grid_default_cell, ctx->wp); + tty_default_attributes(tty, wp, ctx->bg); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_off(tty); @@ -1176,7 +1178,7 @@ tty_cmd_linefeed(struct tty *tty, const struct tty_ctx *ctx) return; } - tty_attributes(tty, &grid_default_cell, wp); + tty_default_attributes(tty, wp, ctx->bg); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_pane(tty, ctx); @@ -1207,7 +1209,7 @@ tty_cmd_scrollup(struct tty *tty, const struct tty_ctx *ctx) return; } - tty_attributes(tty, &grid_default_cell, wp); + tty_default_attributes(tty, wp, ctx->bg); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_pane(tty, ctx); diff --git a/window-copy.c b/window-copy.c index 424ca28d..6d1a9f69 100644 --- a/window-copy.c +++ b/window-copy.c @@ -321,7 +321,7 @@ window_copy_vadd(struct window_pane *wp, const char *fmt, va_list ap) * (so it's on a new line). */ screen_write_carriagereturn(&back_ctx); - screen_write_linefeed(&back_ctx, 0); + screen_write_linefeed(&back_ctx, 0, 8); } else data->backing_written = 1; old_cy = backing->cy;