# ex:ts=8 sw=4:
-# $OpenBSD: ProgressMeter.pm,v 1.45 2014/12/22 14:24:56 espie Exp $
+# $OpenBSD: ProgressMeter.pm,v 1.46 2015/05/18 10:25:10 espie Exp $
#
# Copyright (c) 2010 Marc Espie <espie@openbsd.org>
#
sub setup
{
my ($self, $opt_x, $opt_m, $state) = @_;
+ $self->{state} = $state;
if ($opt_m || (!$opt_x && -t STDOUT)) {
require OpenBSD::ProgressMeter::Term;
bless $self, "OpenBSD::ProgressMeter::Term";
- $self->{state} = $state;
$self->init;
}
}
sub new_sizer
{
- my ($progress, $plist, $state) = @_;
- return $progress->sizer_class->new($progress, $plist, $state);
+ my ($progress, $plist) = @_;
+ return $progress->sizer_class->new($progress, $plist);
}
sub sizer_class
sub new
{
- my ($class, $progress, $plist, $state) = @_;
+ my ($class, $progress, $plist) = @_;
$plist->{totsize} //= $progress->compute_size($plist);
bless {
progress => $progress,
totsize => $plist->{totsize},
donesize => 0,
- state => $state
}, $class;
}
sub saved
{
my $self = shift;
- $self->{state}{stats}{totsize} += $self->{totsize};
- $self->{state}{stats}{donesize} += $self->{donesize};
+ $self->{progress}{state}{stats}{totsize} += $self->{totsize};
+ $self->{progress}{state}{stats}{donesize} += $self->{donesize};
}
1;
# ex:ts=8 sw=4:
-# $OpenBSD: Term.pm,v 1.30 2015/01/04 14:20:04 espie Exp $
+# $OpenBSD: Term.pm,v 1.31 2015/05/18 10:25:10 espie Exp $
#
# Copyright (c) 2004-2007 Marc Espie <espie@openbsd.org>
#
sub visit_with_size
{
my ($progress, $plist, $method, $state, @r) = @_;
- my $p = $progress->new_sizer($plist, $state);
- $plist->size_and($p, $method, $state, @r);
+ my $p = $progress->new_sizer($plist);
+ $plist->size_and($p, $method, $progress->{state}, @r);
}
sub sizer_class
sub new
{
- my ($class, $progress, $plist, $state) = @_;
- my $p = $class->SUPER::new($progress, $plist, $state);
+ my ($class, $progress, $plist) = @_;
+ my $p = $class->SUPER::new($progress, $plist);
$progress->show(0, $p->{totsize});
- if (defined $state->{archive}) {
- $state->{archive}->set_callback(
+ if (defined $progress->{state}{archive}) {
+ $progress->{state}{archive}->set_callback(
sub {
my $done = shift;
$progress->show($p->{donesize} + $done, $p->{totsize});