GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Size(3) User Contributed Perl Documentation Size(3)

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

    use Term::Size;

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

  THIS IS AN UNOFFICIAL PATCH AGAINST Term-Size 0.2 DISTRIBUTION 
  FOUND ON CPAN (http://search.cpan.org/~timpx/Term-Size-0.2/).
  IT IS UNOFFICIAL IN THE SENSE THAT THE AUTHOR Tim Goodwin 
  HASN'T APPROVED IT (YET, I HOPE). BECAUSE OF THIS, THIS 
  DISTRIBUTION IS NOT INDEXED AND AVAILABLE VIA cpan OR cpanp 
  SHELLS UNLESS YOU EXPLICITLY SAY 
  "install FERREIRA/Term-Size-0.203.tar.gz". 
  
  THIS IS UNDELICATE? I THINK IT IS IN A CERTAIN SENSE. BUT IT 
  IS A WAY TO UNFREEZE THE CURRENT DISTRIBUTION STATUS. IF TIM 
  DISAPPROVES, I WILL REMOVE THIS DISTRIBUTION RIGHT AWAY. 
  IF HE APPROVES, I WILL REMOVE THIS DISTRIBUTION RIGHT AWAY 
  AND WORK OUT (AFTER BEEN GIVEN MAINTAINERSHIP STATUS) 
  A DISTRIBUTION WITHOUT THIS NOTE AND WHICH INDEXES CORRECTLY.

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 *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 "Term::Size" 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.

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;
            }
    }

Both functions return "undef" if there is an error.

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

It only works on Unix systems.

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

Candidate for maintainership: Adriano Ferreira, <ferreira@cpan.org>, 2006-05-19.

2008-08-16 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.