#!/bin/bash
set -a
. "$CONNECT_TEST_ENV"
set +a
side=$1
root=$(cd "$(dirname "$0")" && pwd)
capture="$root/$side-capture-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$capture"
printf "%s" "$capture" > "$root/$side-capture-path"
ghostty --gtk-single-instance=false --title='T3 Code pruning proof' --font-size=15 --window-width=140 --window-height=36 -e python3 "$root/driver.py" "$side" > "$root/$side-terminal-private.log" 2>&1 &
terminal_pid=$!
ffmpeg -y -f x11grab -framerate 5 -video_size 1920x1080 -i "$DISPLAY" -c:v libx264 -preset ultrafast -crf 24 -pix_fmt yuv420p "$capture/recording.mp4" > "$root/$side-ffmpeg.log" 2>&1 &
record_pid=$!
for ((i=0;i<210;i++));do
 if test -f "$root/$side-done"; then break; fi
 sleep 1
done
sleep 1
import -window root "$capture/still-1.png"
sleep .5
import -window root "$capture/still-2.png"
sleep 2
kill -INT "$record_pid"
wait "$record_pid"
wait "$terminal_pid"
