1999-10-24 23:45:39 +02:00
|
|
|
|
package output;
|
|
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
|
|
sub new {
|
|
|
|
|
my $proto = shift;
|
|
|
|
|
my $class = ref($proto) || $proto;
|
|
|
|
|
my $self = {};
|
|
|
|
|
bless ($self, $class);
|
|
|
|
|
|
|
|
|
|
my $progress = \${$self->{PROGRESS}};
|
|
|
|
|
my $last_progress = \${$self->{LAST_PROGRESS}};
|
1999-11-08 00:35:03 +01:00
|
|
|
|
my $progress_count = \${$self->{PROGRESS_COUNT}};
|
2000-06-11 22:02:29 +02:00
|
|
|
|
my $prefix = \${$self->{PREFIX}};
|
1999-10-24 23:45:39 +02:00
|
|
|
|
|
|
|
|
|
$$progress = "";
|
|
|
|
|
$$last_progress = "";
|
2000-06-11 22:02:29 +02:00
|
|
|
|
$$progress_count = 0;
|
|
|
|
|
$$prefix = "";
|
1999-10-24 23:45:39 +02:00
|
|
|
|
|
|
|
|
|
return $self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub show_progress {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
my $progress = \${$self->{PROGRESS}};
|
|
|
|
|
my $last_progress = \${$self->{LAST_PROGRESS}};
|
1999-11-08 00:35:03 +01:00
|
|
|
|
my $progress_count = \${$self->{PROGRESS_COUNT}};
|
1999-10-24 23:45:39 +02:00
|
|
|
|
|
1999-11-08 00:35:03 +01:00
|
|
|
|
$$progress_count++;
|
|
|
|
|
|
|
|
|
|
if($$progress_count > 0 && $$progress) {
|
1999-10-24 23:45:39 +02:00
|
|
|
|
print STDERR $$progress;
|
|
|
|
|
$$last_progress = $$progress;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub hide_progress {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
my $progress = \${$self->{PROGRESS}};
|
|
|
|
|
my $last_progress = \${$self->{LAST_PROGRESS}};
|
1999-11-08 00:35:03 +01:00
|
|
|
|
my $progress_count = \${$self->{PROGRESS_COUNT}};
|
|
|
|
|
|
|
|
|
|
$$progress_count--;
|
1999-10-24 23:45:39 +02:00
|
|
|
|
|
|
|
|
|
if($$last_progress) {
|
|
|
|
|
my $message;
|
|
|
|
|
for (1..length($$last_progress)) {
|
|
|
|
|
$message .= " ";
|
|
|
|
|
}
|
|
|
|
|
print STDERR $message;
|
|
|
|
|
undef $$last_progress;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub update_progress {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
my $progress = \${$self->{PROGRESS}};
|
|
|
|
|
my $last_progress = \${$self->{LAST_PROGRESS}};
|
|
|
|
|
|
|
|
|
|
my $prefix = "";
|
|
|
|
|
my $suffix = "";
|
1999-11-08 00:35:03 +01:00
|
|
|
|
if($$last_progress) {
|
|
|
|
|
for (1..length($$last_progress)) {
|
|
|
|
|
$prefix .= "";
|
1999-10-24 23:45:39 +02:00
|
|
|
|
}
|
1999-11-08 00:35:03 +01:00
|
|
|
|
|
|
|
|
|
my $diff = length($$last_progress)-length($$progress);
|
|
|
|
|
if($diff > 0) {
|
|
|
|
|
for (1..$diff) {
|
|
|
|
|
$suffix .= " ";
|
|
|
|
|
}
|
|
|
|
|
for (1..$diff) {
|
|
|
|
|
$suffix .= "";
|
|
|
|
|
}
|
1999-10-24 23:45:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
print STDERR $prefix . $$progress . $suffix;
|
|
|
|
|
$$last_progress = $$progress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub progress {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
my $progress = \${$self->{PROGRESS}};
|
|
|
|
|
|
|
|
|
|
$$progress = shift;
|
|
|
|
|
|
|
|
|
|
$self->update_progress;
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-11 22:02:29 +02:00
|
|
|
|
sub prefix {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
my $prefix = \${$self->{PREFIX}};
|
|
|
|
|
|
|
|
|
|
$$prefix = shift;
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-24 23:45:39 +02:00
|
|
|
|
sub write {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
|
|
my $message = shift;
|
1999-11-08 00:35:03 +01:00
|
|
|
|
|
2000-06-11 22:02:29 +02:00
|
|
|
|
my $prefix = \${$self->{PREFIX}};
|
1999-11-08 00:35:03 +01:00
|
|
|
|
|
1999-10-24 23:45:39 +02:00
|
|
|
|
$self->hide_progress;
|
2000-06-11 22:02:29 +02:00
|
|
|
|
print $$prefix . $message;
|
1999-10-24 23:45:39 +02:00
|
|
|
|
$self->show_progress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
1;
|