diff options
author | 2017-02-08 17:31:09 +0000 | |
---|---|---|
committer | 2017-02-08 17:31:09 +0000 | |
commit | f0063641693bf9c391e3380df0dc2de8d6de156d (patch) | |
tree | 5e006532064dcfaad83a6e6d9f5c9f0b563369f3 /usr.bin/tmux/screen-write.c | |
parent | Cleanup the device removal path (diff) | |
download | wireguard-openbsd-f0063641693bf9c391e3380df0dc2de8d6de156d.tar.xz wireguard-openbsd-f0063641693bf9c391e3380df0dc2de8d6de156d.zip |
Add support for scroll up escape sequence (CSI S) and use it when
possible instead of sending individual line feeds.
Diffstat (limited to 'usr.bin/tmux/screen-write.c')
-rw-r--r-- | usr.bin/tmux/screen-write.c | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/usr.bin/tmux/screen-write.c b/usr.bin/tmux/screen-write.c index 98ee28365cc..0ab014c9589 100644 --- a/usr.bin/tmux/screen-write.c +++ b/usr.bin/tmux/screen-write.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen-write.c,v 1.109 2017/02/08 16:45:18 nicm Exp $ */ +/* $OpenBSD: screen-write.c,v 1.110 2017/02/08 17:31:09 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -839,6 +839,8 @@ screen_write_scrollregion(struct screen_write_ctx *ctx, u_int rupper, if (rupper >= rlower) /* cannot be one line */ return; + screen_write_collect_flush(ctx); + /* Cursor moves to top-left. */ s->cx = 0; s->cy = 0; @@ -854,7 +856,6 @@ screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped) struct screen *s = ctx->s; struct grid *gd = s->grid; struct grid_line *gl; - struct tty_ctx ttyctx; gl = &gd->linedata[gd->hsize + s->cy]; if (wrapped) @@ -864,14 +865,32 @@ screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped) if (s->cy == s->rlower) { grid_view_scroll_region_up(gd, s->rupper, s->rlower); - screen_write_collect_scroll(ctx); - screen_write_initctx(ctx, &ttyctx); - tty_write(tty_cmd_linefeed, &ttyctx); + ctx->scrolled++; } else if (s->cy < screen_size_y(s) - 1) s->cy++; } +/* Scroll up. */ +void +screen_write_scrollup(struct screen_write_ctx *ctx, u_int lines) +{ + struct screen *s = ctx->s; + struct grid *gd = s->grid; + u_int i; + + if (lines == 0) + lines = 1; + else if (lines > s->rlower - s->rupper + 1) + lines = s->rlower - s->rupper + 1; + + for (i = 0; i < lines; i++) { + grid_view_scroll_region_up(gd, s->rupper, s->rlower); + screen_write_collect_scroll(ctx); + } + ctx->scrolled += lines; +} + /* Carriage return (cursor to start of line). */ void screen_write_carriagereturn(struct screen_write_ctx *ctx) @@ -1009,6 +1028,18 @@ screen_write_collect_flush(struct screen_write_ctx *ctx) u_int y, cx, cy; struct tty_ctx ttyctx; + if (ctx->scrolled != 0) { + log_debug("%s: scrolled %u (region %u-%u)", __func__, + ctx->scrolled, s->rupper, s->rlower); + if (ctx->scrolled > s->rlower - s->rupper + 1) + ctx->scrolled = s->rlower - s->rupper + 1; + + screen_write_initctx(ctx, &ttyctx); + ttyctx.num = ctx->scrolled; + tty_write(tty_cmd_scrollup, &ttyctx); + } + ctx->scrolled = 0; + cx = s->cx; cy = s->cy; for (y = 0; y < screen_size_y(s); y++) { TAILQ_FOREACH_SAFE(ci, &ctx->list[y].items, entry, tmp) { |