1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#!/usr/bin/perl -w
=head1 NAME
Debconf::FrontEnd::ScreenSize - screen size tracker
=cut
package Debconf::FrontEnd::ScreenSize;
use strict;
use Debconf::Gettext;
use base qw(Debconf::FrontEnd);
=head1 DESCRIPTION
This FrontEnd is not useful standalone. It serves as a base for FrontEnds
that have a user interface that runs on a resizable tty. The screenheight
field is always set to the current height of the tty, while the screenwidth
field is always set to its width.
=over 4
=item screenheight
The height of the screen.
=item screenwidth
The width of the screen.
=item screenheight_guessed
Set to a true value if the screenheight was guessed to be 25, and may be
anything, if the screen has a height at all.
=back
=head1 METHODS
=over 4
=item init
Sets up SIGWINCH handler and gets current screen size.
=cut
sub init {
my $this=shift;
$this->SUPER::init(@_);
$this->resize; # Get current screen size.
$SIG{WINCH}=sub {
# There is a short period during global destruction where
# $this may have been destroyed but the handler still
# operative.
if (defined $this) {
$this->resize;
}
};
}
=bitem resize
This method is called whenever the tty is resized, and probes to determine the
new screen size.
=cut
sub resize {
my $this=shift;
if (exists $ENV{LINES}) {
$this->screenheight($ENV{'LINES'});
$this->screenheight_guessed(0);
}
else {
# Gotta be a better way..
my ($rows)=`stty -a 2>/dev/null` =~ m/rows (\d+)/s;
if ($rows) {
$this->screenheight($rows);
$this->screenheight_guessed(0);
}
else {
$this->screenheight(25);
$this->screenheight_guessed(1);
}
}
if (exists $ENV{COLUMNS}) {
$this->screenwidth($ENV{'COLUMNS'});
}
else {
my ($cols)=`stty -a 2>/dev/null` =~ m/columns (\d+)/s;
$this->screenwidth($cols || 80);
}
}
=back
=head1 AUTHOR
Joey Hess <joeyh@debian.org>
=cut
1
|