Change relative time for now to only work in the past and not show a

sign which is more useful. Also tidy up some minor style nits.
This commit is contained in:
nicm
2026-06-13 08:59:52 +00:00
parent b3deb9ec86
commit 34a6a9d3a1
5 changed files with 22 additions and 28 deletions

View File

@@ -190,10 +190,11 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
}
if (args_has(args, 'k') || args_has(args, 'm')) {
options_set_number(new_wp->options, "remain-on-exit", 3);
if (args_has(args, 'm'))
if (args_has(args, 'm')) {
options_set_string(new_wp->options,
"remain-on-exit-format",
0, "%s", args_get(args, 'm'));
"remain-on-exit-format", 0, "%s",
args_get(args, 'm'));
}
}
if (args_has(args, 'T')) {
title = format_single_from_target(item, args_get(args, 'T'));

View File

@@ -4052,18 +4052,14 @@ format_relative_time(time_t t)
{
time_t now, age;
u_int d, h, m, s;
char out[32], sign;
char out[32];
time(&now);
if (t > now)
return (NULL);
if (t == now)
return (xstrdup("0s"));
if (t > now) {
sign = '+';
age = t - now;
} else {
sign = '-';
age = now - t;
}
age = now - t;
d = age / 86400;
h = (age % 86400) / 3600;
@@ -4072,21 +4068,21 @@ format_relative_time(time_t t)
if (d != 0) {
if (h != 0)
xsnprintf(out, sizeof out, "%c%ud%uh", sign, d, h);
xsnprintf(out, sizeof out, "%ud%uh", d, h);
else
xsnprintf(out, sizeof out, "%c%ud", sign, d);
xsnprintf(out, sizeof out, "%ud", d);
} else if (h != 0) {
if (m != 0)
xsnprintf(out, sizeof out, "%c%uh%um", sign, h, m);
xsnprintf(out, sizeof out, "%uh%um", h, m);
else
xsnprintf(out, sizeof out, "%c%uh", sign, h);
xsnprintf(out, sizeof out, "%uh", h);
} else if (m != 0) {
if (s != 0)
xsnprintf(out, sizeof out, "%c%um%us", sign, m, s);
xsnprintf(out, sizeof out, "%um%us", m, s);
else
xsnprintf(out, sizeof out, "%c%um", sign, m);
xsnprintf(out, sizeof out, "%um", m);
} else
xsnprintf(out, sizeof out, "%c%us", sign, s);
xsnprintf(out, sizeof out, "%us", s);
return (xstrdup(out));
}
@@ -5183,7 +5179,8 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
else if (fm->argc >= 2 &&
strchr(fm->argv[0], 'f') != NULL) {
free(time_format);
time_format = format_strip(es, fm->argv[1]);
time_format = format_strip(es,
fm->argv[1]);
}
break;
case 'q':

4
tmux.1
View File

@@ -6410,9 +6410,9 @@ will use shorter but less accurate time format for times in the past.
.Ql r
.Pq Ql t/r
will show the time relative to the current time, for example
.Ql \-1m
.Ql \1m
or
.Ql +2m23s .
.Ql 2m23s .
A custom format may be given using an
.Ql f
suffix (note that

View File

@@ -175,7 +175,7 @@ window_clock_init(struct window_mode_entry *wme,
struct window_clock_mode_data *data;
struct screen *s;
wme->data = data = xmalloc(sizeof *data);
wme->data = data = xcalloc(1, sizeof *data);
data->tim = time(NULL);
evtimer_set(&data->timer, window_clock_timer_callback, wme);

View File

@@ -5102,14 +5102,10 @@ window_copy_set_line_numbers(struct window_pane *wp, int enabled)
struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
struct window_copy_mode_data *data;
if (wme == NULL)
return;
if (wme->mode != &window_copy_mode)
if (wme == NULL || wme->mode != &window_copy_mode)
return;
data = wme->data;
if (data == NULL)
return;
if (data->line_numbers == enabled)
if (data == NULL || data->line_numbers == enabled)
return;
data->line_numbers = enabled;
window_copy_redraw_screen(wme);