From e0638c48cd3f23be7480b1e5d7e6f5bae2c5d348 Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 5 Oct 2024 00:32:55 +0000 Subject: [PATCH 1/2] Add copy-mode-position-format to configure the position indicator. --- options-table.c | 12 ++++++++++++ screen-write.c | 22 +++++++++++++++++----- tmux.1 | 2 ++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/options-table.c b/options-table.c index c6b2695f..084be7e4 100644 --- a/options-table.c +++ b/options-table.c @@ -971,6 +971,18 @@ const struct options_table_entry options_table[] = { .text = "Style of the marked line in copy mode." }, + { .name = "copy-mode-position-format", + .type = OPTIONS_TABLE_STRING, + .scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE, + .default_str = "#[align=right]" + "#{t/p:top_line_time}#{?#{e|>:#{top_line_time},0}, ,}" + "[#{scroll_position}/#{history_size}]" + "#{?search_timed_out, (timed out)," + "#{?search_count, (#{search_count}" + "#{?search_count_partial,+,} results),}}", + .text = "Format of the position indicator in copy mode." + }, + { .name = "fill-character", .type = OPTIONS_TABLE_STRING, .scope = OPTIONS_TABLE_WINDOW, diff --git a/screen-write.c b/screen-write.c index fe58ee48..793ad556 100644 --- a/screen-write.c +++ b/screen-write.c @@ -567,9 +567,11 @@ screen_write_fast_copy(struct screen_write_ctx *ctx, struct screen *src, u_int px, u_int py, u_int nx, u_int ny) { struct screen *s = ctx->s; + struct window_pane *wp = ctx->wp; + struct tty_ctx ttyctx; struct grid *gd = src->grid; struct grid_cell gc; - u_int xx, yy, cx, cy; + u_int xx, yy, cx = s->cx, cy = s->cy; if (nx == 0 || ny == 0) return; @@ -578,18 +580,28 @@ screen_write_fast_copy(struct screen_write_ctx *ctx, struct screen *src, for (yy = py; yy < py + ny; yy++) { if (yy >= gd->hsize + gd->sy) break; - cx = s->cx; + s->cx = cx; + if (wp != NULL) + screen_write_initctx(ctx, &ttyctx, 0); for (xx = px; xx < px + nx; xx++) { if (xx >= grid_get_line(gd, yy)->cellsize) break; grid_get_cell(gd, xx, yy, &gc); if (xx + gc.data.width > px + nx) break; - grid_view_set_cell(ctx->s->grid, cx, cy, &gc); - cx++; + grid_view_set_cell(ctx->s->grid, s->cx, s->cy, &gc); + if (wp != NULL) { + ttyctx.cell = &gc; + tty_write(tty_cmd_cell, &ttyctx); + ttyctx.ocx++; + } + s->cx++; } - cy++; + s->cy++; } + + s->cx = cx; + s->cy = cy; } /* Select character set for drawing border lines. */ diff --git a/tmux.1 b/tmux.1 index 77b9ae05..a964fb04 100644 --- a/tmux.1 +++ b/tmux.1 @@ -4833,6 +4833,8 @@ see the .Sx STYLES section. .Pp +.It Ic copy-mode-position-format Ar format +Format of the position indicator in copy mode. .It Xo Ic mode-keys .Op Ic vi | emacs .Xc From 455a2b370588d968d212b3985e9fe482bfe2d411 Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 5 Oct 2024 00:35:35 +0000 Subject: [PATCH 2/2] Remove some debugging left behind. --- window-copy.c | 61 ++++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/window-copy.c b/window-copy.c index 4e3656c7..7c8436f1 100644 --- a/window-copy.c +++ b/window-copy.c @@ -815,6 +815,11 @@ static void window_copy_formats(struct window_mode_entry *wme, struct format_tree *ft) { struct window_copy_mode_data *data = wme->data; + u_int hsize = screen_hsize(data->backing); + struct grid_line *gl; + + gl = grid_get_line(data->backing->grid, hsize - data->oy); + format_add(ft, "top_line_time", "%llu", (unsigned long long)gl->time); format_add(ft, "scroll_position", "%d", data->oy); format_add(ft, "rectangle_toggle", "%d", data->rectflag); @@ -842,6 +847,7 @@ window_copy_formats(struct window_mode_entry *wme, struct format_tree *ft) } format_add(ft, "search_present", "%d", data->searchmark != NULL); + format_add(ft, "search_timed_out", "%d", data->timeout); if (data->searchcount != -1) { format_add(ft, "search_count", "%d", data->searchcount); format_add(ft, "search_count_partial", "%d", data->searchmore); @@ -4190,11 +4196,12 @@ window_copy_write_line(struct window_mode_entry *wme, struct window_copy_mode_data *data = wme->data; struct screen *s = &data->screen; struct options *oo = wp->window->options; - struct grid_line *gl; struct grid_cell gc, mgc, cgc, mkgc; - char hdr[512], tmp[256], *t; - size_t size = 0; + u_int sx = screen_size_x(s); u_int hsize = screen_hsize(data->backing); + const char *value; + char *expanded; + struct format_tree *ft; style_apply(&gc, oo, "mode-style", NULL); gc.flags |= GRID_FLAG_NOPALETTE; @@ -4205,42 +4212,21 @@ window_copy_write_line(struct window_mode_entry *wme, style_apply(&mkgc, oo, "copy-mode-mark-style", NULL); mkgc.flags |= GRID_FLAG_NOPALETTE; + window_copy_write_one(wme, ctx, py, hsize - data->oy + py, + screen_size_x(s), &mgc, &cgc, &mkgc); + if (py == 0 && s->rupper < s->rlower && !data->hide_position) { - gl = grid_get_line(data->backing->grid, hsize - data->oy); - if (gl->time == 0) - xsnprintf(tmp, sizeof tmp, "[%u/%u]", data->oy, hsize); - else { - t = format_pretty_time(gl->time, 1); - xsnprintf(tmp, sizeof tmp, "%s [%u/%u]", t, data->oy, - hsize); - free(t); - } - - if (data->searchmark == NULL) { - if (data->timeout) { - size = xsnprintf(hdr, sizeof hdr, - "(timed out) %s", tmp); - } else - size = xsnprintf(hdr, sizeof hdr, "%s", tmp); - } else { - if (data->searchcount == -1) - size = xsnprintf(hdr, sizeof hdr, "%s", tmp); - else { - size = xsnprintf(hdr, sizeof hdr, - "(%d%s results) %s", data->searchcount, - data->searchmore ? "+" : "", tmp); + value = options_get_string(oo, "copy-mode-position-format"); + if (*value != '\0') { + ft = format_create_defaults(NULL, NULL, NULL, NULL, wp); + expanded = format_expand(ft, value); + if (*expanded != '\0') { + screen_write_cursormove(ctx, 0, 0, 0); + format_draw(ctx, &gc, sx, expanded, NULL, 0); } + free(expanded); + format_free(ft); } - if (size > screen_size_x(s)) - size = screen_size_x(s); - screen_write_cursormove(ctx, screen_size_x(s) - size, 0, 0); - screen_write_puts(ctx, &gc, "%s", hdr); - } else - size = 0; - - if (size < screen_size_x(s)) { - window_copy_write_one(wme, ctx, py, hsize - data->oy + py, - screen_size_x(s) - size, &mgc, &cgc, &mkgc); } if (py == data->cy && data->cx == screen_size_x(s)) { @@ -4673,7 +4659,8 @@ window_copy_copy_buffer(struct window_mode_entry *wme, const char *prefix, struct window_pane *wp = wme->wp; struct screen_write_ctx ctx; - if (set_clip && options_get_number(global_options, "set-clipboard") != 0) { + if (set_clip && + options_get_number(global_options, "set-clipboard") != 0) { screen_write_start_pane(&ctx, wp, NULL); screen_write_setselection(&ctx, "", buf, len); screen_write_stop(&ctx);