ProgressMeter, so make it available from state.
- computation is lazy, so no runtime difference;
- don't bother setting a SIG{WINCH} on non-tty;
- progressmeter already has access to state;
- do an empty window_size_changed in base state, override it for
addcreatedelete to inform the progressmeter.
to be reused in dpb...
# ex:ts=8 sw=4:
-# $OpenBSD: AddCreateDelete.pm,v 1.37 2016/06/15 15:40:13 espie Exp $
+# $OpenBSD: AddCreateDelete.pm,v 1.38 2016/06/23 16:11:23 espie Exp $
#
# Copyright (c) 2007-2014 Marc Espie <espie@openbsd.org>
#
return shift->{interactive}->is_interactive;
}
+sub window_size_changed
+{
+ shift->{progressmeter}->compute_playfield;
+}
+
sub confirm
{
my $self = shift;
# ex:ts=8 sw=4:
-# $OpenBSD: ProgressMeter.pm,v 1.48 2016/06/15 15:31:09 espie Exp $
+# $OpenBSD: ProgressMeter.pm,v 1.49 2016/06/23 16:11:23 espie Exp $
#
# Copyright (c) 2010 Marc Espie <espie@openbsd.org>
#
$self->next;
}
+sub compute_playfield
+{
+}
+
# 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.36 2016/06/15 15:31:09 espie Exp $
+# $OpenBSD: Term.pm,v 1.37 2016/06/23 16:11:23 espie Exp $
#
# Copyright (c) 2004-2007 Marc Espie <espie@openbsd.org>
#
use Term::Cap;
use Term::ReadKey;
+sub width
+{
+ my $self = shift;
+ return $self->{state}->width;
+}
+
sub forked
{
my $self = shift;
- $self->{lastdisplay} = ' 'x($self->{width}-1);
+ $self->{lastdisplay} = ' 'x($self->width-1);
}
sub init
my $oldfh = select(STDOUT);
$| = 1;
select($oldfh);
- $self->find_window_size;
$self->{lastdisplay} = '';
$self->{continued} = 0;
$self->{work} = 0;
}
}
-sub find_window_size
-{
- my $self = shift;
-
- my @l = Term::ReadKey::GetTermSizeGWINSZ(\*STDOUT);
- if (@l != 4) {
- $self->{width} = 80;
- } else {
- $self->{width} = $l[0];
- }
-}
-
sub compute_playfield
{
my $self = shift;
- $self->{playfield} = $self->{width} - length($self->{header}) - 7;
+ $self->{playfield} = $self->width - length($self->{header}) - 7;
# we can print to 80 columns
if ($self->{glitch} && $self->{state}->config->istrue("fullwidth")) {
$self->{playfield} += 1;
my ($self, $header) = @_;
$self->{header} = $header;
$self->compute_playfield;
- $SIG{'WINCH'} = sub {
- $self->find_window_size;
- $self->compute_playfield;
- };
$SIG{'CONT'} = sub {
$self->{continued} = 1;
};
$d.="|$extra";
$prefix++;
}
- if ($self->{width} > length($d)) {
+ if ($self->width > length($d)) {
if ($self->{cleareol}) {
$d .= $self->{cleareol};
} else {
- $d .= ' 'x($self->{width} - length($d) - 1);
+ $d .= ' 'x($self->width - length($d) - 1);
}
}
# ex:ts=8 sw=4:
-# $OpenBSD: State.pm,v 1.35 2016/06/23 12:44:10 espie Exp $
+# $OpenBSD: State.pm,v 1.36 2016/06/23 16:11:23 espie Exp $
#
# Copyright (c) 2007-2014 Marc Espie <espie@openbsd.org>
#
return $self->{subst}->value($k);
}
+sub width
+{
+ my $self = shift;
+ if (!defined $self->{width}) {
+ $self->find_window_size;
+ }
+ return $self->{width};
+}
+
+sub height
+{
+ my $self = shift;
+ if (!defined $self->{height}) {
+ $self->find_window_size;
+ }
+ return $self->{height};
+}
+
+sub find_window_size
+{
+ my $self = shift;
+ require Term::ReadKey;
+ my @l = Term::ReadKey::GetTermSizeGWINSZ(\*STDOUT);
+ if (@l != 4) {
+ $self->{width} = 80;
+ $self->{height} = 24;
+ } else {
+ $self->{width} = $l[0];
+ $self->{height} = $l[1];
+ $SIG{'WINCH'} = sub {
+ $self->find_window_size;
+ $self->window_size_changed;
+ };
+ }
+}
+
+sub window_size_changed
+{
+}
+
OpenBSD::Auto::cache(signer_list,
sub {
my $self = shift;