Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Width.

  • Loading branch information...
commit e235555224ca79540ac364ffff425079f7079082 1 parent 0bfc0da
@sergot authored
Showing with 8 additions and 7 deletions.
  1. +8 −7 lib/Term/ProgressBar.pm
View
15 lib/Term/ProgressBar.pm
@@ -4,24 +4,25 @@ class Term::ProgressBar;
has Int $.count = 100;
has Str $.name = " ";
-has Bool $.p = True;
+has Bool $.p;
# optional
has $.blocka = '[';
has $.blockb = ']';
has $.style = '=';
-#has $!width; TODO
-has $!as;
+has Int $.width = 100;
+
+has Str $!as;
method update(Int $step) {
- my $multi = ($step/($.count/100)).floor;
+ my $multi = ($step/($.count/$.width)).floor;
my $ext = ' ';
if $.p {
- $ext ~= $multi~"%";
+ $ext ~= $multi*(100/$.width).round(0.1)~"%";
}
- if $step % ($.count/100).floor == 0 {
- $!as = "$.name "~$.blocka~($.style x $multi)~(' ' x (100 - $multi))~$.blockb~" $ext";
+ if $step % ($.count/$.width).floor == 0 {
+ $!as = "$.name "~$.blocka~($.style x $multi)~(' ' x ($.width - $multi))~$.blockb~" $ext";
print $!as, "\r";
}
say if $step == $.count;
Please sign in to comment.
Something went wrong with that request. Please try again.