From 45f4ff54850ff9b448070a96b33e63451f973e33 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 5 Aug 2019 06:42:02 +0000 Subject: [PATCH] Add support for the SD (scroll down) escape sequence, GitHub issue 1861. --- input.c | 7 +++++++ screen-write.c | 25 +++++++++++++++++++++++++ tmux.h | 3 +++ tty-term.c | 1 + tty.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 5 files changed, 76 insertions(+), 4 deletions(-) diff --git a/input.c b/input.c index ff8d7a17..f37f8fd8 100644 --- a/input.c +++ b/input.c @@ -244,6 +244,7 @@ enum input_csi_type { INPUT_CSI_RM, INPUT_CSI_RM_PRIVATE, INPUT_CSI_SCP, + INPUT_CSI_SD, INPUT_CSI_SGR, INPUT_CSI_SM, INPUT_CSI_SM_PRIVATE, @@ -270,6 +271,7 @@ static const struct input_table_entry input_csi_table[] = { { 'M', "", INPUT_CSI_DL }, { 'P', "", INPUT_CSI_DCH }, { 'S', "", INPUT_CSI_SU }, + { 'T', "", INPUT_CSI_SD }, { 'X', "", INPUT_CSI_ECH }, { 'Z', "", INPUT_CSI_CBT }, { '`', "", INPUT_CSI_HPA }, @@ -1525,6 +1527,11 @@ input_csi_dispatch(struct input_ctx *ictx) if (n != -1) screen_write_scrollup(sctx, n, bg); break; + case INPUT_CSI_SD: + n = input_get(ictx, 0, 1, 1); + if (n != -1) + screen_write_scrolldown(sctx, n, bg); + break; case INPUT_CSI_TBC: switch (input_get(ictx, 0, 0, 0)) { case -1: diff --git a/screen-write.c b/screen-write.c index 98cdf158..66053eaf 100644 --- a/screen-write.c +++ b/screen-write.c @@ -1088,6 +1088,31 @@ screen_write_scrollup(struct screen_write_ctx *ctx, u_int lines, u_int bg) ctx->scrolled += lines; } +/* Scroll down. */ +void +screen_write_scrolldown(struct screen_write_ctx *ctx, u_int lines, u_int bg) +{ + struct screen *s = ctx->s; + struct grid *gd = s->grid; + struct tty_ctx ttyctx; + u_int i; + + screen_write_initctx(ctx, &ttyctx); + ttyctx.bg = bg; + + 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_down(gd, s->rupper, s->rlower, bg); + + screen_write_collect_flush(ctx, 0); + ttyctx.num = lines; + tty_write(tty_cmd_scrolldown, &ttyctx); +} + /* Carriage return (cursor to start of line). */ void screen_write_carriagereturn(struct screen_write_ctx *ctx) diff --git a/tmux.h b/tmux.h index 076a5fe6..ef24717b 100644 --- a/tmux.h +++ b/tmux.h @@ -420,6 +420,7 @@ enum tty_code_code { TTYC_REV, TTYC_RGB, TTYC_RI, + TTYC_RIN, TTYC_RMACS, TTYC_RMCUP, TTYC_RMKX, @@ -1925,6 +1926,7 @@ void tty_cmd_insertcharacter(struct tty *, const struct tty_ctx *); void tty_cmd_insertline(struct tty *, const struct tty_ctx *); void tty_cmd_linefeed(struct tty *, const struct tty_ctx *); void tty_cmd_scrollup(struct tty *, const struct tty_ctx *); +void tty_cmd_scrolldown(struct tty *, const struct tty_ctx *); void tty_cmd_reverseindex(struct tty *, const struct tty_ctx *); void tty_cmd_setselection(struct tty *, const struct tty_ctx *); void tty_cmd_rawstring(struct tty *, const struct tty_ctx *); @@ -2301,6 +2303,7 @@ 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, u_int); void screen_write_scrollup(struct screen_write_ctx *, u_int, u_int); +void screen_write_scrolldown(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-term.c b/tty-term.c index 39e2b013..774dc9ed 100644 --- a/tty-term.c +++ b/tty-term.c @@ -239,6 +239,7 @@ static const struct tty_term_code_entry tty_term_codes[] = { [TTYC_REV] = { TTYCODE_STRING, "rev" }, [TTYC_RGB] = { TTYCODE_FLAG, "RGB" }, [TTYC_RI] = { TTYCODE_STRING, "ri" }, + [TTYC_RIN] = { TTYCODE_STRING, "rin" }, [TTYC_RMACS] = { TTYCODE_STRING, "rmacs" }, [TTYC_RMCUP] = { TTYCODE_STRING, "rmcup" }, [TTYC_RMKX] = { TTYCODE_STRING, "rmkx" }, diff --git a/tty.c b/tty.c index 024aef27..1658fb74 100644 --- a/tty.c +++ b/tty.c @@ -1558,10 +1558,11 @@ tty_cmd_reverseindex(struct tty *tty, const struct tty_ctx *ctx) return; if (ctx->bigger || - !tty_pane_full_width(tty, ctx) || + (!tty_pane_full_width(tty, ctx) && !tty_use_margin(tty)) || tty_fake_bce(tty, wp, 8) || !tty_term_has(tty->term, TTYC_CSR) || - !tty_term_has(tty->term, TTYC_RI) || + (!tty_term_has(tty->term, TTYC_RI) && + !tty_term_has(tty->term, TTYC_RIN)) || ctx->wp->sx == 1 || ctx->wp->sy == 1) { tty_redraw_region(tty, ctx); @@ -1571,10 +1572,13 @@ tty_cmd_reverseindex(struct tty *tty, const struct tty_ctx *ctx) tty_default_attributes(tty, wp, ctx->bg); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); - tty_margin_off(tty); + tty_margin_pane(tty, ctx); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->orupper); - tty_putcode(tty, TTYC_RI); + if (tty_term_has(tty->term, TTYC_RI)) + tty_putcode(tty, TTYC_RI); + else + tty_putcode1(tty, TTYC_RIN, 1); } void @@ -1652,6 +1656,38 @@ tty_cmd_scrollup(struct tty *tty, const struct tty_ctx *ctx) } } +void +tty_cmd_scrolldown(struct tty *tty, const struct tty_ctx *ctx) +{ + struct window_pane *wp = ctx->wp; + u_int i; + + if (ctx->bigger || + (!tty_pane_full_width(tty, ctx) && !tty_use_margin(tty)) || + tty_fake_bce(tty, wp, 8) || + !tty_term_has(tty->term, TTYC_CSR) || + (!tty_term_has(tty->term, TTYC_RI) && + !tty_term_has(tty->term, TTYC_RIN)) || + wp->sx == 1 || + wp->sy == 1) { + tty_redraw_region(tty, ctx); + return; + } + + tty_default_attributes(tty, wp, ctx->bg); + + tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); + tty_margin_pane(tty, ctx); + tty_cursor_pane(tty, ctx, ctx->ocx, ctx->orupper); + + if (tty_term_has(tty->term, TTYC_RIN)) + tty_putcode1(tty, TTYC_RIN, ctx->num); + else { + for (i = 0; i < ctx->num; i++) + tty_putcode(tty, TTYC_RI); + } +} + void tty_cmd_clearendofscreen(struct tty *tty, const struct tty_ctx *ctx) {