-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfancy-printing-examples.sh
executable file
·63 lines (56 loc) · 1.31 KB
/
fancy-printing-examples.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
59
60
61
62
63
#!/usr/bin/env bash
# Examples that print to the terminal in a fancy way
# Taken from https://stackoverflow.com/a/238094
function progressBarEcho() {
echo -ne '## (20%)\r'
sleep .5
echo -ne '##### (50%)\r'
sleep .5
echo -ne '######## (80%)\r'
sleep .5
echo -ne '######### (90%)\r'
sleep .5
echo '########## (100%)'
}
#progressBarEcho
# Create a spinner animation using 'printf'
# Taken from https://stackoverflow.com/a/3330834
function spinnerPrintf() {
i=1
sp="/-\|"
echo -n ' '
while true
do
printf "\b${sp:i++%${#sp}:1}"
sleep .05
done
}
#spinnerPrintf
# Do some fancy printing by moving the cursor around.
# We use ANSI escape sequences to control the cursor.
#
# See https://en.wikipedia.org/wiki/ANSI_escape_code
#
# Warning: this doesn't work very well but it does move the cursor around. This stuff is confusing.
function cursorControl() {
# Print 'Cake'
echo -ne '[3;1H'
echo -ne 'C'
echo -ne 'a'
echo -ne 'k'
echo -ne 'e'
sleep .5
# Replace the first character ('C') with 'L' to spell 'Lake'
echo -ne '[3;1H'
echo -ne 'L'
sleep .5
# Replace the first character ('L') with 'B' to spell 'Bake'
echo -ne '[3;1H'
echo -ne 'B'
sleep .5
# Replace the first character ('B') with 'T' to spell 'Take'
echo -ne '[3;1H'
echo -e 'T'
sleep .5
}
cursorControl