summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2010-10-25 11:04:48 +0000
committerMarc Espie <espie@cvs.openbsd.org>2010-10-25 11:04:48 +0000
commitcf8ae982ad7cc36cf8d229763cc8301a21a563e0 (patch)
treee10f2600f6e14d41da5f72fe66675246bb869edf
parentab5b296feb0bec49dfe5ed44f70967ac706e5ec5 (diff)
separate "Term" part from "Real progressmeter" handling, so that one can
use the common part independently.
-rw-r--r--usr.sbin/pkg_add/OpenBSD/ProgressMeter/Term.pm106
1 files changed, 55 insertions, 51 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/ProgressMeter/Term.pm b/usr.sbin/pkg_add/OpenBSD/ProgressMeter/Term.pm
index d7d67dee0a0..d50a4d5afab 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.14 2010/08/03 17:31:52 espie Exp $
+# $OpenBSD: Term.pm,v 1.15 2010/10/25 11:04:47 espie Exp $
#
# Copyright (c) 2004-2007 Marc Espie <espie@openbsd.org>
#
@@ -50,8 +50,61 @@ sub count_and
$self->$method(@r);
}
-package OpenBSD::ProgressMeter::Term;
+package OpenBSD::ProgressMeter::Real;
our @ISA = qw(OpenBSD::ProgressMeter);
+
+sub ntogo
+{
+ my ($self, $state, $offset) = @_;
+ return $state->ntogo_string($offset);
+}
+
+sub compute_size
+{
+ my $plist = shift;
+ my $totsize = 0;
+ $plist->compute_size(\$totsize);
+ $totsize = 1 if $totsize == 0;
+ return $totsize;
+}
+
+sub compute_count
+{
+ my $plist = shift;
+ my $total = 0;
+ $plist->compute_count(\$total);
+ $total = 1 if $total == 0;
+ return $total;
+}
+
+sub visit_with_size
+{
+ my ($progress, $plist, $method, $state, @r) = @_;
+ $plist->{totsize} //= compute_size($plist);
+ my $donesize = 0;
+ $progress->show($donesize, $plist->{totsize});
+ if (defined $state->{archive}) {
+ $state->{archive}{callback} = sub {
+ my $done = shift;
+ $progress->show($donesize + $done, $plist->{totsize});
+ };
+ }
+ $plist->size_and($progress, \$donesize, $plist->{totsize},
+ $method, $state, @r);
+}
+
+sub visit_with_count
+{
+ my ($progress, $plist, $method, $state, @r) = @_;
+ $plist->{total} //= compute_count($plist);
+ my $count = 0;
+ $progress->show($count, $plist->{total});
+ $plist->count_and($progress, \$count, $plist->{total},
+ $method, $state, @r);
+}
+
+package OpenBSD::ProgressMeter::Term;
+our @ISA = qw(OpenBSD::ProgressMeter::Real);
use POSIX;
use Term::Cap;
@@ -252,53 +305,4 @@ sub next
print "\r$self->{header}: $todo\n";
}
-sub ntogo
-{
- my ($self, $state, $offset) = @_;
- return $state->ntogo_string($offset);
-}
-
-sub compute_size
-{
- my $plist = shift;
- my $totsize = 0;
- $plist->compute_size(\$totsize);
- $totsize = 1 if $totsize == 0;
- return $totsize;
-}
-
-sub compute_count
-{
- my $plist = shift;
- my $total = 0;
- $plist->compute_count(\$total);
- $total = 1 if $total == 0;
- return $total;
-}
-
-sub visit_with_size
-{
- my ($progress, $plist, $method, $state, @r) = @_;
- $plist->{totsize} //= compute_size($plist);
- my $donesize = 0;
- $progress->show($donesize, $plist->{totsize});
- if (defined $state->{archive}) {
- $state->{archive}{callback} = sub {
- my $done = shift;
- $progress->show($donesize + $done, $plist->{totsize});
- };
- }
- $plist->size_and($progress, \$donesize, $plist->{totsize},
- $method, $state, @r);
-}
-
-sub visit_with_count
-{
- my ($progress, $plist, $method, $state, @r) = @_;
- $plist->{total} //= compute_count($plist);
- my $count = 0;
- $progress->show($count, $plist->{total});
- $plist->count_and($progress, \$count, $plist->{total},
- $method, $state, @r);
-}
1;