-
Notifications
You must be signed in to change notification settings - Fork 10
/
example.sh
executable file
·98 lines (77 loc) · 1.31 KB
/
example.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
## include
. term.sh
## data
declare -a data=( 0 2 3 1 3 3 3 8 2 12 4 2 4 3 )
## clean up everything
cleanup () {
## clear
term clear screen
## bring back cursor
term cursor show
return 0
}
## on SIGINT signal
onsigint () {
cleanup
exit 1
}
## clear screen
term clear screen
## position to top left
term move 0 0
## clear line
term clear line
## hide cursor
term cursor hide
## catch sigint
trap "onsigint" SIGINT
## main loop
{
let pad=3
let n=0
let w=($(tput cols))
let h=($(tput lines))
let x=0
let y=0
let len="${#data[@]}"
term clear screen
term move ${pad} 1
## y axis
for (( n = 0; n < (h - pad - 1); n += 2 )); do
term transition 0 2
term color gray
printf "."
done
y=( ${h} - 2 )
term move ${pad} ${y}
## x axis
for (( n = 0; n < (w - pad * 3); n += 6)); do
term color gray
printf "."
term transition 6 0
done
x=0
for (( i = 0; i < len; ++i )); do
let n="${data[$i]}"
while (( n-- )); do
if (( n < 0 )); then
break
fi
let a=( ${x} * 6 + ${pad} )
let b=( ${h} - ${n} + ${pad} )
#echo $a $b
term move ${a} ${b}
term reset
printf "█"
done
(( x++ ))
sleep .5
done
h=( ${h} - 1)
term move ${w} ${h}
}
## clean up terminal
cleanup
## exit
exit $?