diff options
author | nicm <nicm> | 2017-02-08 17:31:09 +0000 |
---|---|---|
committer | nicm <nicm> | 2017-02-08 17:31:09 +0000 |
commit | e100d465daefd20da0bb5eea87c4b4896badff16 (patch) | |
tree | ff477fbaf93b7acbe2245fe02b1bbf906a6d159a /screen-write.c | |
parent | 13a0b6bb3fe05454cace81f5ec7624f6fd9021a5 (diff) | |
download | rtmux-e100d465daefd20da0bb5eea87c4b4896badff16.tar.gz rtmux-e100d465daefd20da0bb5eea87c4b4896badff16.tar.bz2 rtmux-e100d465daefd20da0bb5eea87c4b4896badff16.zip |
Add support for scroll up escape sequence (CSI S) and use it when
possible instead of sending individual line feeds.
Diffstat (limited to 'screen-write.c')
-rw-r--r-- | screen-write.c | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/screen-write.c b/screen-write.c index 761ec99f..bd615a09 100644 --- a/screen-write.c +++ b/screen-write.c @@ -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) { |