# ex:ts=8 sw=4:
-# $OpenBSD: ProgressMeter.pm,v 1.50 2021/01/30 10:43:43 espie Exp $
+# $OpenBSD: ProgressMeter.pm,v 1.51 2021/01/30 11:19:01 espie Exp $
#
# Copyright (c) 2010 Marc Espie <espie@openbsd.org>
#
$self->{continued} = 1;
}
+sub can_output
+{
+ my $self = shift;
+ return $self->{state}->can_output;
+}
+
# stub class when no actual progressmeter that still prints out.
package OpenBSD::ProgressMeter::Stub;
our @ISA = qw(OpenBSD::ProgressMeter);
# ex:ts=8 sw=4:
-# $OpenBSD: Term.pm,v 1.41 2021/01/30 10:43:43 espie Exp $
+# $OpenBSD: Term.pm,v 1.42 2021/01/30 11:19:01 espie Exp $
#
# Copyright (c) 2004-2007 Marc Espie <espie@openbsd.org>
#
sub message
{
my ($self, $message) = @_;
+ return unless $self->can_output;
if ($self->{cleareol}) {
$message .= $self->{cleareol};
} elsif ($self->{playfield} > length($message)) {
{
my ($self, $current, $total) = @_;
+ return unless $self->can_output;
+
if ($self->{playfield}) {
my $stars = int (($current * $self->{playfield}) / $total + 0.5);
my $percent = int (($current * 100)/$total + 0.5);
{
my $self = shift;
return unless length($self->{lastdisplay}) > 0;
- if ($self->{cleareol}) {
- print "\r", $self->{cleareol};
- } else {
- print "\r", ' 'x length($self->{lastdisplay}), "\r";
+ if ($self->can_output) {
+ if ($self->{cleareol}) {
+ print "\r", $self->{cleareol};
+ } else {
+ print "\r", ' 'x length($self->{lastdisplay}), "\r";
+ }
}
$self->{lastdisplay} = '';
delete $self->{stars};
sub disable
{
my $self = shift;
- print "\n" if length($self->{lastdisplay}) > 0;
+ print "\n" if length($self->{lastdisplay}) > 0 and $self->can_output;
bless $self, "OpenBSD::ProgressMeter::Stub";
}
$self->clear;
$todo //= 'ok';
- print "\r$self->{header}: $todo\n";
+ print "\r$self->{header}: $todo\n" if $self->can_output;
}
package ProgressSizer;
# ex:ts=8 sw=4:
-# $OpenBSD: State.pm,v 1.66 2021/01/30 10:37:22 espie Exp $
+# $OpenBSD: State.pm,v 1.67 2021/01/30 11:19:01 espie Exp $
#
# Copyright (c) 2007-2014 Marc Espie <espie@openbsd.org>
#
$self->{subst} = OpenBSD::Subst->new;
$self->{repo} = OpenBSD::PackageRepositoryFactory->new($self);
$self->{export_level} = 1;
+ $SIG{'CONT'} = sub {
+ $self->handle_continue;
+ }
}
sub repo
sub handle_continue
{
my $self = shift;
- $self->find_window_size(1);
+ $self->find_window_size(1); # 1 is legacy interface for dpb
+ # invalidate cache so this runs again after continue
+ delete $self->{can_output};
}
+OpenBSD::Auto::cache(can_output,
+ sub {
+ require POSIX;
+ # XXX uses POSIX semantics so fd, we can hardcode stdout ;)
+ return getpgrp() == POSIX::tcgetpgrp(1);
+ });
+
sub sync_display
{
}
sub _print
{
my $self = shift;
- $self->_fhprint(\*STDOUT, @_);
+ $self->_fhprint(\*STDOUT, @_) if $self->can_output;
}
sub _errprint
sub print
{
my $self = shift;
- $self->fhprint(\*STDOUT, @_);
+ $self->fhprint(\*STDOUT, @_) if $self->can_output;
}
sub say
{
my $self = shift;
- $self->fhsay(\*STDOUT, @_);
+ $self->fhsay(\*STDOUT, @_) if $self->can_output;
}
sub errprint
$self->find_window_size;
};
}
- $SIG{'CONT'} = sub {
- $self->handle_continue;
- }
}
OpenBSD::Auto::cache(signer_list,