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