1Size(3)               User Contributed Perl Documentation              Size(3)
2
3
4

NAME

6       Term::Size - Perl extension for retrieving terminal size
7

SYNOPSIS

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

DESCRIPTION

15       Term::Size is a Perl module which provides a straightforward way to
16       retrieve the terminal size.
17
18       Both functions take an optional filehandle argument, which defaults to
19       *STDIN{IO}.  They both return a list of two values, which are the
20       current width and height, respectively, of the terminal associated with
21       the specified filehandle.
22
23       "Term::Size::chars" returns the size in units of characters, whereas
24       "Term::Size::pixels" uses units of pixels.
25
26       In a scalar context, both functions return the first element of the
27       list, that is, the terminal width.
28
29       The functions may be imported.
30
31       If you need to pass a filehandle to either of the "Term::Size"
32       functions, beware that the *STDOUT{IO} syntax is only supported in Perl
33       5.004 and later.  If you have an earlier version of Perl, or are
34       interested in backwards compatibility, use *STDOUT instead.
35

EXAMPLES

37       1. Refuse to run in a too narrow window.
38
39           use Term::Size;
40
41           die "Need 80 column screen" if Term::Size::chars *STDOUT{IO} < 80;
42
43       2. Track window size changes.
44
45           use Term::Size 'chars';
46
47           my $changed = 1;
48
49           while (1) {
50                   local $SIG{'WINCH'} = sub { $changed = 1 };
51
52                   if ($changed) {
53                           ($cols, $rows) = chars;
54                           # Redraw, or whatever.
55                           $changed = 0;
56                   }
57           }
58

RETURN VALUES

60       Both functions return "undef" if there is an error.
61
62       If the terminal size information is not available, the functions will
63       normally return "(0, 0)", but this depends on your system.  On
64       character only terminals, "pixels" will normally return "(0, 0)".
65

BUGS

67       It only works on Unix systems.
68

AUTHOR

70       Tim Goodwin, <tim@uunet.pipex.com>, 1997-04-23.
71
72
73
74perl v5.12.0                      1997-05-13                           Size(3)
Impressum