From 9862ea0748499a00def0f768010350ba595e01b8 Mon Sep 17 00:00:00 2001 From: Michael Grant Date: Thu, 8 Oct 2026 21:13:55 +0200 Subject: [PATCH] Add regress test for the OSC 133 output and selection editors. Co-Authored-By: Claude Sonnet 5.5 --- regress/output-editor.sh | 120 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 regress/output-editor.sh diff --git a/regress/output-editor.sh b/regress/output-editor.sh new file mode 100644 index 000000000..a1fe108b0 --- /dev/null +++ b/regress/output-editor.sh @@ -0,0 +1,120 @@ +#!/bin/sh + +# Output and selection editors use either the default or an explicit command. + +PATH=/bin:/usr/bin +TERM=screen + +[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux) +DIR=$(mktemp -d) || exit 1 +TMUX_TMPDIR=$DIR +export TMUX_TMPDIR +TMUX="$TEST_TMUX -LtestA$$ -f/dev/null" +OUT="$TEST_TMUX -LtestB$$ -f/dev/null" + +cleanup() +{ + $OUT kill-server 2>/dev/null + $TMUX kill-server 2>/dev/null + rm -rf "$DIR" +} +trap cleanup EXIT HUP INT TERM + +wait_editor() +{ + i=0 + while [ "$i" -lt 50 ]; do + modal=$($TMUX display-message -p -t edit:0 '#{window_modal_pane}') + if [ -f "$DIR/$1" ] && [ -z "$modal" ]; then + return 0 + fi + sleep 0.1 + i=$((i + 1)) + done + echo "editor did not finish: $1" >&2 + exit 1 +} + +cat >"$DIR/editor.sh" <"$DIR/expected" || exit 1 +for keys in emacs vi; do + $TMUX set-option -w -t edit:0 mode-keys "$keys" || exit 1 + case "$keys" in + emacs) binding=e ;; + vi) binding=M-e ;; + esac + for state in active stopped; do + name="$keys-$state" + $TMUX set-option -g editor "sh $DIR/editor.sh $name" || exit 1 + $TMUX copy-mode -t edit:0 || exit 1 + $TMUX send-keys -t edit:0 -X search-backward one || exit 1 + $TMUX send-keys -t edit:0 -X begin-selection || exit 1 + if [ "$keys" = emacs ]; then + $TMUX send-keys -t edit:0 -X cursor-right || exit 1 + fi + if [ "$state" = stopped ]; then + $TMUX send-keys -t edit:0 -X stop-selection || exit 1 + fi + [ "$($TMUX display-message -p -t edit:0 \ + '#{selection_present}')" = 1 ] || exit 1 + $TMUX send-keys -t edit:0 "$binding" || exit 1 + wait_editor "$name" + cmp "$DIR/expected" "$DIR/$name" || exit 1 + [ "$($TMUX show-buffer)" = sentinel ] || exit 1 + $TMUX send-keys -t edit:0 -X cancel || exit 1 + done +done + +# An empty emacs selection still opens the output. +printf 'one\ntwo\n' >"$DIR/expected" || exit 1 +$TMUX set-option -w -t edit:0 mode-keys emacs || exit 1 +$TMUX set-option -g editor "sh $DIR/editor.sh empty" || exit 1 +$TMUX copy-mode -t edit:0 || exit 1 +$TMUX send-keys -t edit:0 -X search-backward one || exit 1 +$TMUX send-keys -t edit:0 -X begin-selection || exit 1 +[ "$($TMUX display-message -p -t edit:0 '#{selection_present}')" = 0 ] || + exit 1 +$TMUX send-keys -t edit:0 e || exit 1 +wait_editor empty +cmp "$DIR/expected" "$DIR/empty" || exit 1 +$TMUX send-keys -t edit:0 -X cancel || exit 1 + +exit 0