line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Term::Size::Perl; |
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
75884
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
977
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(chars pixels); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.029; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Term::Size::Perl - Perl extension for retrieving terminal size (Perl version) |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Term::Size::Perl; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
($columns, $rows) = Term::Size::Perl::chars *STDOUT{IO}; |
22
|
|
|
|
|
|
|
($x, $y) = Term::Size::Perl::pixels; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Yet another implementation of C. Now |
27
|
|
|
|
|
|
|
in pure Perl, with the exception of a C probe run |
28
|
|
|
|
|
|
|
on build time. |
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 SEE ALSO |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
It all began with L by Tim Goodwin. You may want to |
61
|
|
|
|
|
|
|
have a look at: |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Term::Size |
64
|
|
|
|
|
|
|
Term::Size::Unix |
65
|
|
|
|
|
|
|
Term::Size::Win32 |
66
|
|
|
|
|
|
|
Term::Size::ReadKey |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
It would be helpful if you send me the F generated by |
69
|
|
|
|
|
|
|
the probe at build time. |
70
|
|
|
|
|
|
|
Please reports bugs via CPAN RT, |
71
|
|
|
|
|
|
|
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Term-Size-Perl |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 BUGS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
I am having some hard time to make tests run correctly |
76
|
|
|
|
|
|
|
under the C script. Some Unix systems do not seem to provide a |
77
|
|
|
|
|
|
|
working tty inside automatic installers. I think it needs |
78
|
|
|
|
|
|
|
some skip tests, but I am yet not sure what should be the |
79
|
|
|
|
|
|
|
portable tests for this. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Update: |
82
|
|
|
|
|
|
|
This distribution uses new tests to skip if filehandle |
83
|
|
|
|
|
|
|
is not a tty. It was noticed that C and |
84
|
|
|
|
|
|
|
C, for instance, provide a non-tty STDOUT |
85
|
|
|
|
|
|
|
to the test script and automatic installers |
86
|
|
|
|
|
|
|
could provide a non-tty STDIN. So the former tests |
87
|
|
|
|
|
|
|
were basically wrong. I am improving my understanding |
88
|
|
|
|
|
|
|
of the involved issues and I hope to soon fix the |
89
|
|
|
|
|
|
|
tests for all of Term::Size modules. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 AUTHOR |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
A. R. Ferreira, Eferreira@cpan.orgE |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Copyright (C) 2006-2007 by A. R. Ferreira |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
100
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
require Term::Size::Perl::Params; |
105
|
|
|
|
|
|
|
my %params = Term::Size::Perl::Params::params(); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# ( row, col, x, y ) |
108
|
|
|
|
|
|
|
sub _winsize { |
109
|
0
|
|
0
|
0
|
|
|
my $h = shift || *STDIN; |
110
|
0
|
0
|
|
|
|
|
return unless -t $h; |
111
|
0
|
|
|
|
|
|
my $sz = "\0" x $params{winsize}{sizeof}; |
112
|
0
|
0
|
|
|
|
|
ioctl($h, $params{TIOCGWINSZ}{value}, $sz) |
113
|
|
|
|
|
|
|
or return; |
114
|
0
|
|
|
|
|
|
return unpack $params{winsize}{mask}, $sz; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub chars { |
118
|
0
|
|
|
0
|
1
|
|
my @sz = _winsize(shift); |
119
|
0
|
0
|
|
|
|
|
return unless @sz; |
120
|
0
|
0
|
|
|
|
|
return @sz[1, 0] if wantarray; |
121
|
0
|
|
|
|
|
|
return $sz[1]; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub pixels { |
125
|
0
|
|
|
0
|
1
|
|
my @sz = _winsize(shift); |
126
|
0
|
0
|
|
|
|
|
return unless @sz; |
127
|
0
|
0
|
|
|
|
|
return @sz[2, 3] if wantarray; |
128
|
0
|
|
|
|
|
|
return $sz[2]; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |