Merge branch 'master' into command_parser

This commit is contained in:
Nicholas Marriott
2026-07-21 08:34:58 +01:00
32 changed files with 941 additions and 286 deletions

41
regress/cfg-client-lost.sh Executable file
View File

@@ -0,0 +1,41 @@
#!/bin/sh
PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMPDIR=$(mktemp -d) || exit 1
TMUX="$TEST_TMUX -S$TMPDIR/tmux.sock"
CONF="$TMPDIR/tmux.conf"
READY="$TMPDIR/ready"
cleanup()
{
$TMUX kill-server 2>/dev/null
rm -rf "$TMPDIR"
}
trap cleanup 0 1 15
cat <<EOF >$CONF
new-session -d -s keep 'sleep 1000'
run-shell -b 'touch $READY'
run-shell -d 1 true
source-file /dev/null
EOF
$TMUX -f$CONF new-session -d -s client 'sleep 100' &
pid=$!
i=0
while [ ! -f "$READY" ]; do
[ "$i" -eq 50 ] && exit 1
i=$((i + 1))
sleep 0.1
done
kill "$pid" 2>/dev/null
wait "$pid" 2>/dev/null
sleep 2
$TMUX has-session -t keep || exit 1
exit 0

View File

@@ -0,0 +1,181 @@
#!/bin/sh
# Exercise cmd_template_replace through command-prompt, which passes prompt
# input as argv to args_make_commands. This covers the quoting modes, indexed
# replacements, and cases where replacements are intentionally not made.
PATH=/bin:/usr/bin
TERM=screen
LC_ALL=C.UTF-8
LANG=C.UTF-8
export TERM LC_ALL LANG
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMP=$(mktemp -d) || exit 1
TMUX_TMPDIR="$TMP"
export TMUX_TMPDIR
OUT="$TEST_TMUX -LtestA$$ -f/dev/null"
IN="$TEST_TMUX -LtestB$$ -f/dev/null"
cleanup()
{
$OUT kill-server 2>/dev/null
$IN kill-server 2>/dev/null
rm -rf "$TMP"
}
trap cleanup EXIT
fail()
{
echo "[FAIL] $1"
exit 1
}
settle()
{
sleep 0.5
}
wait_option()
{
option=$1
expected=$2
i=0
while [ "$i" -lt 30 ]; do
value=$($IN show -gqv "$option" 2>/dev/null || true)
[ "$value" = "$expected" ] && return 0
i=$((i + 1))
sleep 0.2
done
fail "expected $option to be '$expected' but got '$value'"
}
accept_prompt()
{
key=$1
value=$2
$OUT send-keys "$key" || exit 1
settle
$OUT send-keys -l "$value" || exit 1
$OUT send-keys Enter || exit 1
settle
}
accept_two_prompts()
{
key=$1
first=$2
second=$3
$OUT send-keys "$key" || exit 1
settle
$OUT send-keys -l "$first" || exit 1
$OUT send-keys Enter || exit 1
settle
$OUT send-keys -l "$second" || exit 1
$OUT send-keys Enter || exit 1
settle
}
reset_options()
{
for option in \
@r @first @second @plain @raw_tail @one @two @two_again \
@double_index @marker; do
$IN set -g "$option" SENTINEL || exit 1
done
$IN set -g @marker unchanged || exit 1
}
$IN new -d -x80 -y24 "sh -c 'exec sleep 1000'" || exit 1
$IN set -g status on || exit 1
$IN set -g status-keys emacs || exit 1
$IN set -g window-size manual || exit 1
$IN bind -n M-s command-prompt -p '(single)' "set -g @r '%%'" ||
exit 1
$IN bind -n M-f command-prompt -p '(first)' \
"set -g @first '%%' ; set -g @second '%%'" ||
exit 1
$IN bind -n M-d command-prompt -p '(double)' 'set -g @r "%%%"' ||
exit 1
$IN bind -n M-r command-prompt -p '(raw)' "set -g @r %1" ||
exit 1
$IN bind -n M-a command-prompt -p '(all)' \
"set -g @first %1 ; set -g @second %1" ||
exit 1
$IN bind -n M-m command-prompt -p 'one,two' \
"set -g @one %1 ; set -g @two %2 ; set -g @two_again %2" ||
exit 1
$IN bind -n M-i command-prompt -p 'one,two' 'set -g @double_index "%2%"' ||
exit 1
$IN bind -n M-n command-prompt -p '(none)' \
"set -g @plain no-template-markers" ||
exit 1
$OUT new -d -x80 -y24 || exit 1
$OUT set -g status off || exit 1
$OUT set -g window-size manual || exit 1
$OUT send-keys -l "$IN attach" || exit 1
$OUT send-keys Enter || exit 1
sleep 1
reset_options
# %% is for templates already inside single quotes. A single quote in the
# replacement must stay data and must not close the surrounding quotes.
payload="can't ; set -g @marker changed ; done"
accept_prompt M-s "$payload"
wait_option @r "$payload"
wait_option @marker unchanged
# Only the first %% is replaced.
reset_options
payload="first'value"
accept_prompt M-f "$payload"
wait_option @first "$payload"
wait_option @second %%
# %%% keeps the previous double-quote escaping behaviour.
reset_options
payload='a"$;~\z'
accept_prompt M-d "$payload"
wait_option @r "$payload"
# %1 is intentionally left raw as an escape hatch.
reset_options
$IN set -g @raw_tail unchanged || exit 1
accept_prompt M-r 'raw ; set -g @raw_tail yes'
wait_option @r raw
wait_option @raw_tail yes
# All instances of %1 are replaced.
reset_options
accept_prompt M-a repeat
wait_option @first repeat
wait_option @second repeat
# %1 and %2 select different prompt values, and all instances of %2 are
# replaced.
reset_options
accept_two_prompts M-m one two
wait_option @one one
wait_option @two two
wait_option @two_again two
# %idx% uses double-quote escaping for indexed replacements.
reset_options
payload='b"$;~\y'
accept_two_prompts M-i ignored "$payload"
wait_option @double_index "$payload"
# A template without replacement markers is left alone.
reset_options
accept_prompt M-n 'unused ; set -g @marker changed'
wait_option @plain no-template-markers
wait_option @marker unchanged
exit 0

