mirror of
https://github.com/pi-hole/pi-hole
synced 2025-01-03 12:40:56 +00:00
Address revision requests:
- replace `local var` with `_var` (POSIX style); - move inline comments Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
This commit is contained in:
parent
8d1f286f30
commit
d89720330f
@ -1346,34 +1346,41 @@ check_database_integrity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Show a text spinner during a long process run
|
# Show a text spinner during a long process run
|
||||||
#
|
|
||||||
spinner(){
|
spinner(){
|
||||||
# Show the spinner only if there is a tty
|
# Show the spinner only if there is a tty
|
||||||
if tty -s; then
|
if tty -s; then
|
||||||
local PID=$! # PID of the most recent background process
|
# PID of the most recent background process
|
||||||
local spin="/-\|"
|
_PID=$!
|
||||||
local start=0
|
_spin="/-\|"
|
||||||
local elapsed=0
|
_start=0
|
||||||
local i=1
|
_elapsed=0
|
||||||
|
_i=1
|
||||||
|
|
||||||
start=$(date +%s) # Start the counter
|
# Start the counter
|
||||||
|
_start=$(date +%s)
|
||||||
|
|
||||||
tput civis > /dev/tty # Hide the cursor
|
# Hide the cursor
|
||||||
trap 'tput cnorm > /dev/tty' EXIT # ensures cursor is visible again, in case of premature exit
|
tput civis > /dev/tty
|
||||||
|
|
||||||
while [ -d /proc/$PID ]; do
|
# ensures cursor is visible again, in case of premature exit
|
||||||
elapsed=$(( $(date +%s) - start ))
|
trap 'tput cnorm > /dev/tty' EXIT
|
||||||
|
|
||||||
|
while [ -d /proc/$_PID ]; do
|
||||||
|
_elapsed=$(( $(date +%s) - _start ))
|
||||||
# use hours only if needed
|
# use hours only if needed
|
||||||
if [ "$elapsed" -lt 3600 ]; then
|
if [ "$_elapsed" -lt 3600 ]; then
|
||||||
printf "\r${spin:i++%${#spin}:1} %02d:%02d" $((elapsed/60)) $((elapsed%60)) >"$(tty)"
|
printf "\r${_spin:_i++%${#_spin}:1} %02d:%02d" $((_elapsed/60)) $((_elapsed%60)) >"$(tty)"
|
||||||
else
|
else
|
||||||
printf "\r${spin:i++%${#spin}:1} %02d:%02d:%02d" $((elapsed/3600)) $(((elapsed/60)%60)) $((elapsed%60)) >"$(tty)"
|
printf "\r${_spin:_i++%${#_spin}:1} %02d:%02d:%02d" $((_elapsed/3600)) $(((_elapsed/60)%60)) $((_elapsed%60)) >"$(tty)"
|
||||||
fi
|
fi
|
||||||
sleep 0.25
|
sleep 0.25
|
||||||
done
|
done
|
||||||
|
|
||||||
printf "\r" >"$(tty)" # Return to the begin of the line after completion (the spinner will be overwritten)
|
# Return to the begin of the line after completion (the spinner will be overwritten)
|
||||||
tput cnorm > /dev/tty # Restore cursor visibility
|
printf "\r" >"$(tty)"
|
||||||
|
|
||||||
|
# Restore cursor visibility
|
||||||
|
tput cnorm > /dev/tty
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user