Term::Size - Perl extension for retrieving terminal size
use Term::Size; ($columns, $rows) = Term::Size::chars; ($x, $y) = Term::Size::pixels
Term::Size is a Perl module which provides a straightforward way to retrieve the terminal size.
The function Term::Size::chars returns a list of two values, which are the current width and height respectively of the terminal, in characters.
Term::Size::chars
The function Term::Size::pixels returns a list of two values, which are the current width and height respectively of the terminal, in pixels.
Term::Size::pixels
In a scalar context, both functions return the first element of the list, that is, the terminal width.
The functions may be imported.
1. Refuse to run in a too narrow window.
use Term::Size; die "Need 80 column screen" if Term::Size::chars < 80;
2. Track window size changes.
use Term::Size 'chars'; my $changed = 1; while (1) { local $SIG{'WINCH'} = sub { $changed = 1 }; if ($changed) { ($cols, $rows) = chars; # Redraw, or whatever. $changed = 0; } }
Both functions return undef if there is an error.
undef
If the terminal size information is not available, the functions will normally return (0, 0), but this depends on your system. On character only terminals, pixels will normally return (0, 0).
(0, 0)
pixels
It only works on Unix systems.
Tim Goodwin, <tim@uunet.pipex.com>, 1997-04-23.
To install Term::Size, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Term::Size
CPAN shell
perl -MCPAN -e shell install Term::Size
For more information on module installation, please visit the detailed CPAN module installation guide.