App-Glacier
view release on metacpan or search on metacpan
lib/App/Glacier/Progress.pm view on Meta::CPAN
}
my $show_default = 1;
if ($v = delete $opts{show_current}) {
$self->{_show_current} = $v;
$show_default = 0;
}
if ($v = delete $opts{show_total}) {
$self->{_show_total} = $v;
$show_default = 0;
}
if ($v = delete $opts{show_percent}) {
$self->{_show_percent} = $v;
$show_default = 0;
}
if ($v = delete $opts{show_dots}) {
$self->{_show_dots} = $v;
$show_default = 0;
}
if ($v = delete $opts{show_none}) {
$show_default = 0;
}
croak "extra arguments" if keys %opts;
if ($show_default) {
$self->{_show_current} = 1;
$self->{_show_total} = 1;
$self->{_show_percent} = 1;
}
if (-t STDOUT) {
$self->{_sigwinch} = $SIG{WINCH};
if (open($self->{_tty}, "+</dev/tty")) {
select((select($self->{_tty}), $|=1)[0]);
} else {
$self->{_tty} = undef;
}
$SIG{WINCH} = sub {
lib/App/Glacier/Progress.pm view on Meta::CPAN
return unless defined $self->{_tty};
my $text = '';
if ($self->{_show_current}) {
$text .= sprintf("%*d", $self->{_digits}, $self->{_current});
}
if ($self->{_show_total}) {
$text .= ' / ' if $self->{_show_current};
$text .= sprintf('%*d', $self->{_digits}, $self->{_total});
}
if ($self->{_show_percent}) {
$text .= ' ' if $text ne '';
$text .= sprintf("%3d%%", int(100 * $self->{_current} / $self->{_total}));
}
$text = $self->{_prefix} . ': ' . $text if $self->{_prefix};
if ($self->{_show_dots}) {
my $w = $self->_getwidth;
if ($w > length($text)) {
$w -= length($text) + 2;
$text .= '.' x int($self->{_current} / $self->{_total} * $w);
( run in 0.409 second using v1.01-cache-2.11-cpan-05162d3a2b1 )