View File

@@ -1,8 +1,9 @@
#!/bin/sh
# 947
# size in control mode should change after refresh-client -C, and -x and -y
# should work without -d for control clients
# size in control mode should change after refresh-client -C, per-window
# control client sizes should work, and -x and -y should work without -d for
# control clients
PATH=/bin:/usr/bin
TERM=screen
@@ -47,4 +48,21 @@ $TMUX ls -F':#{window_width} #{window_height}' >>$OUT
printf ":100 50\n:80 24\n"|cmp -s $OUT - || exit 1
$TMUX kill-server 2>/dev/null
TMUX="$TEST_TMUX -LtestA$$-4 -f/dev/null"
$TMUX -f/dev/null new -d || exit 1
$TMUX neww || exit 1
w0=$($TMUX display -p -t :0 '#{window_id}')
w1=$($TMUX display -p -t :1 '#{window_id}')
cat <<EOF|$TMUX -f/dev/null -C a >$TMP
refresh -C 80,24
refresh -C ${w0}:40x10
display -p -t ${w0} 'w0 #{window_width} #{window_height}'
display -p -t ${w1} 'w1 #{window_width} #{window_height}'
refresh -C ${w0}:
display -p -t ${w0} 'w0c #{window_width} #{window_height}'
EOF
grep ^w $TMP >$OUT
printf "w0 40 10\nw1 80 24\nw0c 80 24\n"|cmp -s $OUT - || exit 1
$TMUX kill-server 2>/dev/null
exit 0

View File

