Perl Diver 2.31
Main Environment Variables Perl Default Values Perl Config - Summary Perl Config - Full Installed Modules List Directory uptime Docs

Module Documentation
Details and documentation about a specific module, including version and documentation (if available). Note that while links to perldoc.com and search.cpan.org are provided, the module may be part of a larger distribution. If you reach a File Not Found page on either site, please try the parent module.

Term::Size

Name Term::Size
Version 0.209
Located at /usr/lib64/perl5/vendor_perl
File /usr/lib64/perl5/vendor_perl/Term/Size.pm
Is Core No
Search CPAN for this module Term::Size
Documentation Term::Size
Module Details Term::Size


NAME

Term::Size - Retrieve terminal size (Unix version)


SYNOPSIS

    use Term::Size;
    ($columns, $rows) = Term::Size::chars *STDOUT{IO};
    ($x, $y) = Term::Size::pixels;


DESCRIPTION

the Term::Size manpage is a Perl module which provides a straightforward way to retrieve the terminal size.

Both functions take an optional filehandle argument, which defaults to *STDIN{IO}. They both return a list of two values, which are the current width and height, respectively, of the terminal associated with the specified filehandle.

Term::Size::chars returns the size in units of characters, whereas Term::Size::pixels uses units of pixels.

In a scalar context, both functions return the first element of the list, that is, the terminal width.

The functions may be imported.

If you need to pass a filehandle to either of the the Term::Size manpage functions, beware that the *STDOUT{IO} 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 *STDOUT instead.


EXAMPLES

1. Refuse to run in a too narrow window.

    use Term::Size;
    die "Need 80 column screen" if Term::Size::chars *STDOUT{IO} < 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;
            }
    }


RETURN VALUES

If there is an error, both functions return undef in scalar context, or an empty list in list context.

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).


CAVEATS

the Term::Size manpage only works on Unix systems, as it relies on the ioctl function to retrieve the terminal size. If you need terminal size in Windows, see the Term::Size::Win32 manpage.

Before version 0.208, chars and pixels used to return false on error.


SEE ALSO

the Term::Size::Any manpage, the Term::Size::Perl manpage, the Term::Size::ReadKey manpage, the Term::Size::Win32 manpage.


AUTHOR

Tim Goodwin, <tim@uunet.pipex.com>, 1997-04-23.


MANTAINER

Adriano Ferreira, <ferreira@cpan.org>, 2006-05-19.

Perl Diver brought to you by ScriptSolutions.com © 1997- 2024