From: espie Date: Mon, 18 May 2015 10:25:10 +0000 (+0000) Subject: since the progressmeter is always tied to a state, store the state always, X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ecb1e57b5cb7b1f22b99fc14be16915d072aa01d;p=openbsd since the progressmeter is always tied to a state, store the state always, and not just in the Term case. allows passing less parameters around. --- diff --git a/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm b/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm index f5fdb28370f..241f4f234d9 100644 --- a/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm +++ b/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm @@ -1,5 +1,5 @@ # 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 # @@ -44,10 +44,10 @@ sub compute_size 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; } } @@ -56,8 +56,8 @@ sub disable {} 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 @@ -116,13 +116,12 @@ package PureSizer; 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; } @@ -137,8 +136,8 @@ sub advance 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; diff --git a/usr.sbin/pkg_add/OpenBSD/ProgressMeter/Term.pm b/usr.sbin/pkg_add/OpenBSD/ProgressMeter/Term.pm index 655959b5230..d0ded47b69f 100644 --- a/usr.sbin/pkg_add/OpenBSD/ProgressMeter/Term.pm +++ b/usr.sbin/pkg_add/OpenBSD/ProgressMeter/Term.pm @@ -1,5 +1,5 @@ # 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 # @@ -61,8 +61,8 @@ sub compute_count 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 @@ -295,11 +295,11 @@ our @ISA = qw(PureSizer); 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});