added PoC's for spinner and progressbar
This commit is contained in:
parent
994c79c403
commit
fabdacc129
2 changed files with 46 additions and 4 deletions
7
demo.sh
7
demo.sh
|
|
@ -105,3 +105,10 @@ for option in "${my_options[@]}"; do
|
||||||
echo -e "$option\t=> ${result[idx]}"
|
echo -e "$option\t=> ${result[idx]}"
|
||||||
((idx++))
|
((idx++))
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Example usage for above:
|
||||||
|
until $(sleep 5); do
|
||||||
|
spin
|
||||||
|
sleep 0.2
|
||||||
|
done
|
||||||
|
endspin
|
||||||
35
functions
35
functions
|
|
@ -281,6 +281,41 @@ ctrl_c(){
|
||||||
# ensure ctrl-c to cancel script ends the entire process and not just the current function
|
# ensure ctrl-c to cancel script ends the entire process and not just the current function
|
||||||
# trap ctrl_c INT # Commented out by default to prevent abnormal background exits
|
# trap ctrl_c INT # Commented out by default to prevent abnormal background exits
|
||||||
|
|
||||||
|
# Function for spinner status
|
||||||
|
sp="/-\|"
|
||||||
|
sc=0
|
||||||
|
spin() {
|
||||||
|
printf "\b${sp:sc++:1}"
|
||||||
|
((sc==${#sp})) && sc=0
|
||||||
|
}
|
||||||
|
endspin() {
|
||||||
|
printf "\r%s\n" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Example usage for above:
|
||||||
|
# until work_done; do
|
||||||
|
# spin
|
||||||
|
# some_work ...
|
||||||
|
# done
|
||||||
|
# endspin
|
||||||
|
|
||||||
|
# https://github.com/fearside/ProgressBar/blob/master/progressbar.sh
|
||||||
|
progress-bar() {
|
||||||
|
# Process data
|
||||||
|
let _progress=(${1}*100/${2}*100)/100
|
||||||
|
let _done=(${_progress}*4)/10
|
||||||
|
let _left=40-$_done
|
||||||
|
# Build progressbar string lengths
|
||||||
|
_done=$(printf "%${_done}s")
|
||||||
|
_left=$(printf "%${_left}s")
|
||||||
|
|
||||||
|
# 1.2 Build progressbar strings and print the ProgressBar line
|
||||||
|
# 1.2.1 Output example:
|
||||||
|
# 1.2.1.1 Progress : [########################################] 100%
|
||||||
|
printf "\rProgress : [${_done// /#}${_left// /-}] ${_progress}%%"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
# Renders a text based list of options that can be selected by the
|
# Renders a text based list of options that can be selected by the
|
||||||
# user using up, down and enter keys and returns the chosen option.
|
# user using up, down and enter keys and returns the chosen option.
|
||||||
#
|
#
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue