Skip to content

Commit

Permalink
Fix to correctly clean spinners on finishing or terminating
Browse files Browse the repository at this point in the history
  • Loading branch information
iliajie committed Sep 28, 2024
1 parent e297fe6 commit 83ff146
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions slib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
# slog logging library Copyright Fred Palmer and Joe Cooper
# Licensed under the BSD 3 clause license
#------------------------------------------------------------------------------

restore_cursor () {
tput cnorm
}

cleanup () {
exit_code=$1
stty echo 1>/dev/null 2>&1
Expand All @@ -19,7 +24,7 @@ cleanup () {
done
tput sgr0
fi
tput cnorm
restore_cursor
if [ -n "$VIRTUALMIN_INSTALL_TEMPDIR" ]; then
if echo "$VIRTUALMIN_INSTALL_TEMPDIR" | grep -q "virtualmin-"; then
rm -rf $VIRTUALMIN_INSTALL_TEMPDIR
Expand Down Expand Up @@ -231,6 +236,9 @@ SPINNER_SYMBOLS="WIDE_ASCII_PROG" # Name of the variable containing the symbols.
SPINNER_CLEAR=1 # Blank the line when done.

spinner () {
# Add this trap to make sure the spinner is terminated and the cursor
# is restored, when the script is either finished or killed.
trap 'restore_cursor; exit' INT QUIT TERM EXIT
# Safest option are one of these. Doesn't need Unicode, at all.
local WIDE_ASCII_PROG="[>-] [->] [--] [--]"
local WIDE_UNI_GREYSCALE2="▒▒▒ █▒▒ ██▒ ███ ▒██ ▒▒█ ▒▒▒"
Expand Down Expand Up @@ -281,7 +289,7 @@ spinner () {
done
done
tput rc
tput cnorm
restore_cursor
return 0
}

Expand Down Expand Up @@ -365,7 +373,7 @@ run_ok () {
kill $spinpid 2>/dev/null
rm -rf ${SPINNER_DONEFILE} 2>/dev/null 2>&1
tput rc
tput cnorm
restore_cursor
fi
fi
# Log what we were supposed to be running
Expand Down

0 comments on commit 83ff146

Please sign in to comment.