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