-
Notifications
You must be signed in to change notification settings - Fork 1
/
animate.pl
executable file
·65 lines (51 loc) · 1.38 KB
/
animate.pl
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
#!/usr/bin/perl
use strict;
use warnings;
use Time::HiRes qw(usleep);
use Digest::MD5 qw(md5_hex);
if (!scalar @ARGV) {
print "$0 <height of frame> <width of frame> [wait in seconds] [refresh 1/0]$/";
print
' Reads from stdin in frames of a given height'.$/.
' clearing the screen between each frame. Piping'.$/.
' input in strongly recomended.'.$/;
exit;
}
my $height = 10;
$height = $1 if (scalar @ARGV > 0 && $ARGV[0] =~ /(\d+)/);
exit 1 unless $height;
my $width = 10;
$width = $1 if (scalar @ARGV > 1 && $ARGV[1] =~ /(\d+)/);
exit 2 unless $width;
my $wait = 0;
$wait = $1 if (scalar @ARGV > 2 && $ARGV[2] =~ /(\d*\.?\d+)/);
$wait = 0 unless $wait;
$wait *= 1000000;
my $refresh = 1;
$refresh = $1 if (scalar @ARGV > 3 && $ARGV[3] =~ /(\d*\.?\d+)/);
my $lastRun = 0;
my $compare = 0;
while (1)
{
my @lines;
for my $i(1..$height)
{
exit if eof STDIN;
my $line = <STDIN>;
chomp $line;
push (@lines, "|$line|");
}
my $thisRun = md5_hex(join ('', @lines));
if ($thisRun eq $compare)
{
sleep 1;
exit;
}
$compare = $lastRun;
$lastRun = $thisRun;
system('clear') if $refresh;
print '+'; print '-' for (1..$width); print "+".$/;
print join ($/, @lines).$/;
print '+'; print '-' for (1..$width); print "+".$/;
usleep $wait;
}