From 34698289a4662b104b2ff282ec177c666100f563 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 8 Mar 2023 10:39:12 -0800 Subject: [PATCH] v1.1.5 - added additional spinner styles --- demo.sh | 20 ++++++------ functions | 91 ++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 85 insertions(+), 26 deletions(-) mode change 100644 => 100755 demo.sh diff --git a/demo.sh b/demo.sh old mode 100644 new mode 100755 index 0061b9f..191f867 --- a/demo.sh +++ b/demo.sh @@ -1,11 +1,10 @@ #!/bin/bash # Initial Vars -VERSION=1.0.0 +VERSION=1.1.0 scriptname="${0##*/}" rundir="${0%/*}" runuser="$(whoami)" -pretty_date="$(date +%Y-%m-%d_%H-%M-%S)" source ${rundir}/functions @@ -45,6 +44,8 @@ boxborder \ "${red}${unl}Red + Underline${dfl}" \ "${red}${inv}Red + Inverted${dfl}" # boxborder + +# demo different box border types echo "" boxborder "${lyl}Bounding Boxes${dfl}" box-double @@ -60,6 +61,7 @@ boxborder "Single Character" box-norm boxborder "Normal" +# Demo interactive menus boxborder \ "${lyl}Keyboard Interactive Menus${dfl}"\ $(boxseparator) \ @@ -80,7 +82,7 @@ choice=$? echo "Choosen index = $choice" echo " value = ${options[$choice]}" -# Examples for above select_opt +# Examples for select_opt case `select_opt "Yes" "No" "Cancel"` in 0) echo "selected Yes";; 1) echo "selected No";; @@ -106,9 +108,9 @@ for option in "${my_options[@]}"; do ((idx++)) done -# Example usage for above: - until $(sleep 5); do - spin - sleep 0.2 - done - endspin \ No newline at end of file +# Spinner +for i in {1..11} ; do + boxborder "spinner$i demo" + set_spinner spinner$i + spin "sleep 3" +done \ No newline at end of file diff --git a/functions b/functions index 8fb57bd..397f2f9 100644 --- a/functions +++ b/functions @@ -2,7 +2,7 @@ # pyr0ball script functions library # Initial Vars -functionsrev=1.1.4 +functionsrev=1.1.5 scriptname="${0##*/}" rundir="${0%/*}" rundir_absolute=$(cd `dirname $0` && pwd) @@ -10,6 +10,12 @@ runuser="$(whoami)" pretty_date="$(date +%Y-%m-%d_%H-%M-%S)" short_date="$(date +%Y-%m-%d)" +# return any cursor mods to normal on exit +cleanup(){ + tput cnorm +} +trap cleanup EXIT + # Escape characters (if your shell uses a different one, you can modify it here) # By default this is using the usual bash escape code ESC=$( printf '\033') @@ -556,24 +562,75 @@ ctrl_c(){ # Function for spinner status # usage: spin "command [args]" -spin() { - sp="/-\|" - sc=0 - $@ & - _PID=&! - while [ -d /proc/$_PID ] ; do - printf "\b${sp:sc++:1}" - ((sc==${#sp})) && sc=0 - done - printf "\r%s\n" "$@" +set_spinner() { + case $1 in + spinner1) + FRAME="⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏" + FRAME_INTERVAL=0.05 + ;; + spinner2) + FRAME="-\|/" + FRAME_INTERVAL=0.1 + ;; + spinner3) + FRAME="◐◓◑◒" + FRAME_INTERVAL=0.2 + ;; + spinner4) + FRAME=":(:|:):D" + FRAME_INTERVAL=0.5 + ;; + spinner5) + FRAME="◇◈◆◈" + FRAME_INTERVAL=0.2 + ;; + spinner6) + FRAME="⚬⚭⚮⚯⚮⚭" + FRAME_INTERVAL=0.2 + ;; + spinner7) + FRAME="░▒▓█▓▒" + FRAME_INTERVAL=0.25 + ;; + spinner8) + FRAME="☉◎◉◎☉" + FRAME_INTERVAL=0.1 + ;; + spinner9) + FRAME="♡♥❤♥♡" + FRAME_INTERVAL=0.15 + ;; + spinner10) + FRAME="✧☆★✪✲◌" + FRAME_INTERVAL=0.1 + ;; + spinner11) + FRAME="●◕☯◔◕" + FRAME_INTERVAL=0.25 + ;; + *) + echo "No spinner is defined for $1" + exit 1 + esac } -# Example usage for above: -# until work_done; do -# spin -# some_work ... -# done -# endspin +spin() { + tput civis + sc=0 + CMD=$@ + $CMD & + _PID=$! + while [ -d /proc/$_PID ] ; do + for i in "${FRAME[@]}" ; do + printf "\b${FRAME:sc++:1}" + ((sc==${#FRAME})) && sc=0 + #echo -ne "\b${FRAME[$i]}" + sleep $FRAME_INTERVAL + done + done + printf "\r\n" + tput cnorm +} # https://github.com/fearside/ProgressBar/blob/master/progressbar.sh progress-bar() {