line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Term::Size::Perl; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
138467
|
use strict; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
610
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(chars pixels); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.030_0'; |
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 omitted, 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 omitted, 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
|
|
|
|
|
|
|
L |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
L |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
L |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
L |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Please reports bugs via GitHub, |
72
|
|
|
|
|
|
|
https://github.com/aferreira/cpan-Term-Size-Perl/issues |
73
|
|
|
|
|
|
|
When reporting bugs, it may be helpful to attach the F generated by |
74
|
|
|
|
|
|
|
the probe at build time. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 AUTHOR |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Adirano Ferreira, Eferreira@cpan.orgE |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Copyright (C) 2006-2007, 2017-2018 by Adriano Ferreira |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
85
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
require Term::Size::Perl::Params; |
90
|
|
|
|
|
|
|
my %params = Term::Size::Perl::Params::params(); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# ( row, col, x, y ) |
93
|
|
|
|
|
|
|
sub _winsize { |
94
|
0
|
|
0
|
0
|
|
|
my $h = shift || *STDIN; |
95
|
0
|
0
|
|
|
|
|
return unless -t $h; |
96
|
0
|
|
|
|
|
|
my $sz = "\0" x $params{winsize}{sizeof}; |
97
|
0
|
0
|
|
|
|
|
ioctl($h, $params{TIOCGWINSZ}{value}, $sz) |
98
|
|
|
|
|
|
|
or return; |
99
|
0
|
|
|
|
|
|
return unpack $params{winsize}{mask}, $sz; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub chars { |
103
|
0
|
|
|
0
|
1
|
|
my @sz = _winsize(shift); |
104
|
0
|
0
|
|
|
|
|
return unless @sz; |
105
|
0
|
0
|
|
|
|
|
return @sz[1, 0] if wantarray; |
106
|
0
|
|
|
|
|
|
return $sz[1]; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub pixels { |
110
|
0
|
|
|
0
|
1
|
|
my @sz = _winsize(shift); |
111
|
0
|
0
|
|
|
|
|
return unless @sz; |
112
|
0
|
0
|
|
|
|
|
return @sz[2, 3] if wantarray; |
113
|
0
|
|
|
|
|
|
return $sz[2]; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |