Merge branch 'master' into events

This commit is contained in:
Nicholas Marriott
2026-07-09 11:19:54 +01:00
10 changed files with 103 additions and 11 deletions

View File

@@ -127,6 +127,7 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2)
#define FORMAT_QUOTE_SHELL_SQ 0x20000000
#define FORMAT_OPTIONS 0x40000000
#define FORMAT_ENVIRON 0x80000000ULL
#define FORMAT_DIFFERENCE 0x100000000ULL
/* Limit on recursion. */
#define FORMAT_LOOP_LIMIT 100
@@ -4221,6 +4222,17 @@ format_relative_time(time_t t)
return (xstrdup(out));
}
/* Make a time difference in seconds. */
static char *
format_time_difference(time_t t)
{
time_t now = time(NULL);
char *out;
xasprintf(&out, "%ld", (long)now - (long)t);
return (out);
}
/* Find a format entry. */
static char *
format_find(struct format_tree *ft, const char *key, uint64_t modifiers,
@@ -4305,6 +4317,8 @@ found:
return (NULL);
if (modifiers & FORMAT_RELATIVE)
found = format_relative_time(t);
else if (modifiers & FORMAT_DIFFERENCE)
found = format_time_difference(t);
else if (modifiers & FORMAT_PRETTY)
found = format_pretty_time(t, 0);
else {
@@ -5684,6 +5698,8 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
modifiers |= FORMAT_PRETTY;
else if (strchr(fm->argv[0], 'r') != NULL)
modifiers |= FORMAT_RELATIVE;
else if (strchr(fm->argv[0], 'd') != NULL)
modifiers |= FORMAT_DIFFERENCE;
else if (fm->argc >= 2 &&
strchr(fm->argv[0], 'f') != NULL) {
free(time_format);

View File

@@ -244,7 +244,7 @@ popup_check_cb(struct client* c, void *data, u_int px, u_int py, u_int nx)
*/
for (i = 0; i < mr->used; i++) {
server_client_overlay_range(pd->px, pd->py, pd->sx,
pd->sy, r->ranges[i].px, py, r->ranges[i].nx,
pd->sy, mr->ranges[i].px, py, mr->ranges[i].nx,
&pd->or[i]);
}

View File

@@ -0,0 +1,37 @@
#!/bin/sh
PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -LtestA$$ -f/dev/null"
$TMUX kill-server 2>/dev/null
cleanup()
{
$TMUX kill-server 2>/dev/null
}
trap cleanup 0
trap 'exit 1' 1 2 3 15
$TMUX new -d -x40 -y10 \
'i=0; while [ $i -lt 80 ]; do echo "line $i"; i=$((i + 1)); done; cat' ||
exit 1
$TMUX set -g window-size manual || exit 1
$TMUX copy-mode -e || exit 1
$TMUX send-keys -X history-top || exit 1
$TMUX send-keys -X start-of-line || exit 1
$TMUX send-keys -X begin-selection || exit 1
$TMUX send-keys -X cursor-down || exit 1
[ "$($TMUX display-message -p '#{selection_present}')" = "1" ] || exit 1
$TMUX send-keys -N200 -X scroll-down || exit 1
[ "$($TMUX display-message -p '#{pane_in_mode} #{scroll_position}')" = "1 0" ] ||
exit 1
$TMUX send-keys -X clear-selection || exit 1
$TMUX send-keys -X scroll-down || exit 1
[ "$($TMUX display-message -p '#{pane_in_mode}')" = "0" ] || exit 1
exit 0

View File

@@ -291,6 +291,15 @@ if [ -z "$($TMUX display-message -p '#{t/r:@ts}')" ]; then
echo "Format test failed for '#{t/r:@ts}': empty result"
exit 1
fi
# t/d: difference from the current time in seconds.
diff=$($TMUX display-message -p '#{t/d:@ts}')
case "$diff" in
[0-9]*) ;;
*)
echo "Format test failed for '#{t/d:@ts}': expected positive value, got '$diff'"
exit 1
;;
esac
# t/f: custom strftime format applied to the variable's time. Tested in a
# format_expand context (list-windows -F), where a single strftime specifier is
@@ -326,6 +335,14 @@ done
# A time in the future has no relative form.
$TMUX set -g @future "$((now + 100000))"
test_format "#{t/r:@future}" ""
diff=$($TMUX display-message -p '#{t/d:@future}')
case "$diff" in
-[0-9]*) ;;
*)
echo "Format test failed for '#{t/d:@future}': expected negative value, got '$diff'"
exit 1
;;
esac
# --- Content search (C) --------------------------------------------------

View File

