For the *-output commands like select-output, if cmd had no output like "true" then select an empty string.

This commit is contained in:
Michael Grant
2026-10-07 14:41:35 +02:00
parent ef6a76b485
commit 18c4c9c702
3 changed files with 28 additions and 28 deletions

View File

@@ -95,9 +95,27 @@ sleep 1
$TMUX copy-mode -t :empty || exit 1
$TMUX set-buffer sentinel || exit 1
$TMUX send-keys -t :empty.0 -X copy-output || exit 1
[ "$($TMUX show-buffer)" = one ] || exit 1
[ "$($TMUX show-buffer)" = sentinel ] || exit 1
$TMUX send-keys -t :empty.0 -X select-output || exit 1
[ "$($TMUX display-message -p -t :empty.0 '#{selection_present}')" = 0 ] || exit 1
$TMUX send-keys -t :empty.0 -X cancel || exit 1
$TMUX new-window -d -n emptyprompt "printf '\\033]133;A\\007p\\$ \\033]133;B\\007echo\\033]133;C\\007one\\n\\033]133;D;0\\007\\033]133;A\\007p\\$ \\033]133;B\\007true\\n\\033]133;C\\007\\033]133;D;0\\007\\033]133;A\\007p\\$ \\033]133;B\\007'; exec sleep 100" || exit 1
sleep 1
$TMUX copy-mode -t :emptyprompt || exit 1
$TMUX set-buffer sentinel || exit 1
$TMUX send-keys -t :emptyprompt.0 -X copy-output || exit 1
[ "$($TMUX show-buffer)" = sentinel ] || exit 1
$TMUX send-keys -t :emptyprompt.0 -X cancel || exit 1
$TMUX new-window -d -n blank "printf '\\033]133;A\\007p\\$ \\033]133;B\\007echo\\n\\033]133;C\\007\\n\\033]133;D;0\\007\\033]133;A\\007p\\$ \\033]133;B\\007'; exec sleep 100" || exit 1
sleep 1
$TMUX copy-mode -t :blank || exit 1
$TMUX set-buffer sentinel || exit 1
$TMUX send-keys -t :blank.0 -X copy-output || exit 1
[ $($TMUX show-buffer | wc -c) -eq 1 ] || exit 1
$TMUX send-keys -t :blank.0 -X cancel || exit 1
$TMUX new-window -d -n prompt "printf '\\033]133;A\\007p\\$ \\033]133;B\\007echo\\033]133;C\\007one\\n\\033]133;D;0\\007\\033]133;A\\007p\\$ \\033]133;B\\007'; exec sleep 100" || exit 1
sleep 1
$TMUX copy-mode -t :prompt || exit 1

5
tmux.1
View File

@@ -2579,11 +2579,12 @@ If there is no
.Ql D
marker, the output ends at the last used cell in the copy-mode buffer,
omitting unused blank rows at the bottom.
At the following prompt or below it, they use the most recent nonempty output.
At the following prompt or below it, they use the most recent output.
With
.Fl a ,
they use the entire copy-mode buffer instead.
If no output range can be found, no text is copied, piped or opened.
If no output range can be found, or the output is empty, no text is copied,
piped or opened.
.Pp
The search commands come in several varieties:
.Ql search\-forward

View File

@@ -6246,8 +6246,6 @@ window_copy_find_output_range(struct window_mode_entry *wme, u_int *sx,
int found_start = 0, found_end = 0;
int next_prompt, in_range, end_ok;
int found;
void *buf;
size_t len;
cursor_x = data->cx;
cursor_y = screen_hsize(data->backing) + data->cy - data->oy;
@@ -6332,14 +6330,6 @@ window_copy_find_output_range(struct window_mode_entry *wme, u_int *sx,
}
window_copy_output_end(data->backing, ex, ey);
}
buf = window_copy_get_grid_range(wme, *sx, *sy, *ex, *ey, &len);
if (buf == NULL) {
log_debug("%s: empty output", __func__);
found = window_copy_find_previous_output_range(wme, cursor_x,
cursor_y, sx, sy, ex, ey);
return (found);
}
free(buf);
log_debug("%s: output from %u,%u to %u,%u", __func__, *sx, *sy,
*ex, *ey);
return (1);
@@ -6355,10 +6345,8 @@ window_copy_find_previous_output_range(struct window_mode_entry *wme,
struct grid *gd = data->backing->grid;
struct grid_line *gl;
struct osc133_data *od;
void *buf;
u_int start_x, start_y, end_x, end_y;
u_int start_x, start_y;
u_int y, total;
size_t len;
int found = 0, have_prompt = 0;
int pending = 0;
int has_start, has_end, end_first;
@@ -6398,18 +6386,11 @@ window_copy_find_previous_output_range(struct window_mode_entry *wme,
}
}
if (pending && has_end) {
end_x = od->out_end_col;
end_y = y;
buf = window_copy_get_grid_range(wme, start_x, start_y,
end_x, end_y, &len);
if (buf != NULL) {
free(buf);
*sx = start_x;
*sy = start_y;
*ex = end_x;
*ey = end_y;
found = 1;
}
*sx = start_x;
*sy = start_y;
*ex = od->out_end_col;
*ey = y;
found = 1;
pending = 0;
}
if (has_start && end_first) {