man Term::Size () - Perl extension for retrieving terminal size

NAME

Term::Size - Perl extension for retrieving terminal size

SYNOPSIS

    use Term::Size;

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

DESCRIPTION

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

Both functions take an optional filehandle argument, which defaults to CW*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.

CWTerm::Size::chars returns the size in units of characters, whereas CWTerm::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 CWTerm::Size functions, beware that the CW*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 CW*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

Both functions return CWundef if there is an error.

If the terminal size information is not available, the functions will normally return CW(0, 0), but this depends on your system. On character only terminals, CWpixels will normally return CW(0, 0).

BUGS

It only works on Unix systems.

AUTHOR

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