@@ -448,7 +448,7 @@ sleep 0.1
$TMUX new-session -d -x 1 -y 1 -s test-setup "sleep 2" || exit 1
$TMUX set-option -g history-limit "$HISTORY_LIMIT" || exit 1
$TMUX new-session -d -x 80 -y "$HEIGHT" -s stress 'cat' || exit 1
$TMUX new-session -d -x 80 -y "$HEIGHT" -s stress 'stty -echo; exec cat' || exit 1
$TMUX kill-session -t test-setup || exit 1
sleep 0.3

View File

@@ -1588,8 +1588,10 @@ redraw_draw(struct client *c, struct window_pane *wp, int flags)
struct screen *sl;
struct redraw_scene *scene;
struct window_pane *loop;
u_int width, i, y, lines;
u_int width, i, y, lines, j;
struct redraw_span *first;
struct visible_ranges *r;
struct visible_range *rr;
int redraw;
if (c->flags & CLIENT_SUSPENDED)
@@ -1694,8 +1696,16 @@ redraw_draw(struct client *c, struct window_pane *wp, int flags)
else
y = c->tty.sy - lines;
sl = c->status.active;
for (i = 0; i < lines; i++)
tty_draw_line(tty, sl, 0, i, UINT_MAX, 0, y + i, NULL);
for (i = 0; i < lines; i++) {
r = tty_check_overlay_range(tty, 0, y + i, tty->sx);
for (j = 0; j < r->used; j++) {
rr = &r->ranges[j];
if (rr->nx == 0)
continue;
tty_draw_line(tty, sl, rr->px, i, rr->nx,
rr->px, y + i, NULL);
}
}
}
if (c->overlay_draw != NULL && (flags & REDRAW_OVERLAY))
c->overlay_draw(c, c->overlay_data);

View File

@@ -3114,7 +3114,13 @@ screen_write_alternateon(struct screen_write_ctx *ctx, struct grid_cell *gc,
if (wp != NULL) {
window_pane_clear_resizes(wp, NULL);
if (event_initialized(&wp->resize_timer))
evtimer_del(&wp->resize_timer);
layout_fix_panes(wp->window, NULL);
if (!TAILQ_EMPTY(&wp->resize_queue)) {
window_pane_send_resize(wp, wp->sx, wp->sy);
window_pane_clear_resizes(wp, NULL);
}
server_redraw_window_borders(wp->window);
}

View File

@@ -216,7 +216,7 @@ spawn_window(struct spawn_context *sc, char **cause)
/* Set the name of the new window. */
if (~sc->flags & SPAWN_RESPAWN) {
free(w->name);
if (sc->name == NULL || *sc->name == '\0')
if (sc->name == NULL)
w->name = default_window_name(w);
else {
w->name = xstrdup(sc->name);

10
tmux.1
View File

@@ -2342,7 +2342,8 @@ but also exit copy mode if the cursor reaches the bottom.
.It Xo
.Ic scroll\-exit\-on
.Xc
Turn on exiting copy mode when scrolling to the end of the buffer.
Turn on exiting copy mode when scrolling to the end of the buffer, unless a
selection is present.
.It Xo
.Ic scroll\-exit\-off
.Xc
@@ -2619,6 +2620,7 @@ instead of
.Fl e
specifies that scrolling to the bottom of the history (to the visible screen)
should exit copy mode.
This will not happen if a selection is present.
While in copy mode, pressing a key other than those used for scrolling will
disable this behaviour.
This is intended to allow fast scrolling through a pane's history, for
@@ -6843,10 +6845,14 @@ Adding
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
will give the time relative to the current time, for example
.Ql \&1m
or
.Ql 2m23s .
.Ql d
.Pq Ql t/d
will give the difference from the time to current time in seconds (future
times are negative).
A custom format may be given using an
.Ql f
suffix (note that

View File

@@ -854,7 +854,7 @@ window_copy_scroll1(struct window_mode_entry *wme, struct window_pane *wp,
window_copy_cursor_end_of_line(wme);
}
if (scroll_exit && data->oy == 0) {
if (scroll_exit && data->oy == 0 && data->screen.sel == NULL) {
window_pane_reset_mode(wp);
return;
}
@@ -972,7 +972,7 @@ window_copy_pagedown1(struct window_mode_entry *wme, int half_page,
window_copy_cursor_end_of_line(wme);
}
if (scroll_exit && data->oy == 0)
if (scroll_exit && data->oy == 0 && data->screen.sel == NULL)
return (1);
if (data->searchmark != NULL && !data->timeout)
window_copy_search_marks(wme, NULL, data->searchregex, 1);
@@ -2352,7 +2352,7 @@ window_copy_cmd_scroll_down(struct window_copy_cmd_state *cs)
for (; np != 0; np--)
window_copy_cursor_down(wme, 1);
if (data->scroll_exit && data->oy == 0)
if (data->scroll_exit && data->oy == 0 && data->screen.sel == NULL)
return (WINDOW_COPY_CMD_CANCEL);
return (WINDOW_COPY_CMD_NOTHING);
}