| 1 | package Term::Size; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use vars qw(@EXPORT_OK @ISA $VERSION); | ||
| 5 | |||
| 6 | use DynaLoader (); | ||
| 7 | use Exporter (); | ||
| 8 | |||
| 9 | @ISA = qw(Exporter DynaLoader); | ||
| 10 | @EXPORT_OK = qw(chars pixels); | ||
| 11 | |||
| 12 | $VERSION = '0.209'; | ||
| 13 | |||
| 14 | bootstrap Term::Size $VERSION; | ||
| 15 | |||
| 16 | 1; | ||
| 17 | |||
| 18 | =encoding utf8 | ||
| 19 | |||
| 20 | =head1 NAME | ||
| 21 | |||
| 22 | Term::Size - Retrieve terminal size (Unix version) | ||
| 23 | |||
| 24 | =head1 SYNOPSIS | ||
| 25 | |||
| 26 | use Term::Size; | ||
| 27 | |||
| 28 | ($columns, $rows) = Term::Size::chars *STDOUT{IO}; | ||
| 29 | ($x, $y) = Term::Size::pixels; | ||
| 30 | |||
| 31 | =head1 DESCRIPTION | ||
| 32 | |||
| 33 | L<Term::Size> is a Perl module which provides a straightforward way to | ||
| 34 | retrieve the terminal size. | ||
| 35 | |||
| 36 | Both functions take an optional filehandle argument, which defaults to | ||
| 37 | C<*STDIN{IO}>. They both return a list of two values, which are the | ||
| 38 | current width and height, respectively, of the terminal associated with | ||
| 39 | the specified filehandle. | ||
| 40 | |||
| 41 | C<Term::Size::chars> returns the size in units of characters, whereas | ||
| 42 | C<Term::Size::pixels> uses units of pixels. | ||
| 43 | |||
| 44 | In a scalar context, both functions return the first element of the | ||
| 45 | list, that is, the terminal width. | ||
| 46 | |||
| 47 | The functions may be imported. | ||
| 48 | |||
| 49 | If you need to pass a filehandle to either of the L<Term::Size> | ||
| 50 | functions, beware that the C<*STDOUT{IO}> syntax is only supported in | ||
| 51 | Perl 5.004 and later. If you have an earlier version of Perl, or are | ||
| 52 | interested in backwards compatibility, use C<*STDOUT> instead. | ||
| 53 | |||
| 54 | =head1 EXAMPLES | ||
| 55 | |||
| 56 | 1. Refuse to run in a too narrow window. | ||
| 57 | |||
| 58 | use Term::Size; | ||
| 59 | |||
| 60 | die "Need 80 column screen" if Term::Size::chars *STDOUT{IO} < 80; | ||
| 61 | |||
| 62 | 2. Track window size changes. | ||
| 63 | |||
| 64 | use Term::Size 'chars'; | ||
| 65 | |||
| 66 | my $changed = 1; | ||
| 67 | |||
| 68 | while (1) { | ||
| 69 | local $SIG{'WINCH'} = sub { $changed = 1 }; | ||
| 70 | |||
| 71 | if ($changed) { | ||
| 72 | ($cols, $rows) = chars; | ||
| 73 | # Redraw, or whatever. | ||
| 74 | $changed = 0; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | =head1 RETURN VALUES | ||
| 79 | |||
| 80 | If there is an error, both functions return C<undef> | ||
| 81 | in scalar context, or an empty list in list context. | ||
| 82 | |||
| 83 | If the terminal size information is not available, the functions | ||
| 84 | will normally return C<(0, 0)>, but this depends on your system. On | ||
| 85 | character only terminals, C<pixels> will normally return C<(0, 0)>. | ||
| 86 | |||
| 87 | =head1 CAVEATS | ||
| 88 | |||
| 89 | L<Term::Size> only works on Unix systems, as it relies on the | ||
| 90 | C<ioctl> function to retrieve the terminal size. If you need | ||
| 91 | terminal size in Windows, see L<Term::Size::Win32>. | ||
| 92 | |||
| 93 | Before version 0.208, C<chars> and C<pixels> used to return false on error. | ||
| 94 | |||
| 95 | =head1 SEE ALSO | ||
| 96 | |||
| 97 | L<Term::Size::Any>, L<Term::Size::Perl>, L<Term::Size::ReadKey>, L<Term::Size::Win32>. | ||
| 98 | |||
| 99 | =head1 AUTHOR | ||
| 100 | |||
| 101 | Tim Goodwin, <tim@uunet.pipex.com>, 1997-04-23. | ||
| 102 | |||
| 103 | =head1 MANTAINER | ||
| 104 | |||
| 105 | Adriano Ferreira, <ferreira@cpan.org>, 2006-05-19. | ||
| 106 | |||
| 107 | =cut |