Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use POSIX qw(strftime);
- use Getopt::Long qw(GetOptions);
- use IO::Handle;
- use Data::Dumper;
- STDOUT->autoflush();
- my $time;
- my $gentable;
- my $X_size = 8;
- my $Y_size = 11;
- my $_digits =
- "
- +12345678|12345678|12345678|12345678|12345678|12345678|12345678|12345678|12345678|12345678|12345678|
- 1|...11...|..2222..|..3333..|....44..|.555555.|..6666..|.777777.|..8888..|..9999..|..0000..|........|
- 2|..111...|.22..22.|.3...33.|...444..|.5....5.|.66.....|.....77.|.88..88.|.99..99.|.00..00.|...::...|
- 3|.1111...|....22..|.....33.|..4..4..|.55.....|.6......|....77..|..8..8..|.9....9.|.0....0.|..::::..|
- 4|...11...|...22...|...33...|.4...4..|.55555..|.66666..|...77...|...88...|.99..99.|.0....0.|...::...|
- 5|...11...|..22....|...33...|.44444..|.....55.|.66..66.|..77....|...88...|..99999.|.0....0.|........|
- 6|...11...|.22.....|.....33.|....44..|......5.|.6....6.|.77.....|..8..8..|......9.|.0....0.|...::...|
- 7|.1.11.1.|.2....2.|.3...33.|....44..|.5...55.|.66..66.|.77.....|.88..88.|.....99.|.00..00.|..::::..|
- 8|.111111.|.222222.|..3333..|..44444.|..5555..|..6666..|.77.....|..8888..|..9999..|..0000..|...::...|
- ";
- GetOptions(
- 'gentable|g' => \$gentable,
- 'height|x=i' => \$X_size,
- 'width|y=i' => \$Y_size) or die;
- if ($gentable) {
- gen_helper_table($X_size,$Y_size);
- } else { show_ascii_clock() };
- sub show_ascii_clock {
- my @display_matrix;
- my @display_rows = split(/\n/,$_digits);
- @$display_rows = shift(@display_rows); # get rid of the mess
- @$display_rows = shift(@display_rows); # must be cleaner solution
- # but i want to sleep, it's 3AM;
- for (;;) {
- $time = strftime "%H:%M:%S", localtime;
- for (@display_rows) {
- my @array = split(/\|/,$_);
- foreach(split(//,$time))
- {
- if ($_ =~ /^[1-9]/) {
- print $array[$_];
- } elsif ($_ =~ /0/) {
- print $array[$Y_size-1];
- } else {
- print $array[$Y_size];
- }
- }
- print "\n";
- }
- sleep 1;
- system("tput clear"); # clear the terminal
- }
- };
- sub gen_helper_table { # use cat > *.txt
- my($X,$Y) = @_;
- my $line = 1;
- print " " x length($X);
- print "+";
- foreach (1..$Y) { # gen first line
- foreach (1..$X) {
- $_ = $_ + 0;
- print $_ % 10;
- $_++;
- }
- print "|";
- }
- print "\n";
- foreach (1..$X) {
- if (length($X)>1) {
- my $indent = length($X)-length($line);
- print " " x $indent;
- }
- print $line;
- foreach (1..$Y) {
- print "|";
- print "." x $X;
- }
- print "|\n";
- $line++;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement