Created
May 10, 2018 03:15
-
-
Save rawiriblundell/52d5a2ada5b602ec6bce68e6e5234d52 to your computer and use it in GitHub Desktop.
Print any number of stars and use font effects (dim, normal, bold) to give the effect of progress, goes from side to side
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| progWidth="${1:-3}" | |
| sleepTime="0.2" | |
| resetTerm() { | |
| tput sgr0 # Unset as many things that we've set as possible | |
| tput cnorm # Display the cursor again | |
| printf '%s\n' "" | |
| exit 0 | |
| } | |
| # Try to set things back the way they were, however we exit | |
| trap resetTerm HUP INT QUIT TERM EXIT | |
| # GNU sleep can handle fractional seconds, non-GNU cannot | |
| # so we default to 1 second resolution in that scenario | |
| if ! sleep "${sleepTime}" &>/dev/null; then | |
| sleepTime=1 | |
| fi | |
| tput sc # Capture position | |
| tput civis # Hide cursor | |
| tput dim # Set base emphasis | |
| printf '%*s' "${progWidth}" | tr ' ' "*" # Setup base char width | |
| while true; do # Infinite loop | |
| tput rc # Return to saved position | |
| for ((i=0;i<progWidth;i++)); do # Iterate horizontally | |
| for em in dim sgr0 bold sgr0 dim; do # Emphasis sequence | |
| printf -- '%s' "$(tput "${em}")*" # Output emphasised char | |
| sleep "${sleepTime}" # Pause for effect | |
| tput cub1 # Move left one char | |
| done | |
| tput cuf1 # Move right one char | |
| done | |
| tput cub1 | |
| for ((i=progWidth;i>0;i--)); do | |
| for em in dim sgr0 bold sgr0 dim; do | |
| printf -- '%s' "$(tput "${em}")*" | |
| sleep "${sleepTime}" | |
| tput cub1 | |
| done | |
| tput cub1 | |
| done | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment