spinner fix
This commit is contained in:
parent
d25c213346
commit
3f613e9851
|
|
@ -36,22 +36,24 @@ spinner() {
|
||||||
local elapsed=0
|
local elapsed=0
|
||||||
local last_heartbeat=0
|
local last_heartbeat=0
|
||||||
local spinner_tty=0
|
local spinner_tty=0
|
||||||
|
local spinner_tty_path=""
|
||||||
|
|
||||||
start_ts="$(date +%s)"
|
start_ts="$(date +%s)"
|
||||||
|
|
||||||
if [[ -w /dev/tty ]]; then
|
spinner_tty_path="$(tty 2>/dev/null || true)"
|
||||||
|
if [[ -n "$spinner_tty_path" && "$spinner_tty_path" != "not a tty" && -w "$spinner_tty_path" ]]; then
|
||||||
spinner_tty=1
|
spinner_tty=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if command -v tput >/dev/null 2>&1 && [[ "$spinner_tty" -eq 1 ]]; then
|
if command -v tput >/dev/null 2>&1 && [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
tput civis >/dev/tty 2>/dev/null || true
|
tput civis >"$spinner_tty_path" 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while kill -0 "$pid" 2>/dev/null; do
|
while kill -0 "$pid" 2>/dev/null; do
|
||||||
i=$(((i + 1) % 4))
|
i=$(((i + 1) % 4))
|
||||||
elapsed=$(( $(date +%s) - start_ts ))
|
elapsed=$(( $(date +%s) - start_ts ))
|
||||||
if [[ "$spinner_tty" -eq 1 ]]; then
|
if [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
printf '\r[%c] %s... %ss' "${spin:$i:1}" "$msg" "$elapsed" >/dev/tty
|
printf '\r[%c] %s... %ss' "${spin:$i:1}" "$msg" "$elapsed" >"$spinner_tty_path"
|
||||||
fi
|
fi
|
||||||
if (( elapsed >= last_heartbeat + 15 )); then
|
if (( elapsed >= last_heartbeat + 15 )); then
|
||||||
log "HEARTBEAT: ${msg} still running (${elapsed}s)"
|
log "HEARTBEAT: ${msg} still running (${elapsed}s)"
|
||||||
|
|
@ -61,20 +63,20 @@ spinner() {
|
||||||
done
|
done
|
||||||
|
|
||||||
if command -v tput >/dev/null 2>&1 && [[ "$spinner_tty" -eq 1 ]]; then
|
if command -v tput >/dev/null 2>&1 && [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
tput cnorm >/dev/tty 2>/dev/null || true
|
tput cnorm >"$spinner_tty_path" 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
wait "$pid"
|
wait "$pid"
|
||||||
local rc=$?
|
local rc=$?
|
||||||
if [[ "$rc" -eq 0 ]]; then
|
if [[ "$rc" -eq 0 ]]; then
|
||||||
if [[ "$spinner_tty" -eq 1 ]]; then
|
if [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
printf '\r[OK] %s. \n' "$msg" >/dev/tty
|
printf '\r[OK] %s. \n' "$msg" >"$spinner_tty_path"
|
||||||
else
|
else
|
||||||
echo "[OK] $msg"
|
echo "[OK] $msg"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [[ "$spinner_tty" -eq 1 ]]; then
|
if [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
printf '\r[FAIL:%s] %s. \n' "$rc" "$msg" >/dev/tty
|
printf '\r[FAIL:%s] %s. \n' "$rc" "$msg" >"$spinner_tty_path"
|
||||||
else
|
else
|
||||||
echo "[FAIL:$rc] $msg"
|
echo "[FAIL:$rc] $msg"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -464,22 +464,24 @@ spinner() {
|
||||||
local elapsed=0
|
local elapsed=0
|
||||||
local last_heartbeat=0
|
local last_heartbeat=0
|
||||||
local spinner_tty=0
|
local spinner_tty=0
|
||||||
|
local spinner_tty_path=""
|
||||||
|
|
||||||
start_ts="$(date +%s)"
|
start_ts="$(date +%s)"
|
||||||
|
|
||||||
if [[ -w /dev/tty ]]; then
|
spinner_tty_path="$(tty 2>/dev/null || true)"
|
||||||
|
if [[ -n "$spinner_tty_path" && "$spinner_tty_path" != "not a tty" && -w "$spinner_tty_path" ]]; then
|
||||||
spinner_tty=1
|
spinner_tty=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if command -v tput >/dev/null 2>&1 && [[ "$spinner_tty" -eq 1 ]]; then
|
if command -v tput >/dev/null 2>&1 && [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
tput civis >/dev/tty 2>/dev/null || true
|
tput civis >"$spinner_tty_path" 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while kill -0 "$pid" 2>/dev/null; do
|
while kill -0 "$pid" 2>/dev/null; do
|
||||||
i=$(((i+1) % 4))
|
i=$(((i+1) % 4))
|
||||||
elapsed=$(( $(date +%s) - start_ts ))
|
elapsed=$(( $(date +%s) - start_ts ))
|
||||||
if [[ "$spinner_tty" -eq 1 ]]; then
|
if [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
printf "\r[%c] %s... %ss" "${spin:$i:1}" "$msg" "$elapsed" >/dev/tty
|
printf "\r[%c] %s... %ss" "${spin:$i:1}" "$msg" "$elapsed" >"$spinner_tty_path"
|
||||||
fi
|
fi
|
||||||
if (( elapsed >= last_heartbeat + 15 )); then
|
if (( elapsed >= last_heartbeat + 15 )); then
|
||||||
log "HEARTBEAT: ${msg} still running (${elapsed}s)"
|
log "HEARTBEAT: ${msg} still running (${elapsed}s)"
|
||||||
|
|
@ -489,10 +491,10 @@ spinner() {
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ "$spinner_tty" -eq 1 ]]; then
|
if [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
printf "\r%-80s\r" "" >/dev/tty
|
printf "\r%-80s\r" "" >"$spinner_tty_path"
|
||||||
fi
|
fi
|
||||||
if command -v tput >/dev/null 2>&1 && [[ "$spinner_tty" -eq 1 ]]; then
|
if command -v tput >/dev/null 2>&1 && [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
tput cnorm >/dev/tty 2>/dev/null || true
|
tput cnorm >"$spinner_tty_path" 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -507,6 +509,7 @@ run_long() {
|
||||||
local elapsed=0
|
local elapsed=0
|
||||||
local last_heartbeat=0
|
local last_heartbeat=0
|
||||||
local spinner_tty=0
|
local spinner_tty=0
|
||||||
|
local spinner_tty_path=""
|
||||||
local timed_out=0
|
local timed_out=0
|
||||||
shift 2
|
shift 2
|
||||||
|
|
||||||
|
|
@ -516,12 +519,13 @@ run_long() {
|
||||||
pid=$!
|
pid=$!
|
||||||
start_ts="$(date +%s)"
|
start_ts="$(date +%s)"
|
||||||
|
|
||||||
if [[ -w /dev/tty ]]; then
|
spinner_tty_path="$(tty 2>/dev/null || true)"
|
||||||
|
if [[ -n "$spinner_tty_path" && "$spinner_tty_path" != "not a tty" && -w "$spinner_tty_path" ]]; then
|
||||||
spinner_tty=1
|
spinner_tty=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if command -v tput >/dev/null 2>&1 && [[ "$spinner_tty" -eq 1 ]]; then
|
if command -v tput >/dev/null 2>&1 && [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
tput civis >/dev/tty 2>/dev/null || true
|
tput civis >"$spinner_tty_path" 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while kill -0 "$pid" 2>/dev/null; do
|
while kill -0 "$pid" 2>/dev/null; do
|
||||||
|
|
@ -529,7 +533,7 @@ run_long() {
|
||||||
elapsed=$(( $(date +%s) - start_ts ))
|
elapsed=$(( $(date +%s) - start_ts ))
|
||||||
|
|
||||||
if [[ "$spinner_tty" -eq 1 ]]; then
|
if [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
printf "\r[%c] %s... %ss" "${spin:$i:1}" "$msg" "$elapsed" >/dev/tty
|
printf "\r[%c] %s... %ss" "${spin:$i:1}" "$msg" "$elapsed" >"$spinner_tty_path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if (( elapsed >= last_heartbeat + 15 )); then
|
if (( elapsed >= last_heartbeat + 15 )); then
|
||||||
|
|
@ -550,10 +554,10 @@ run_long() {
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ "$spinner_tty" -eq 1 ]]; then
|
if [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
printf "\r%-80s\r" "" >/dev/tty
|
printf "\r%-80s\r" "" >"$spinner_tty_path"
|
||||||
fi
|
fi
|
||||||
if command -v tput >/dev/null 2>&1 && [[ "$spinner_tty" -eq 1 ]]; then
|
if command -v tput >/dev/null 2>&1 && [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
tput cnorm >/dev/tty 2>/dev/null || true
|
tput cnorm >"$spinner_tty_path" 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if wait "$pid"; then
|
if wait "$pid"; then
|
||||||
|
|
|
||||||
|
|
@ -233,6 +233,7 @@ run_long() {
|
||||||
local elapsed=0
|
local elapsed=0
|
||||||
local last_heartbeat=0
|
local last_heartbeat=0
|
||||||
local spinner_tty=0
|
local spinner_tty=0
|
||||||
|
local spinner_tty_path=""
|
||||||
local timed_out=0
|
local timed_out=0
|
||||||
shift 2
|
shift 2
|
||||||
|
|
||||||
|
|
@ -242,12 +243,13 @@ run_long() {
|
||||||
pid=$!
|
pid=$!
|
||||||
start_ts="$(date +%s)"
|
start_ts="$(date +%s)"
|
||||||
|
|
||||||
if [[ -w /dev/tty ]]; then
|
spinner_tty_path="$(tty 2>/dev/null || true)"
|
||||||
|
if [[ -n "$spinner_tty_path" && "$spinner_tty_path" != "not a tty" && -w "$spinner_tty_path" ]]; then
|
||||||
spinner_tty=1
|
spinner_tty=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if command -v tput >/dev/null 2>&1 && [[ "$spinner_tty" -eq 1 ]]; then
|
if command -v tput >/dev/null 2>&1 && [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
tput civis >/dev/tty 2>/dev/null || true
|
tput civis >"$spinner_tty_path" 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while kill -0 "$pid" 2>/dev/null; do
|
while kill -0 "$pid" 2>/dev/null; do
|
||||||
|
|
@ -255,7 +257,7 @@ run_long() {
|
||||||
elapsed=$(( $(date +%s) - start_ts ))
|
elapsed=$(( $(date +%s) - start_ts ))
|
||||||
|
|
||||||
if [[ "$spinner_tty" -eq 1 ]]; then
|
if [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
printf "\r[%c] %s... %ss" "${spin:$i:1}" "$msg" "$elapsed" >/dev/tty
|
printf "\r[%c] %s... %ss" "${spin:$i:1}" "$msg" "$elapsed" >"$spinner_tty_path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if (( elapsed >= last_heartbeat + 15 )); then
|
if (( elapsed >= last_heartbeat + 15 )); then
|
||||||
|
|
@ -276,10 +278,10 @@ run_long() {
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ "$spinner_tty" -eq 1 ]]; then
|
if [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
printf "\r%-80s\r" "" >/dev/tty
|
printf "\r%-80s\r" "" >"$spinner_tty_path"
|
||||||
fi
|
fi
|
||||||
if command -v tput >/dev/null 2>&1 && [[ "$spinner_tty" -eq 1 ]]; then
|
if command -v tput >/dev/null 2>&1 && [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
tput cnorm >/dev/tty 2>/dev/null || true
|
tput cnorm >"$spinner_tty_path" 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
wait "$pid"
|
wait "$pid"
|
||||||
|
|
@ -290,13 +292,13 @@ run_long() {
|
||||||
|
|
||||||
if [[ "$rc" -eq 0 ]]; then
|
if [[ "$rc" -eq 0 ]]; then
|
||||||
if [[ "$spinner_tty" -eq 1 ]]; then
|
if [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
printf "\r[OK] %s. \n" "$msg" >/dev/tty
|
printf "\r[OK] %s. \n" "$msg" >"$spinner_tty_path"
|
||||||
else
|
else
|
||||||
echo "[OK] $msg"
|
echo "[OK] $msg"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [[ "$spinner_tty" -eq 1 ]]; then
|
if [[ "$spinner_tty" -eq 1 ]]; then
|
||||||
printf "\r[FAIL:%s] %s. \n" "$rc" "$msg" >/dev/tty
|
printf "\r[FAIL:%s] %s. \n" "$rc" "$msg" >"$spinner_tty_path"
|
||||||
else
|
else
|
||||||
echo "[FAIL:$rc] $msg"
|
echo "[FAIL:$rc] $msg"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue