From a711f92af97076651e3e4ccbabd29d9ec3e33a60 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. --- usr.bin/tmux/format.c | 15 +++++++++------ usr.bin/tmux/grid.c | 4 +++- usr.bin/tmux/server.c | 6 +++++- usr.bin/tmux/tmux.h | 5 ++++- usr.bin/tmux/window-copy.c | 35 +++++++++++++++++++++-------------- 5 files changed, 42 insertions(+), 23 deletions(-) diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index d040c45a65a..02d1ac33d7d 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.304 2022/05/30 13:07:06 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.305 2022/06/21 09:30:01 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott @@ -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/usr.bin/tmux/grid.c b/usr.bin/tmux/grid.c index 9935067ee3c..a018975f659 100644 --- a/usr.bin/tmux/grid.c +++ b/usr.bin/tmux/grid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grid.c,v 1.123 2022/03/30 07:05:26 nicm Exp $ */ +/* $OpenBSD: grid.c,v 1.124 2022/06/21 09:30:01 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -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/usr.bin/tmux/server.c b/usr.bin/tmux/server.c index ef1183146a5..f98ea710ee5 100644 --- a/usr.bin/tmux/server.c +++ b/usr.bin/tmux/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.201 2022/05/30 12:48:57 nicm Exp $ */ +/* $OpenBSD: server.c,v 1.202 2022/06/21 09:30:01 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -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/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 2b38b9f1e5c..9f9e3bc1870 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1174 2022/06/17 07:28:05 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1175 2022/06/21 09:30:01 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -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/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c index a6a02ab5217..e99c021ee49 100644 --- a/usr.bin/tmux/window-copy.c +++ b/usr.bin/tmux/window-copy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-copy.c,v 1.335 2022/06/09 09:12:55 nicm Exp $ */ +/* $OpenBSD: window-copy.c,v 1.336 2022/06/21 09:30:01 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -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) { - size = xsnprintf(hdr, sizeof hdr, - "[%u/%u]", data->oy, hsize); - } else { + if (data->searchcount == -1) + size = xsnprintf(hdr, sizeof hdr, "%s", tmp); + 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)) -- 2.20.1