From 9ed0afd2d6f7ea4402367beffa0780666c2f217d Mon Sep 17 00:00:00 2001 From: William Harrington Date: Fri, 26 Mar 2021 15:51:29 -0500 Subject: Remove spinner script and move spinner function to functions. --- functions.sh | 48 +++++++++++++++++++++++++++++++++++++++++++++++- spinner.sh | 48 ------------------------------------------------ 2 files changed, 47 insertions(+), 49 deletions(-) delete mode 100644 spinner.sh diff --git a/functions.sh b/functions.sh index d2ff5be..6b8671a 100644 --- a/functions.sh +++ b/functions.sh @@ -12,8 +12,54 @@ download() printf "%b" "${RED}FAILED! WGET EXIT (${retval})\n${RST}" exit "${retval}" fi - printf "%b" "\b\b\b\b\n" tput cnorm } export -f download + +## spinner takes the pid of the process as the first argument and +# string to display as second argument (default provided) and spins +# until the process completes. +spinner() { + local proc="$1" + #local str="${2:-'Copyright of KatworX© Tech. Developed by Arjun Singh Kathait and Debugged by the ☆Stack Overflow Community☆'}" + local str="" + local delay="0.1" + tput civis # hide cursor + printf "%b" "${WHT}" + while [ -d /proc/"$proc" ]; do + #-\|/ + #⠁⠂⠄⡀⢀⠠⠐⠈ + #▁▂▃▄▅▆▇█▇▆▅▄▃▂▁ + #←↖↑↗→↘↓↙ + #▖▘▝▗ + #◢◣◤◥ + #┤┘┴└├┌┬┐ + #◰◳◲◱ + #◴◷◶◵ + #◐◓◑◒ + #⣾⣽⣻⢿⡿⣟⣯⣷ + printf '\033[s\033[u[ ▁ ] %s\033[u' "$str"; sleep "$delay" + printf '\033[s\033[u[ ▂ ] %s\033[u' "$str"; sleep "$delay" + printf '\033[s\033[u[ ▃ ] %s\033[u' "$str"; sleep "$delay" + printf '\033[s\033[u[ ▄ ] %s\033[u' "$str"; sleep "$delay" + printf '\033[s\033[u[ ▅ ] %s\033[u' "$str"; sleep "$delay" + printf '\033[s\033[u[ ▆ ] %s\033[u' "$str"; sleep "$delay" + printf '\033[s\033[u[ ▇ ] %s\033[u' "$str"; sleep "$delay" + printf '\033[s\033[u[ █ ] %s\033[u' "$str"; sleep "$delay" + printf '\033[s\033[u[ ▇ ] %s\033[u' "$str"; sleep "$delay" + printf '\033[s\033[u[ ▆ ] %s\033[u' "$str"; sleep "$delay" + printf '\033[s\033[u[ ▅ ] %s\033[u' "$str"; sleep "$delay" + printf '\033[s\033[u[ ▄ ] %s\033[u' "$str"; sleep "$delay" + printf '\033[s\033[u[ ▃ ] %s\033[u' "$str"; sleep "$delay" + printf '\033[s\033[u[ ▂ ] %s\033[u' "$str"; sleep "$delay" + printf '\033[s\033[u[ ▁ ] %s\033[u' "$str"; sleep "$delay" + done + wait "${proc}" + retval=$? + printf '\033[s\033[u%*s\033[u\033[0m' $((${#str}+6)) " " # return to normal + tput cnorm # restore cursor + return $retval +} + +export -f spinner diff --git a/spinner.sh b/spinner.sh deleted file mode 100644 index 74cb450..0000000 --- a/spinner.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash - -## spinner takes the pid of the process as the first argument and -# string to display as second argument (default provided) and spins -# until the process completes. -spinner() { - local proc="$1" - #local str="${2:-'Copyright of KatworX© Tech. Developed by Arjun Singh Kathait and Debugged by the ☆Stack Overflow Community☆'}" - local str="" - local delay="0.1" - tput civis # hide cursor - printf "%b" "${WHT}" - while [ -d /proc/"$proc" ]; do - #-\|/ - #⠁⠂⠄⡀⢀⠠⠐⠈ - #▁▂▃▄▅▆▇█▇▆▅▄▃▂▁ - #←↖↑↗→↘↓↙ - #▖▘▝▗ - #◢◣◤◥ - #┤┘┴└├┌┬┐ - #◰◳◲◱ - #◴◷◶◵ - #◐◓◑◒ - #⣾⣽⣻⢿⡿⣟⣯⣷ - printf '\033[s\033[u[ ▁ ] %s\033[u' "$str"; sleep "$delay" - printf '\033[s\033[u[ ▂ ] %s\033[u' "$str"; sleep "$delay" - printf '\033[s\033[u[ ▃ ] %s\033[u' "$str"; sleep "$delay" - printf '\033[s\033[u[ ▄ ] %s\033[u' "$str"; sleep "$delay" - printf '\033[s\033[u[ ▅ ] %s\033[u' "$str"; sleep "$delay" - printf '\033[s\033[u[ ▆ ] %s\033[u' "$str"; sleep "$delay" - printf '\033[s\033[u[ ▇ ] %s\033[u' "$str"; sleep "$delay" - printf '\033[s\033[u[ █ ] %s\033[u' "$str"; sleep "$delay" - printf '\033[s\033[u[ ▇ ] %s\033[u' "$str"; sleep "$delay" - printf '\033[s\033[u[ ▆ ] %s\033[u' "$str"; sleep "$delay" - printf '\033[s\033[u[ ▅ ] %s\033[u' "$str"; sleep "$delay" - printf '\033[s\033[u[ ▄ ] %s\033[u' "$str"; sleep "$delay" - printf '\033[s\033[u[ ▃ ] %s\033[u' "$str"; sleep "$delay" - printf '\033[s\033[u[ ▂ ] %s\033[u' "$str"; sleep "$delay" - printf '\033[s\033[u[ ▁ ] %s\033[u' "$str"; sleep "$delay" - done - wait "${proc}" - retval=$? - printf '\033[s\033[u%*s\033[u\033[0m' $((${#str}+6)) " " # return to normal - tput cnorm # restore cursor - return $retval -} - -export -f spinner -- cgit v1.2.3-54-g00ecf