improvements to spinner

This commit is contained in:
2025-12-18 13:24:58 -06:00
parent ad5b8e4482
commit 65fb35877e
5 changed files with 46 additions and 18 deletions

View File

@@ -324,18 +324,16 @@ bash_sort() {
printf '%s\n' "${arr[@]}"
}
spinner() {
if [[ $1 == 'reset' ]]; then
echo -ne ' \n'
return 0
fi
_start_spinner() {
local spinChars=(
"-"
'\'
"|"
"/"
)
sleep 1
while true; do
for ((ind = 0; ind < "${#spinChars[@]}"; ind++)); do
echo -ne "${spinChars[${ind}]}" '\b\b'
@@ -344,6 +342,28 @@ spinner() {
done
}
spinner() {
local action="$1"
local spinPidFile="${TMP_DIR}/.spinner-pid"
case "${action}" in
start)
test -f "${spinPidFile}" &&
rm "${spinPidFile}"
# don't want to clutter logs if running headless
test "${HEADLESS}" == '1' &&
return
_start_spinner &
echo $! >"${spinPidFile}"
;;
stop)
test -f "${spinPidFile}" && kill "$(<"${spinPidFile}")"
echo -ne ' \n'
;;
esac
}
get_pkgconfig_version() {
local pkg="$1"
pkg-config --modversion "${pkg}"