From 7d3e2c83d4487c306fc77f22c2cc12f5842bd5ae Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 12 May 2017 10:45:38 +0000 Subject: [PATCH 1/4] Store copy mode search string in pane so search-again command works even if you exit and reenter copy mode (it doesn't remember the position, just the search string), suggested by espie@. --- format.c | 4 ++-- window-copy.c | 25 ++++++++++--------------- window.c | 1 + 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/format.c b/format.c index d6bc9ceb..eb61a00a 100644 --- a/format.c +++ b/format.c @@ -1376,8 +1376,8 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp) format_add(ft, "pane_synchronized", "%d", !!options_get_number(wp->window->options, "synchronize-panes")); - format_add(ft, "pane_search_string", "%s", - window_copy_search_string(wp)); + if (wp->searchstr != NULL) + format_add(ft, "pane_search_string", "%s", wp->searchstr); format_add(ft, "pane_tty", "%s", wp->tty); format_add(ft, "pane_pid", "%ld", (long) wp->pid); diff --git a/window-copy.c b/window-copy.c index 8424bfa6..424ca28d 100644 --- a/window-copy.c +++ b/window-copy.c @@ -208,8 +208,13 @@ window_copy_init(struct window_pane *wp) data->rectflag = 0; data->scroll_exit = 0; - data->searchtype = WINDOW_COPY_OFF; - data->searchstr = NULL; + if (wp->searchstr != NULL) { + data->searchtype = WINDOW_COPY_SEARCHUP; + data->searchstr = xstrdup(wp->searchstr); + } else { + data->searchtype = WINDOW_COPY_OFF; + data->searchstr = NULL; + } data->searchmark = NULL; data->searchx = data->searchy = data->searcho = -1; @@ -1134,6 +1139,9 @@ window_copy_search(struct window_pane *wp, int direction, int moveflag) u_int fx, fy, endline; int wrapflag, cis, found; + free(wp->searchstr); + wp->searchstr = xstrdup(data->searchstr); + fx = data->cx; fy = screen_hsize(data->backing) - data->oy + data->cy; @@ -2482,16 +2490,3 @@ window_copy_drag_update(__unused struct client *c, struct mouse_event *m) if (window_copy_update_selection(wp, 1)) window_copy_redraw_selection(wp, old_cy); } - -const char * -window_copy_search_string(struct window_pane *wp) -{ - struct window_copy_mode_data *data; - - if (wp->mode != &window_copy_mode) - return (""); - data = wp->modedata; - if (data->searchtype == WINDOW_COPY_OFF || data->searchstr == NULL) - return (""); - return (data->searchstr); -} diff --git a/window.c b/window.c index 297192b7..392a889e 100644 --- a/window.c +++ b/window.c @@ -828,6 +828,7 @@ static void window_pane_destroy(struct window_pane *wp) { window_pane_reset_mode(wp); + free(wp->searchstr); if (wp->fd != -1) { bufferevent_free(wp->event); From 886d50dcabf98d7469d982241336593acbb2e6f6 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 12 May 2017 10:50:11 +0000 Subject: [PATCH 2/4] ECH needs to use background colour. --- input.c | 3 ++- screen-write.c | 3 ++- tmux.h | 4 ++-- tty.c | 14 +++++++++++++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/input.c b/input.c index 34fa7a9c..22dd1ee2 100644 --- a/input.c +++ b/input.c @@ -1308,7 +1308,8 @@ input_csi_dispatch(struct input_ctx *ictx) } break; case INPUT_CSI_ECH: - screen_write_clearcharacter(sctx, input_get(ictx, 0, 1, 1)); + screen_write_clearcharacter(sctx, input_get(ictx, 0, 1, 1), + ictx->cell.cell.bg); break; case INPUT_CSI_DCH: screen_write_deletecharacter(sctx, input_get(ictx, 0, 1, 1), diff --git a/screen-write.c b/screen-write.c index 6631ab56..7dace38a 100644 --- a/screen-write.c +++ b/screen-write.c @@ -606,7 +606,7 @@ screen_write_deletecharacter(struct screen_write_ctx *ctx, u_int nx, u_int bg) /* Clear nx characters. */ void -screen_write_clearcharacter(struct screen_write_ctx *ctx, u_int nx) +screen_write_clearcharacter(struct screen_write_ctx *ctx, u_int nx, u_int bg) { struct screen *s = ctx->s; struct tty_ctx ttyctx; @@ -623,6 +623,7 @@ screen_write_clearcharacter(struct screen_write_ctx *ctx, u_int nx) return; screen_write_initctx(ctx, &ttyctx); + ttyctx.bg = bg; grid_view_clear(s->grid, s->cx, s->cy, nx, 1, 8); diff --git a/tmux.h b/tmux.h index a91ed2e1..bfe7df3a 100644 --- a/tmux.h +++ b/tmux.h @@ -792,6 +792,7 @@ struct window_pane { struct event modetimer; time_t modelast; u_int modeprefix; + char *searchstr; TAILQ_ENTRY(window_pane) entry; RB_ENTRY(window_pane) tree_entry; @@ -1996,7 +1997,7 @@ void screen_write_cursorleft(struct screen_write_ctx *, u_int); void screen_write_alignmenttest(struct screen_write_ctx *); void screen_write_insertcharacter(struct screen_write_ctx *, u_int, u_int); void screen_write_deletecharacter(struct screen_write_ctx *, u_int, u_int); -void screen_write_clearcharacter(struct screen_write_ctx *, u_int); +void screen_write_clearcharacter(struct screen_write_ctx *, u_int, u_int); void screen_write_insertline(struct screen_write_ctx *, u_int, u_int); void screen_write_deleteline(struct screen_write_ctx *, u_int, u_int); void screen_write_clearline(struct screen_write_ctx *, u_int); @@ -2177,7 +2178,6 @@ void window_copy_vadd(struct window_pane *, const char *, va_list); void window_copy_pageup(struct window_pane *, int); void window_copy_start_drag(struct client *, struct mouse_event *); int window_copy_scroll_position(struct window_pane *); -const char *window_copy_search_string(struct window_pane *); /* window-choose.c */ extern const struct window_mode window_choose_mode; diff --git a/tty.c b/tty.c index 18e4c3d2..e182be22 100644 --- a/tty.c +++ b/tty.c @@ -798,6 +798,7 @@ tty_clear_area(struct tty *tty, const struct window_pane *wp, u_int py, u_int ny, u_int px, u_int nx, u_int bg) { u_int yy; + char tmp[64]; log_debug("%s: %u,%u at %u,%u", __func__, nx, ny, px, py); @@ -815,6 +816,17 @@ tty_clear_area(struct tty *tty, const struct window_pane *wp, u_int py, tty_putcode(tty, TTYC_ED); return; } + + /* + * If we're setting a background colour (so it is not default), + * we can use DECFRA. + */ + if (tty->term_type == TTY_VT420 && bg != 8) { + xsnprintf(tmp, sizeof tmp, "\033[32;%u;%u;%u;%u$x", + py + 1, px + 1, py + ny, px + nx); + tty_puts(tty, tmp); + return; + } } /* Couldn't use an escape sequence, loop over the lines. */ @@ -1023,7 +1035,7 @@ tty_cmd_deletecharacter(struct tty *tty, const struct tty_ctx *ctx) void tty_cmd_clearcharacter(struct tty *tty, const struct tty_ctx *ctx) { - tty_attributes(tty, &grid_default_cell, ctx->wp); + tty_default_attributes(tty, ctx->wp, ctx->bg); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); From 7f626c89595abd5dae6716d6b6e21ea96e22a856 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 12 May 2017 11:13:43 +0000 Subject: [PATCH 3/4] Can use INDN to clear regions with default background colour if margins are supported. --- tty.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tty.c b/tty.c index e182be22..720eb417 100644 --- a/tty.c +++ b/tty.c @@ -808,6 +808,7 @@ tty_clear_area(struct tty *tty, const struct window_pane *wp, u_int py, /* If genuine BCE is available, can try escape sequences. */ if (!tty_fake_bce(tty, wp, bg)) { + /* Use ED if clearing off the bottom of the terminal. */ if (px == 0 && px + nx >= tty->sx && py + ny >= tty->sy && @@ -818,8 +819,9 @@ tty_clear_area(struct tty *tty, const struct window_pane *wp, u_int py, } /* - * If we're setting a background colour (so it is not default), - * we can use DECFRA. + * On VT420 compatible terminals we can use DECFRA if the + * background colour isn't default (because it doesn't work + * after SGR 0). */ if (tty->term_type == TTY_VT420 && bg != 8) { xsnprintf(tmp, sizeof tmp, "\033[32;%u;%u;%u;%u$x", @@ -827,6 +829,17 @@ tty_clear_area(struct tty *tty, const struct window_pane *wp, u_int py, tty_puts(tty, tmp); return; } + + /* + * If margins are supported, can just scroll the area off to + * clear it. + */ + if (tty_use_margin(tty) && tty_term_has(tty->term, TTYC_INDN)) { + tty_region(tty, py, py + ny - 1); + tty_margin(tty, px, px + nx - 1); + tty_putcode1(tty, TTYC_INDN, ny); + return; + } } /* Couldn't use an escape sequence, loop over the lines. */ From 60f7b05c0c9fbee371dac86229d888aed7b0e7f6 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 12 May 2017 11:19:24 +0000 Subject: [PATCH 4/4] Regions can't be smaller than 2 so don't try to clear them by scrolling if so. --- tty.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tty.c b/tty.c index 720eb417..00460574 100644 --- a/tty.c +++ b/tty.c @@ -834,7 +834,10 @@ tty_clear_area(struct tty *tty, const struct window_pane *wp, u_int py, * If margins are supported, can just scroll the area off to * clear it. */ - if (tty_use_margin(tty) && tty_term_has(tty->term, TTYC_INDN)) { + if (nx > 2 && + ny > 2 && + tty_use_margin(tty) && + tty_term_has(tty->term, TTYC_INDN)) { tty_region(tty, py, py + ny - 1); tty_margin(tty, px, px + nx - 1); tty_putcode1(tty, TTYC_INDN, ny);