Last active
July 4, 2016 12:48
-
-
Save jmcveigh/dc7783f462dc9c6dd6a26b7716db454a to your computer and use it in GitHub Desktop.
This writes to STDOUT the Ansi Art included as DATA_NUV_HEADER as colours using Inline::Files then new process with ProgressBar then exit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use common::sense; | |
my ($max,$wrk) = (100, undef); | |
# below is the Worker1 routine | |
package Worker1 { | |
use Moose; | |
use threads; | |
use threads::shared; | |
use Term::ANSIColor qw(color); | |
use Term::ProgressBar; | |
use Time::HiRes qw(usleep); | |
use constant TEXT_CURSOR_POSITION_STATUS_BEGIN => '[27;33H'; | |
use constant TEXT_CURSOR_POSITION_PROGRESSBAR_BEGIN => '[29;0H'; | |
use namespace::autoclean; | |
my $job_in_progress :shared = 0; | |
sub do_job { | |
my $self = shift; | |
my $thr1 = threads->create(\&job); | |
$thr1->join; | |
} | |
sub job_begin { | |
my $self = shift; | |
if ($job_in_progress) { | |
return; | |
} | |
return($job_in_progress = 1); | |
} | |
sub job_end { | |
my $self = shift; | |
$job_in_progress = 0; | |
} | |
sub status { | |
my $status = shift; | |
my $error = shift; | |
$error //= 0; | |
select(STDOUT); | |
$|++; | |
print TEXT_CURSOR_POSITION_STATUS_BEGIN; | |
print color('green') if $error == 0; | |
print color('yellow') if $error == 1; | |
print color('red') if $error == 2; | |
print $status; | |
print TEXT_CURSOR_POSITION_PROGRESSBAR_BEGIN; | |
print color('cyan'); | |
} | |
sub job { | |
if (job_begin) { | |
my $progress = Term::ProgressBar->new($max); | |
for (0..$max) { | |
# this is the work, right here | |
usleep(100); | |
# update status | |
status(sprintf(color('black') . "# this is the status text for the job iteration %03d", $_)); | |
# update progress | |
$progress->update($_) | |
} | |
job_end; | |
} | |
} | |
__PACKAGE__->meta->make_immutable; | |
} | |
package Application { | |
use common::sense; | |
use Moose; | |
use Inline::Files; | |
use Term::ANSIColor qw(color); | |
use Term::ProgressBar; | |
use Text::ANSI::Util qw( | |
ta_length | |
ta_split_codes | |
); | |
use Term::ProgressBar; | |
use feature 'say'; | |
use feature 'state'; | |
use feature 'switch'; | |
use namespace::autoclean; | |
has '_data_nuv_header' => ( | |
is => 'ro', | |
isa => 'ArrayRef[Str]', | |
lazy => 1, | |
required => 1, | |
default => sub { [] }, | |
); | |
sub splat { | |
my ($self, @collection_of_lines) = (shift, @_); | |
my $buffer = ''; | |
for my $line (@collection_of_lines) { | |
$buffer .= $line; | |
} | |
return $buffer; | |
} | |
sub main { | |
my ($self) = @_; | |
# read DATA_NUV_HEADER in to an array of lines | |
$self->_data_nuv_header; | |
while (<DATA_NUV_HEADER>) { | |
push @{$self->_data_nuv_header}, $_; | |
} | |
# also : ta_length($self->splat(@{$self->_data_nuv_header})); | |
my @collection_of_parts = ta_split_codes($self->splat(@{$self->_data_nuv_header})); | |
system('cls'); | |
sleep 1; | |
print "\n" x 2; | |
print "@collection_of_parts", "\n"x 2; | |
sleep 1; | |
$self->proc; | |
print "\n" x 2; | |
print color('white'); | |
sleep 1; | |
exit; | |
} | |
sub proc { | |
$wrk = Worker1->new; | |
$wrk->do_job; | |
} | |
__PACKAGE__->meta->make_immutable; | |
} | |
my $app = Application->new->main unless caller; | |
1; | |
__END__ | |
__DATA_NUV_HEADER__ | |
[0m[55C[35mÜ[37m | |
[36C[35mÜþ[37m[15C[35m [37m [1;35m [0;35mÜ[37m | |
[3C[35m [37m[29C[35mÜ[37m[19C[1;35m [0;35mÜ[37m [30;45mÞÝÛ n[1;35;40mnew usr[0m [1;35mvoti[0;35mng[37m | |
[3C[35m Ûß[1;31mß[0m[8C[35mÛ[1;45mÜ[0;35mÜ [37m [35m Ü [37m[5C[35m ß [37m [35m ß [37m[5C[35m Ü ß[37m | |
[35m ß[1;45mß[0;35mÛÜÜßÛÛÜÜßßßÜß Ü[37m [35mÛÛ[1;45mß[0;35mßÜÜÛ[37m[3C[35mß Ü ÛÜÛ Ü ß[37m[3C[35mÛÜÜßÜ[1;45mÜß[0m | |
[4C[35m Û[1;45m°° [0;35mÛÛÛ[37m[4C[35mÛ[1;45mß[0;35mÛ Ü[37m [35mÛÛÛ[1;45mß[0;35mÛÛÛ[37m[4C[35mÛ[1;45mß[0;35m ÜÛ[37m [1;35;45mß[0;35mÜ ÛÛ[37m[4C[35mÛÛÛÛ[1;45m°°[0;35mÛ[37m[8C[1m [0m | |
[5C[35mÛÛÛ[41m²²[40mÛÛ[37m[4C[35mÛÛÛÛ[1;45mß[0m [35mÛÛ[1;45m°°[0;35mÛÛÛ[37m[4C[35;41m²²²²²[37;40m [35mÛÛÛÛÛ[37m[4C[1;31;41m°[0;35;41m²²ÛÛÛ²[37;40m[8C[1m [0m[13C[1;30m ßßßß [0;35;41m²²²²²²²[37;40m [1;30mßß[0m [1;31;41m°[0;35;41m²ÛÛ[1;31m°[0m [1;31;41m° [0;35;41m²²²²²[37;40m [1;30mßß [0;35;41m±±±±±[37;40m [35;41m²²²²[1;31m°[0m [1;30mßß[0m [1;31;41m±[0;35;41m°±±²²²[37;40m [1;30mßß[0m [35mß[37m [1;30mßßßßßß[0mß[1;30mßßß[0mß[1;30mßßß[0mßß[1mßß[0m[4C[35mÜ[41m±±±²±±±[37;40m[4C[1;31;41m±±°±°[0m [35m [1;31;41m±°°[0;35;41m±±±[40mÛ[37m[4C[35;41m°[1;31m°[0;35;41m°[40m [1;31mÜ[0m [35;41m±[1;31m°[0;35;41m±[1;31m±±[0m[3C[1;31m [41m²±°[0;35;41m°°[1;31m°±[0m [35m [1;31mÜ [0m | |
[5C[35;41m°°[1;31m±°[0;35;41m°°°[37;40m[3C[1;31mßÜÜÜ[41m²[0;35;41m°[40m [1;31;41mÛ±°[40mÛÝßßÜ[0;35m [1;31;41m±[40mÜÜÛÜ[0m [1;31mÜ[0;35mß[1;31;41m°±²[40mÜÜ[0;35m [1;31;41m±[40mßÜÜßßÜß[0m [1;31mÜ [0m | |
[1;31mÜ[0m [1;31mÛ[0;35;41m°[1;31m²±±±²[40mÜ [0m[3C[1;31m [0m [1;31mßßÞ[0m [1;31m ßßßß[0m [1;31mßßßÜÜ[41mÛ[40mÛÜ[0;35m [1;31mß[0;35m [1;31mÜ ßß ßßß[0m [1;31mÜ[0;35m [1;30m [0m | |
[1;30m ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ [0m | |
[1;30mÜßß ßßÜ[0m | |
[1;30mÞÝ[0m[76C[1;30mÞÝÛ[0m[78C[1;30mÛ²[0m [1;30mnowplay[0m[70C[1;30m²±[0m [1;30mgroup[0m[72C[1;30m±°[0m [1;30mbonk..[0m[70C[1;30m°[0m [1;30msong genre[0m | |
g[1;30mgensoft (zenbae) typing .. [ # status[0m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment