From 9c89f7c2af748858e784e8c533c548460bd6b10e Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 21 Jun 2022 09:30:01 +0000 Subject: [PATCH] Store time lines are scrolled into history and display in copy mode. --- format.c | 13 ++++++++----- grid.c | 2 ++ server.c | 4 ++++ tmux.h | 3 +++ window-copy.c | 33 ++++++++++++++++++++------------- 5 files changed, 37 insertions(+), 18 deletions(-) diff --git a/format.c b/format.c index d085e348..69d8ef34 100644 --- a/format.c +++ b/format.c @@ -3387,12 +3387,12 @@ format_quote_style(const char *s) } /* Make a prettier time. */ -static char * -format_pretty_time(time_t t) +char * +format_pretty_time(time_t t, int seconds) { struct tm now_tm, tm; time_t now, age; - char s[6]; + char s[9]; time(&now); if (now < t) @@ -3404,7 +3404,10 @@ format_pretty_time(time_t t) /* Last 24 hours. */ if (age < 24 * 3600) { - strftime(s, sizeof s, "%H:%M", &tm); + if (seconds) + strftime(s, sizeof s, "%H:%M:%S", &tm); + else + strftime(s, sizeof s, "%H:%M", &tm); return (xstrdup(s)); } @@ -3509,7 +3512,7 @@ found: if (t == 0) return (NULL); if (modifiers & FORMAT_PRETTY) - found = format_pretty_time(t); + found = format_pretty_time(t, 0); else { if (time_format != NULL) { localtime_r(&t, &tm); diff --git a/grid.c b/grid.c index 1109ac58..ba251e70 100644 --- a/grid.c +++ b/grid.c @@ -399,6 +399,7 @@ grid_scroll_history(struct grid *gd, u_int bg) gd->hscrolled++; grid_compact_line(&gd->linedata[gd->hsize]); + gd->linedata[gd->hsize].time = current_time; gd->hsize++; } @@ -438,6 +439,7 @@ grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower, u_int bg) /* Move the line into the history. */ memcpy(gl_history, gl_upper, sizeof *gl_history); + gl_history->time = current_time; /* Then move the region up and clear the bottom line. */ memmove(gl_upper, gl_upper + 1, (lower - upper) * sizeof *gl_upper); diff --git a/server.c b/server.c index 3a2580a9..5cbe3921 100644 --- a/server.c +++ b/server.c @@ -55,6 +55,8 @@ struct cmd_find_state marked_pane; static u_int message_next; struct message_list message_log; +time_t current_time; + static int server_loop(void); static void server_send_exit(void); static void server_accept(int, short, void *); @@ -257,6 +259,8 @@ server_loop(void) struct client *c; u_int items; + current_time = time (NULL); + do { items = cmdq_next(NULL); TAILQ_FOREACH(c, &clients, entry) { diff --git a/tmux.h b/tmux.h index ed347c80..c77b77c7 100644 --- a/tmux.h +++ b/tmux.h @@ -725,6 +725,7 @@ struct grid_line { u_int extdsize; int flags; + time_t time; }; /* Entire grid of cells. */ @@ -2095,6 +2096,7 @@ void format_add_cb(struct format_tree *, const char *, format_cb); void format_log_debug(struct format_tree *, const char *); void format_each(struct format_tree *, void (*)(const char *, const char *, void *), void *); +char *format_pretty_time(time_t, int); char *format_expand_time(struct format_tree *, const char *); char *format_expand(struct format_tree *, const char *); char *format_single(struct cmdq_item *, const char *, @@ -2587,6 +2589,7 @@ extern struct tmuxproc *server_proc; extern struct clients clients; extern struct cmd_find_state marked_pane; extern struct message_list message_log; +extern time_t current_time; void server_set_marked(struct session *, struct winlink *, struct window_pane *); void server_clear_marked(void); diff --git a/window-copy.c b/window-copy.c index 09304218..b955d222 100644 --- a/window-copy.c +++ b/window-copy.c @@ -4092,8 +4092,9 @@ 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]; + char hdr[512], tmp[256], *t; size_t size = 0; u_int hsize = screen_hsize(data->backing); @@ -4107,23 +4108,29 @@ window_copy_write_line(struct window_mode_entry *wme, mkgc.flags |= GRID_FLAG_NOPALETTE; 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) [%u/%u]", data->oy, hsize); - } else { - size = xsnprintf(hdr, sizeof hdr, - "[%u/%u]", data->oy, hsize); - } + "(timed out) %s", tmp); + } else + size = xsnprintf(hdr, sizeof hdr, "%s", tmp); } else { - if (data->searchcount == -1) { + if (data->searchcount == -1) + size = xsnprintf(hdr, sizeof hdr, "%s", tmp); + else { size = xsnprintf(hdr, sizeof hdr, - "[%u/%u]", data->oy, hsize); - } else { - size = xsnprintf(hdr, sizeof hdr, - "(%d%s results) [%u/%u]", data->searchcount, - data->searchmore ? "+" : "", data->oy, - hsize); + "(%d%s results) %s", data->searchcount, + data->searchmore ? "+" : "", tmp); } } if (size > screen_size_x(s))