From 0f7d778bfe357bd031249165d69561a5f92a0d8a Mon Sep 17 00:00:00 2001 From: William Harrington Date: Thu, 1 Apr 2021 12:14:20 -0500 Subject: Adjust function spinner to take in a spinner type. If no type is defined then random will be chosen. Pass the 2nd argument as spinnertype when spinner is invoked. Cleanup some extraction text and reset the colors at the end. --- chapter6/backup.sh | 2 +- env.sh | 5 +++++ functions.sh | 44 ++++++++++++++++++++++++++++---------------- packageinstall.sh | 6 +++--- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/chapter6/backup.sh b/chapter6/backup.sh index 6d23c27..f710037 100644 --- a/chapter6/backup.sh +++ b/chapter6/backup.sh @@ -10,7 +10,7 @@ else echo -ne "${GRN}Backing up ${YLW}${LFS}${GRN} to ${YLW}${file}${RST}... " pushd "${LFS}" > /dev/null || exit 1 sudo XZ_OPTS="-T${NUMPROCS} -e" tar cJpf "${HOME}"/"${file}" "${directories[@]}" >/dev/null 2>&1 & pid=$! - spinner "$pid" + spinner "$pid" "${SPINNER}" retval=$? if [ "$retval" -ne 0 ]; then printf "%b" "${RED}FAILED!${RST}\n" diff --git a/env.sh b/env.sh index 4e05c06..269cb77 100644 --- a/env.sh +++ b/env.sh @@ -37,3 +37,8 @@ unset numjobs export PS1 LC_ALL LFS LFS_TGT PATH CONFIG_SITE export LFS_VER LFS_DISK LFS_PART LFS_PWD NUMPROCS MAKEFLAGS + + +# Set spinner type (0-11 in funtions.sh) +SPINNER=0 +export SPINNER diff --git a/functions.sh b/functions.sh index 8c5bd93..9a2e685 100644 --- a/functions.sh +++ b/functions.sh @@ -33,56 +33,68 @@ function cursorBack() { function spinner() { # make sure we use non-unicode character type locale # (that way it works for any locale as long as the font supports the characters) + local numspinners=12 + local LC_CTYPE=C local pid=$1 # Process Id of the previous running command - case $(($RANDOM % 12)) in + local spintype=$2 + + if [ -z "${spintype}" ] || [ "${spintype}" -ge "${numspinners}" ]; then + spintype=$((RANDOM % numspinners)) + fi + + case "${spintype}" in 0) - local spin='⠁⠂⠄⡀⢀⠠⠐⠈' - local charwidth=3 + local spin='.oO0Oo' + local charwidth=1 ;; 1) local spin='-\|/' local charwidth=1 ;; 2) - local spin="▁▂▃▄▅▆▇█▇▆▅▄▃▂▁" + local spin='⠁⠂⠄⡀⢀⠠⠐⠈' local charwidth=3 ;; 3) - local spin="▉▊▋▌▍▎▏▎▍▌▋▊▉" + local spin="▁▂▃▄▅▆▇█▇▆▅▄▃▂▁" local charwidth=3 ;; 4) - local spin='←↖↑↗→↘↓↙' + local spin="▉▊▋▌▍▎▏▎▍▌▋▊▉" local charwidth=3 ;; 5) - local spin='▖▘▝▗' + local spin='←↖↑↗→↘↓↙' local charwidth=3 ;; 6) - local spin='┤┘┴└├┌┬┐' + local spin='▖▘▝▗' local charwidth=3 ;; 7) - local spin='◢◣◤◥' + local spin='┤┘┴└├┌┬┐' local charwidth=3 ;; 8) - local spin='◰◳◲◱' + local spin='◢◣◤◥' local charwidth=3 ;; 9) - local spin='◴◷◶◵' + local spin='◰◳◲◱' local charwidth=3 ;; 10) - local spin='◐◓◑◒' + local spin='◴◷◶◵' local charwidth=3 ;; 11) + local spin='◐◓◑◒' + local charwidth=3 + ;; + 12) local spin='⣾⣽⣻⢿⡿⣟⣯⣷' local charwidth=3 ;; @@ -91,14 +103,14 @@ function spinner() { local i=0 tput civis # cursor invisible tput bold setaf 7 - while kill -0 $pid 2>/dev/null; do - local i=$(((i + $charwidth) % ${#spin})) + while kill -0 "$pid" 2>/dev/null; do + local i=$(((i + charwidth) % ${#spin})) printf "%b" "${spin:$i:$charwidth}" cursorBack 1 - sleep .1 + sleep .2 done tput cnorm - wait $pid # capture exit code + wait "$pid" # capture exit code return $? } diff --git a/packageinstall.sh b/packageinstall.sh index 5105fbb..afd11a0 100644 --- a/packageinstall.sh +++ b/packageinstall.sh @@ -16,9 +16,9 @@ else # Remove existing if exists rm -rf "${DIRNAME}" - printf "%b" "${IBLU}Extracting ${YLW}${CACHEFILE}... " + printf "%b" "${IBLU}Extracting ${YLW}${CACHEFILE}... ${RST}" tar xf "${CACHEFILE}" > /dev/null 2>&1 & pid=$! - spinner "$pid" + spinner "$pid" "${SPINNER}" retval=$? if [ "$retval" -ne 0 ]; then printf "%b" "${GRN}Extraction ${RED}FAILED!${RST}\n" @@ -33,7 +33,7 @@ else mkdir -p "${LFS}/sources/log/chapter${CHAPTER}/" source "${LFS}/sources/chapter${CHAPTER}/${PACKAGE}.sh" 2>&1 > "${LFS}/sources/log/chapter${CHAPTER}/${PACKAGE}.log" 2>&1 & pid=$! - spinner "$pid" + spinner "$pid" "${SPINNER}" retval=$? if [ "$retval" -ne 0 ]; then printf "%b" "${RED}FAILED!${RST}\n" -- cgit v1.2.3-54-g00ecf