From: espie Date: Thu, 23 Jun 2016 16:11:23 +0000 (+0000) Subject: there's no reason for window size computation to be linked to the X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=645b31ca37bbd21d5b9ed70a837f879f4f9cdedf;p=openbsd there's no reason for window size computation to be linked to the 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... --- diff --git a/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm b/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm index e61677d033f..f6af4b538db 100644 --- a/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm +++ b/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm @@ -1,5 +1,5 @@ # 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 # @@ -99,6 +99,11 @@ sub is_interactive return shift->{interactive}->is_interactive; } +sub window_size_changed +{ + shift->{progressmeter}->compute_playfield; +} + sub confirm { my $self = shift; diff --git a/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm b/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm index 17ffdc6cc41..8cb613b1a4e 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.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 # @@ -80,6 +80,10 @@ sub for_list $self->next; } +sub compute_playfield +{ +} + # stub class when no actual progressmeter that still prints out. package OpenBSD::ProgressMeter::Stub; our @ISA = qw(OpenBSD::ProgressMeter); diff --git a/usr.sbin/pkg_add/OpenBSD/ProgressMeter/Term.pm b/usr.sbin/pkg_add/OpenBSD/ProgressMeter/Term.pm index ef72c7f401f..2d32716e210 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.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 # @@ -86,10 +86,16 @@ use POSIX; 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 @@ -98,7 +104,6 @@ sub init my $oldfh = select(STDOUT); $| = 1; select($oldfh); - $self->find_window_size; $self->{lastdisplay} = ''; $self->{continued} = 0; $self->{work} = 0; @@ -120,22 +125,10 @@ sub init } } -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; @@ -150,10 +143,6 @@ sub set_header 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; }; @@ -186,11 +175,11 @@ sub _show $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); } } diff --git a/usr.sbin/pkg_add/OpenBSD/State.pm b/usr.sbin/pkg_add/OpenBSD/State.pm index 6d93213661d..56080e9a4f5 100644 --- a/usr.sbin/pkg_add/OpenBSD/State.pm +++ b/usr.sbin/pkg_add/OpenBSD/State.pm @@ -1,5 +1,5 @@ # 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 # @@ -363,6 +363,46 @@ sub defines 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;