-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation.sh
executable file
·80 lines (66 loc) · 1.76 KB
/
animation.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
#!/bin/bash
tigerdir=${0%/*}
FRAMES[0]="$tigerdir/frames/walk-01.txt"
FRAMES[1]="$tigerdir/frames/walk-02.txt"
FRAMES[2]="$tigerdir/frames/walk-03.txt"
FRAMES[3]="$tigerdir/frames/walk-04.txt"
FRAMES[4]="$tigerdir/frames/walk-05.txt"
FRAMES[5]="$tigerdir/frames/walk-06.txt"
FRAMES[6]="$tigerdir/frames/walk-07.txt"
FRAMES[7]="$tigerdir/frames/walk-08.txt"
FRAMES[8]="$tigerdir/frames/walk-09.txt"
FRAMES[9]="$tigerdir/frames/walk-10.txt"
# Displays the content of a file with some left padding
function file_display ()
{
echo -ne "\033[s\033[0;0H"
offset=2
echo -ne "\033[38;5;209m"
IFS=''
line_number=0
tput civis
while read file_line
do
echo -ne "\033[${offset}C"
pos=0
while [ $pos -lt ${#file_line} ]; do
chr=${file_line:$pos:1}
if [ $(($pos + $offset)) -lt ${LINE[$line_number]} ]; then
echo -ne "\033[1C"
else
echo -n "$chr"
fi
pos=$((pos + 1))
done
echo
line_number=$(($line_number + 1))
done < $1
tput cnorm
echo -ne "\033[0;m"
echo -ne "\033[u"
}
i=0
count=0
height=$(tput lines)
height=$(($height - 2))
while read line
do
echo "$line"
line=$(echo $line | sed -E "s/\x1B\[[0-9]([0-9])?[;m]([0-9])?([0-9])?(;)?([0-9])?([0-9])?([0-9])?(m)?//g")
if [ $count -lt $height ]; then
LINE[$count]=${#line}
else
file_display "${FRAMES[$i]}"
tmp=0
while [ $tmp -lt $height ]; do
LINE[$tmp]=${LINE[$(($tmp + 1))]}
tmp=$(($tmp + 1))
done
LINE[$(($height - 1))]=${#line}
fi
i=$(($i + 1))
count=$(($count + 1))
if [ $i -ge 10 ]; then
i=0
fi
done < "/dev/stdin"