.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Size 3pm" .TH Size 3pm 2024-03-07 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Term::Size \- Retrieve terminal size on Unix .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Term::Size; \& \& ($columns, $rows) = Term::Size::chars *STDOUT{IO}; \& ($x, $y) = Term::Size::pixels; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Term::Size is a Perl module which provides a straightforward way to retrieve the terminal size. .PP Both functions take an optional filehandle argument, which defaults to \&\f(CW*STDIN{IO}\fR. They both return a list of two values, which are the current width and height, respectively, of the terminal associated with the specified filehandle. .PP \&\f(CW\*(C`Term::Size::chars\*(C'\fR returns the size in units of characters, whereas \&\f(CW\*(C`Term::Size::pixels\*(C'\fR uses units of pixels. .PP In a scalar context, both functions return the first element of the list, that is, the terminal width. .PP The functions may be imported. .PP If you need to pass a filehandle to either of the Term::Size functions, beware that the \f(CW*STDOUT{IO}\fR syntax is only supported in Perl 5.004 and later. If you have an earlier version of Perl, or are interested in backwards compatibility, use \f(CW*STDOUT\fR instead. .SH EXAMPLES .IX Header "EXAMPLES" 1. Refuse to run in a too narrow window. .PP .Vb 1 \& use Term::Size; \& \& die "Need 80 column screen" if Term::Size::chars *STDOUT{IO} < 80; .Ve .PP 2. Track window size changes. .PP .Vb 1 \& use Term::Size \*(Aqchars\*(Aq; \& \& my $changed = 1; \& \& while (1) { \& local $SIG{\*(AqWINCH\*(Aq} = sub { $changed = 1 }; \& \& if ($changed) { \& ($cols, $rows) = chars; \& # Redraw, or whatever. \& $changed = 0; \& } \& } .Ve .SH "RETURN VALUES" .IX Header "RETURN VALUES" If there is an error, both functions return \f(CW\*(C`undef\*(C'\fR in scalar context, or an empty list in list context. .PP If the terminal size information is not available, the functions will normally return \f(CW\*(C`(0, 0)\*(C'\fR, but this depends on your system. On character only terminals, \f(CW\*(C`pixels\*(C'\fR will normally return \f(CW\*(C`(0, 0)\*(C'\fR. .SH CAVEATS .IX Header "CAVEATS" Term::Size only works on Unix systems, as it relies on the \&\f(CW\*(C`ioctl\*(C'\fR function to retrieve the terminal size. If you need terminal size in Windows, see Term::Size::Win32. .PP Before version 0.208, \f(CW\*(C`chars\*(C'\fR and \f(CW\*(C`pixels\*(C'\fR used to return false on error. .SH "SEE ALSO" .IX Header "SEE ALSO" Term::Size::Any, Term::Size::Perl, Term::Size::ReadKey, Term::Size::Win32. .SH AUTHOR .IX Header "AUTHOR" Tim Goodwin, , 1997\-04\-23. .SH MANTAINER .IX Header "MANTAINER" Adriano Ferreira, , 2006\-05\-19. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 1997\-05\-13 by Tim Goodwin. .PP You may redistribute them under the same terms as Perl itself.