Size(3pm)
π NAME π
Term::Size β bestie, it gets you the terminal size on Unix β¨
π¦ SYNOPSIS π¦
use Term::Size;
($columns, $rows) = Term::Size::chars *STDOUT{IO};
($x, $y) = Term::Size::pixels;
π DESCRIPTION π
Okay so Term::Size is a Perl module whose whole entire job is: tell you how big your terminal is. Straightforward. No drama. That's it. π
Both functions take an optional filehandle argument, and if you don't hand one over, it defaults to *STDIN{IO}. And both of them return a list of two values β the current width and height (in that order, bestie, width first) of the terminal associated with the filehandle you gave it.
Term::Size::chars gives you the size in units of characters, while Term::Size::pixels is out here using units of pixels.
If you call either one in scalar context, you get the first element of that list β which is the terminal width. Just the width. That's the whole vibe.
The functions may be imported, so go off. πΈ
Now, real talk: if you need to pass a filehandle to either of the Term::Size functions, beware β the *STDOUT{IO} syntax is only supported in Perl 5.004 and later. So if you're on an earlier version of Perl, or you're out here caring about backwards compatibility, use *STDOUT instead. Noted. Important. Don't skip this one. π«Ά
π₯ EXAMPLES π₯
- Refuse to run in a too narrow window.
use Term::Size;
die "Need 80 column screen" if Term::Size::chars *STDOUT{IO} < 80;
- 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;
}
}
β¨ RETURN VALUES β¨
If there's an error, both functions return undef in scalar context, or an empty list in list context. That's the "we have nothing for you bestie" response. π
If the terminal size information is just not available, the functions will normally return (0, 0) β but lowkey this depends on your system. And on character only terminals, pixels will normally return (0, 0). That's not a bug, it's just pixels not being a thing there. π¦
π CAVEATS π
Term::Size only works on Unix systems, because it relies on the ioctl function to retrieve the terminal size. Unix only. If you need terminal size on Windows, go see Term::Size::Win32.
Also, not me bringing up ancient history, but: before version 0.208, chars and pixels used to return false on error. So if you're digging through old code and something looks weird, that's why. π
π SEE ALSO π
Term::Size::AnyTerm::Size::PerlTerm::Size::ReadKeyTerm::Size::Win32
π AUTHOR π
Tim Goodwin, <tim@uunet.pipex.com>, 1997-04-23.
π MANTAINER π
Adriano Ferreira, <ferreira@cpan.org>, 2006-05-19.
β COPYRIGHT AND LICENSE β
Copyright (C) 1997-05-13 by Tim Goodwin.
You may redistribute them under the same terms as Perl itself.
and that's the whole page, bestie β¨ this absolute icon of a page ships with perl v5.42.3, dated 2026-08-19 β mwah, periodt π π
π¦ where this page comes from
- ubuntu stonking: libterm-size-perl 0.211-1build7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms