Skip to content

Instantly share code, notes, and snippets.

@polettix

polettix/tsb1.pl Secret

Created May 9, 2021 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polettix/4a62bc344638a88ee64d5193029cf397 to your computer and use it in GitHub Desktop.
Save polettix/4a62bc344638a88ee64d5193029cf397 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use 5.024;
use warnings;
use experimental qw< postderef signatures >;
no warnings qw< experimental::postderef experimental::signatures >;
use Time::HiRes 'sleep';
use FindBin '$Bin';
use lib "$Bin/local/lib/perl5";
use Term::StatusBar;
my $status = new Term::StatusBar(
label => 'My Status: ',
totalItems => 10, ## Equiv to $status->setItems(10)
);
$status->start; ## Optional, but recommended
do_linear(10);
sub do_linear ($n_items) {
$status->setItems($n_items);
for (1 .. $n_items) {
sleep 0.4;
$status->update;
}
}
#!/usr/bin/env perl
use 5.024;
use warnings;
use experimental qw< postderef signatures >;
no warnings qw< experimental::postderef experimental::signatures >;
use Time::HiRes 'sleep';
use FindBin '$Bin';
use lib "$Bin/local/lib/perl5";
use Term::StatusBar;
my $status = new Term::StatusBar(
label => 'My Status: ',
totalItems => 10, ## Equiv to $status->setItems(10)
startPos => 'bottom',
);
$status->start; ## Optional, but recommended
do_linear(10);
sub do_linear ($n_items) {
$status->setItems($n_items);
for (1 .. $n_items) {
sleep 0.4;
$status->update;
}
}
#!/usr/bin/env perl
use 5.024;
use warnings;
use experimental qw< postderef signatures >;
no warnings qw< experimental::postderef experimental::signatures >;
use FindBin '$Bin';
use lib "$Bin/local/lib/perl5", "$Bin/lib";
use Term::StatusBar;
my $status = new Term::StatusBar(
label => 'My Status: ',
totalItems => 10, ## Equiv to $status->setItems(10)
startPos => 'bottom',
);
$status->start; ## Optional, but recommended
do_random(20);
sub do_linear ($n_items) {
$status->setItems($n_items);
for (1 .. $n_items) {
sleep 0.4;
$status->update;
}
}
sub do_random ($n_items) {
my @chunks;
my $n = $n_items;
while ($n > 0) {
my $chunk = 1 + int(4 * rand);
$chunk = $n if $chunk > $n;
push @chunks, $chunk;
$n -= $chunk;
}
$status->setItems($n_items);
while (@chunks) {
sleep 1;
$status->update(shift @chunks);
}
} ## end sub doSomething
#!/usr/bin/env perl
use 5.024;
use warnings;
use experimental qw< postderef signatures >;
no warnings qw< experimental::postderef experimental::signatures >;
use Time::HiRes 'sleep';
use FindBin '$Bin';
use lib "$Bin/local/lib/perl5", "$Bin/lib";
use Term::StatusBar;
my $status = new Term::StatusBar(
label => 'My Status: ',
totalItems => 10, ## Equiv to $status->setItems(10)
startPos => 'bottom',
);
$status->start; ## Optional, but recommended
#do_linear(10);
$status->reset;
do_random(20);
sub do_linear ($n_items) {
$status->setItems($n_items);
for (1 .. $n_items) {
sleep 0.4;
$status->update;
}
}
sub do_random ($n_items) {
my @chunks;
my $n = $n_items;
while ($n > 0) {
my $chunk = 1 + int(4 * rand);
$chunk = $n if $chunk > $n;
push @chunks, $chunk;
$n -= $chunk;
}
$status->setItems($n_items);
while (@chunks) {
sleep 1;
$status->update(shift @chunks);
}
} ## end sub doSomething
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment