#!/bin/bash
set -eu
root="$1"
for name in before-standard after-standard before-quoting after-quoting; do
  gnome-terminal --wait --hide-menubar --geometry=155x36 --title="CLI evidence" -- bash -c 'printf "\033[?25l"; cat "$1"; read -r -t 5 || true' proof "$root/$name.txt" &
  terminal_pid=$!
  for i in $(seq 1 30); do
    window=$(xdotool search --name '^CLI evidence$' 2>/dev/null | head -1) || true
    [ -n "$window" ] && break
    sleep 0.2
  done
  xdotool windowsize "$window" 1900 1030
  sleep 1
  import -window "$window" "$root/$name-check.png"
  sleep 0.5
  import -window "$window" "$root/$name.png"
  compare -metric AE "$root/$name-check.png" "$root/$name.png" null: 2> "$root/$name-stability.txt" || true
  xdotool windowfocus "$window"
  xdotool key Return
  wait "$terminal_pid"
done
