-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloading.sh
executable file
·58 lines (50 loc) · 1.89 KB
/
loading.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Load in the functions and animations
source ./bash_loading_animations.sh
# Run BLA::stop_loading_animation if the script is interrupted
trap BLA::stop_loading_animation SIGINT
BLA_passing_dots=( 0.25 '. ' '.. ' '...' ' ..' ' .' ' ' )
declare -a BLA_active_loading_animation
BLA::play_loading_animation_loop() {
while true ; do
for frame in "${BLA_active_loading_animation[@]}" ; do
printf "\r%s" "${frame}"
sleep "${BLA_loading_animation_frame_interval}"
done
done
}
BLA::start_loading_animation() {
BLA_active_loading_animation=( "${@}" )
# Extract the delay between each frame from array BLA_active_loading_animation
BLA_loading_animation_frame_interval="${BLA_active_loading_animation[0]}"
unset "BLA_active_loading_animation[0]"
tput civis # Hide the terminal cursor
BLA::play_loading_animation_loop &
BLA_loading_animation_pid="${!}"
}
BLA::stop_loading_animation() {
kill "${BLA_loading_animation_pid}" &> /dev/null
printf "\n"
tput cnorm # Restore the terminal cursor
}
animation() {
BLA_active_loading_animation=( "${@}" )
# Extract the delay between each frame from the active_loading_animation array
BLA_loading_animation_frame_interval="${BLA_active_loading_animation[0]}"
# Sleep long enough that all frames are showed
# substract 1 to the number of frames to account for index [0]
demo_duration=$( echo "${BLA_active_loading_animation[0]} * ( ${#BLA_active_loading_animation[@]} - 1 )" | bc )
# Make sure each animation is shown for at least 3 seconds
if [[ $( echo "if (${demo_duration} < 3) 0 else 1" | bc ) -eq 0 ]] ; then
demo_duration=3
fi
unset "BLA_active_loading_animation[0]"
echo
BLA::play_loading_animation_loop &
BLA_loading_animation_pid="${!}"
sleep "${demo_duration}"
kill "${BLA_loading_animation_pid}" &> /dev/null
# clear
}
tput civis # Hide the terminal cursor
# clear
animation "${BLA_passing_dots[@]}"