File Coverage

blib/lib/Term/Size/ReadKey.pm
Criterion Covered Total %
statement 6 14 42.8
branch 0 4 0.0
condition 0 3 0.0
subroutine 2 5 40.0
pod 2 2 100.0
total 10 28 35.7


line stmt bran cond sub pod time code
1            
2             package Term::Size::ReadKey;
3            
4 2     2   81591 use strict;
  2         5  
  2         114  
5            
6             require Exporter;
7            
8 2     2   11 use vars qw( @ISA @EXPORT_OK $VERSION );
  2         4  
  2         739  
9             @ISA = qw( Exporter );
10             @EXPORT_OK = qw( chars pixels );
11            
12             $VERSION = '0.03';
13            
14             =head1 NAME
15            
16             Term::Size::ReadKey - Retrieve terminal size (via Term::ReadKey)
17            
18             =head1 SYNOPSIS
19            
20             use Term::Size::ReadKey;
21            
22             ($columns, $rows) = Term::Size::ReadKey::chars *STDOUT{IO};
23             ($x, $y) = Term::Size::ReadKey::pixels;
24            
25             =head1 DESCRIPTION
26            
27             Yet another implementation of C. Now using
28             C to do the hard work.
29            
30             =head2 FUNCTIONS
31            
32             =over 4
33            
34             =item B
35            
36             ($columns, $rows) = chars($h);
37             $columns = chars($h);
38            
39             C returns the terminal size in units of characters
40             corresponding to the given filehandle C<$h>.
41             If the argument is ommitted, C<*STDIN{IO}> is used.
42             In scalar context, it returns the terminal width.
43            
44             =item B
45            
46             ($x, $y) = pixels($h);
47             $x = pixels($h);
48            
49             C returns the terminal size in units of pixels
50             corresponding to the given filehandle C<$h>.
51             If the argument is ommitted, C<*STDIN{IO}> is used.
52             In scalar context, it returns the terminal width.
53            
54             Many systems with character-only terminals will return C<(0, 0)>.
55            
56             =back
57            
58             =head1 BUGS
59            
60             The basic test may fail harshly when running under the
61             test harness. This happens with Term::ReadKey alone as
62             well. Term::ReadKey gets away with murder by setting
63             COLUMNS and LINES environment variables (which are used
64             as a fallback). This release also applies the same cheat.
65             I gotta find a more decent fix to these issues.
66            
67             =head1 SEE ALSO
68            
69             It all began with L by Tim Goodwin. You may want to
70             have a look at:
71            
72             Term::Size
73             Term::Size::Unix
74             Term::Size::Win32
75             Term::Size::Perl
76            
77             You may as well be interested in what more C does.
78            
79             Term::ReadKey
80            
81             Please reports bugs via CPAN RT,
82             http://rt.cpan.org/NoAuth/Bugs.html?Dist=Term-Size-ReadKey
83            
84             =head1 AUTHOR
85            
86             A. R. Ferreira, Eferreira@cpan.orgE
87            
88             =head1 COPYRIGHT AND LICENSE
89            
90             Copyright (C) 2006-2008 by A. R. Ferreira
91            
92             This library is free software; you can redistribute it and/or modify
93             it under the same terms as Perl itself.
94            
95             =cut
96            
97             require Term::ReadKey;
98            
99            
100             # ( row, col, x, y )
101             sub _winsize {
102 0   0 0     my $h = shift || *STDIN;
103 0           return Term::ReadKey::GetTerminalSize($h);
104             }
105            
106             sub chars {
107 0     0 1   my @sz = _winsize(shift);
108 0 0         return @sz[0, 1] if wantarray;
109 0           return $sz[0];
110             }
111            
112             sub pixels {
113 0     0 1   my @sz = _winsize(shift);
114 0 0         return @sz[2, 3] if wantarray;
115 0           return $sz[2];
116             }
117            
118             1;