release.sh: redirige output a /dev/tty en select_arrow (evita captura en subshell)

This commit is contained in:
Super User
2026-06-17 21:12:37 -04:00
parent 40b4e2bd99
commit 4d1ab84cfc

View File

@@ -14,50 +14,50 @@ bar="━━━━━━━━━━━━━━━━━━━━━━━━━
blen=${#bar}
# ── helpers ──
cleanup() { tput cnorm; exit; }
CURSOR_ON='\033[?25h'
CURSOR_OFF='\033[?25l'
cleanup() { printf "$CURSOR_ON" >/dev/tty; exit; }
trap cleanup EXIT INT TERM
cursor_off() { tput civis; }
cursor_on() { tput cnorm; }
# ── arrow selector ──
select_arrow() {
local opts=("$@")
local sel=0 key i n=${#opts[@]}
local tty=/dev/tty
for i in "${!opts[@]}"; do
if [ "$i" -eq "$sel" ]; then
printf " ${C} ${opts[$i]}${N}\n"
printf " ${C} ${opts[$i]}${N}\n" >"$tty"
else
printf " ${opts[$i]}\n"
printf " ${opts[$i]}\n" >"$tty"
fi
done
printf '\033[%dA' "$n"
cursor_off
printf '\033[%dA' "$n" >"$tty"
printf "$CURSOR_OFF" >"$tty"
while true; do
IFS= read -rsn1 key
IFS= read -rsn1 key <"$tty"
if [[ $key == $'\x1b' ]]; then
read -rsn2 -t 0.01 key || key=''
read -rsn2 -t 0.01 key <"$tty" || key=''
case "$key" in
'[A') (( sel > 0 )) && (( sel-- )) ;;
'[B') (( sel < n - 1 )) && (( sel++ )) ;;
esac
elif [[ -z "$key" || "$key" == $'\n' || "$key" == $'\r' ]]; then
printf '\033[%dA\033[J' "$n"
cursor_on
printf '\033[%dA\033[J' "$n" >"$tty"
printf "$CURSOR_ON" >"$tty"
printf '%s\n' "${opts[$sel]}"
return 0
fi
for i in "${!opts[@]}"; do
if [ "$i" -eq "$sel" ]; then
printf "\033[2K\r ${C} ${opts[$i]}${N}\n"
printf "\033[2K\r ${C} ${opts[$i]}${N}\n" >"$tty"
else
printf "\033[2K\r ${opts[$i]}\n"
printf "\033[2K\r ${opts[$i]}\n" >"$tty"
fi
done
printf '\033[%dA' "$n"
printf '\033[%dA' "$n" >"$tty"
done
}