@@ -73,11 +73,14 @@ $TMUX new-session -d -s m -x 80 -y 24 'cat' || exit 1
$TMUX split-window -t m:0 'cat' || exit 1
p0=$($TMUX display-message -p -t m:0.0 '#{pane_id}')
p1=$($TMUX display-message -p -t m:0.1 '#{pane_id}')
$TMUX set -g display-panes-format 'P#{pane_index}' ||
$TMUX set -g display-panes-format \
'P#{pane_index}:#{pane_unzoomed_width}x#{pane_unzoomed_height}' ||
fail "set display-panes-format failed"
$TMUX2 new-session -d -s out -x 80 -y 24 "$TMUX attach -t m" || exit 1
wait_clients 1
p0_size=$($TMUX display-message -p -t "$p0" '#{pane_width}x#{pane_height}')
p1_size=$($TMUX display-message -p -t "$p1" '#{pane_width}x#{pane_height}')
capture()
{
@@ -100,11 +103,38 @@ wait_capture()
$TMUX display-panes -d 0 -t "$p0" || fail "display-panes failed"
wait_format "$p0" '#{pane_mode}' 'panes-mode'
wait_format "$p0" '#{window_zoomed_flag}' '1'
wait_capture 'P0'
wait_capture 'P1'
wait_format "$p0" '#{pane_unzoomed_width}x#{pane_unzoomed_height}' \
"$p0_size"
wait_capture "P0:$p0_size"
wait_capture "P1:$p1_size"
$TMUX send-keys -t "$p0" q || fail "exit panes mode failed"
wait_format "$p0" '#{pane_in_mode}' '0'
wait_format "$p0" '#{window_zoomed_flag}' '0'
$TMUX set -g display-panes-format 'P#{pane_index}' ||
fail "reset display-panes-format failed"
# Unzoomed sizes match the visible pane size when scrollbars reserve space.
$TMUX set -w -t m:0 pane-scrollbars on ||
fail "set pane-scrollbars failed"
$TMUX set -w -t m:0 pane-scrollbars-style "width=2,pad=1" ||
fail "set pane-scrollbars-style failed"
p0_size=$($TMUX display-message -p -t "$p0" '#{pane_width}x#{pane_height}')
p1_size=$($TMUX display-message -p -t "$p1" '#{pane_width}x#{pane_height}')
$TMUX set -g display-panes-format \
'S#{pane_index}:#{pane_unzoomed_width}x#{pane_unzoomed_height}' ||
fail "set scrollbar display-panes-format failed"
$TMUX display-panes -d 0 -t "$p0" || fail "display-panes scrollbar failed"
wait_format "$p0" '#{window_zoomed_flag}' '1'
wait_format "$p0" '#{pane_unzoomed_width}x#{pane_unzoomed_height}' \
"$p0_size"
wait_capture "S0:$p0_size"
wait_capture "S1:$p1_size"
$TMUX send-keys -t "$p0" q || fail "exit scrollbar panes mode failed"
wait_format "$p0" '#{pane_in_mode}' '0'
$TMUX set -w -t m:0 pane-scrollbars off ||
fail "reset pane-scrollbars failed"
$TMUX set -g display-panes-format 'P#{pane_index}' ||
fail "reset display-panes-format after scrollbars failed"
# -Z starts unzoomed.
$TMUX display-panes -Zd 0 -t "$p0" || fail "display-panes -Z failed"
@@ -192,13 +222,21 @@ $TMUX set -g display-panes-format 'P#{pane_index}' ||
# pane content into the status row.
$TMUX set -w -t m:0 pane-border-status top ||
fail "set pane-border-status failed"
$TMUX set -g display-panes-format '' || fail "clear display-panes-format failed"
status_p0_size=$($TMUX display-message -p -t "$p0" \
'#{pane_width}x#{pane_height}')
status_p1_size=$($TMUX display-message -p -t "$p1" \
'#{pane_width}x#{pane_height}')
$TMUX set -g display-panes-format \
'#[align=right]T#{pane_index}:#{pane_unzoomed_width}x#{pane_unzoomed_height}' ||
fail "set status display-panes-format failed"
$TMUX respawn-pane -k -t "$p0" 'printf "STATUS-TOP\n"; exec cat' ||
fail "write status marker failed"
wait_capture 'STATUS-TOP'
$TMUX display-panes -d 0 -t "$p0" || fail "display-panes status failed"
wait_format "$p0" '#{pane_mode}' 'panes-mode'
wait_capture 'STATUS-TOP'
wait_capture "T0:$status_p0_size"
wait_capture "T1:$status_p1_size"
CAPTURED=$(capture)
first=$(printf '%s\n' "$CAPTURED" | sed -n '1p')
second=$(printf '%s\n' "$CAPTURED" | sed -n '2p')
@@ -230,13 +268,18 @@ wait_format "$fp" '#{pane_mode}' 'panes-mode'
wait_format "$fp" '#{window_zoomed_flag}' '1'
wait_capture '┌'
wait_capture '┘'
fp_size=$($TMUX display-message -p -t "$fp" \
'#{pane_unzoomed_width}x#{pane_unzoomed_height}')
[ "$fp_size" = "30x8" ] ||
fail "expected floating unzoomed size 30x8, got $fp_size"
$TMUX send-keys -t "$fp" q || fail "exit zoomed floating panes mode failed"
wait_format "$fp" '#{pane_in_mode}' '0'
wait_format "$fp" '#{window_zoomed_flag}' '0'
$TMUX resize-pane -t "$fp" -x 48 -y 14 ||
fail "resize floating pane larger failed"
$TMUX set -g display-panes-format '#[align=right]FP#{pane_width}x#{pane_height}' ||
$TMUX set -g display-panes-format \
'#[align=right]FP#{pane_unzoomed_width}x#{pane_unzoomed_height}' ||
fail "set floating display-panes-format failed"
$TMUX display-panes -Zd 0 -t "$fp" || fail "display-panes floating format failed"
wait_format "$fp" '#{pane_mode}' 'panes-mode'

View File

@@ -5,11 +5,20 @@
start_pane alternate 10 3 'MAIN\033[?1049hALT\033[?1049lZ\n'
check_capture alternate 'MAINZ'
start_pane osc133 10 4 '\033]133;A\007prompt\n\033]133;C\007output\n'
check_capture osc133 'prompt
output'
check_flags osc133 'P prompt
O output'
start_pane osc133 20 8 'xx\033]133;A\007p>\033]133;B\007cmd\nxy\033]133;P;k=s\007more\nzz\033]133;C\007out\033]133;D;7\007\nq\033]133;C\007bad\033]133;D;-1\007\nqq\033]133;C\007big\033]133;D;300\007\nzzz\033]133;C\007ok\033]133;D\007\n'
check_capture osc133 'xxp>cmd
xymore
zzout
qbad
qqbig
zzzok'
check_raw_matches osc133 \
'L 0 \(0\) flags=START_PROMPT,START_COMMAND\[[0-9a-f]+\].* osc133=2,4,0,0,0' \
'L 1 \(1\) flags=SECOND_PROMPT\[[0-9a-f]+\].* osc133=2,0,0,0,0' \
'L 2 \(2\) flags=START_OUTPUT,END_OUTPUT\[[0-9a-f]+\].* osc133=0,0,2,5,7' \
'L 3 \(3\) flags=START_OUTPUT,END_OUTPUT\[[0-9a-f]+\].* osc133=0,0,1,4,255' \
'L 4 \(4\) flags=START_OUTPUT,END_OUTPUT\[[0-9a-f]+\].* osc133=0,0,2,5,255' \
'L 5 \(5\) flags=START_OUTPUT,END_OUTPUT\[[0-9a-f]+\].* osc133=0,0,3,5,0'
$TMUX kill-server 2>/dev/null
exit $exit_status

View File

@@ -21,7 +21,7 @@ exit_status=0
format_string () {
case $1 in
*\')
printf '"%%%%"'
printf '"%%%%%%"'
;;
*)
printf "'%%%%'"