Skip to content

Instantly share code, notes, and snippets.

@jmcveigh
Last active July 4, 2016 12:48
Show Gist options
  • Save jmcveigh/dc7783f462dc9c6dd6a26b7716db454a to your computer and use it in GitHub Desktop.
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.
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 => '';
use constant TEXT_CURSOR_POSITION_PROGRESSBAR_BEGIN => '';
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__
Ü
Üþ   Ü
 Ü Ü ÞÝÛ nnew usr voting
 ÛßßÛÜÜ   Ü  ß   ß  Ü ß
 ßßÛÜÜßÛÛÜÜßßßÜß Ü ÛÛßßÜÜÛß Ü ÛÜÛ Ü ßÛÜÜßÜÜß
 Û°° ÛÛÛÛßÛ Ü ÛÛÛßÛÛÛÛß ÜÛ ßÜ ÛÛÛÛÛÛ°°Û 
ÛÛÛ²²ÛÛÛÛÛÛß ÛÛ°°ÛÛÛ²²²²² ÛÛÛÛÛ°²²ÛÛÛ²  ßßßß ²²²²²²² ßß °²ÛÛ° ° ²²²²² ßß ±±±±± ²²²²° ßß ±°±±²²² ßß ß ßßßßßßßßßßßßßßßßßßܱ±±²±±±±±°±°  ±°°±±±Û°°° Ü ±°±±± ²±°°°°±  Ü 
°°±°°°°ßÜÜܲ° Û±°ÛÝßßÜ ±ÜÜÛÜ Üß°±²ÜÜ ±ßÜÜßßÜß Ü 
Ü Û°²±±±²Ü   ßßÞ  ßßßß ßßßÜÜÛÛÜ ß Ü ßß ßßß Ü  
 ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ 
Üßß ßßÜ
ÞÝÞÝÛÛ² nowplay²± group±° bonk..° song genre
ggensoft (zenbae) typing .. [ # status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment