Completion/_termsize.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 58 CC 4 SCAR 24.0
CC
4
Cov
0%
get_term_size
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 11.0
1 package Term::Completion::_termsize;
2
3 use strict;
4
5 my $get_term_size;
6
7 # try to load Term::Size
8 if( eval { require Term::Size; 1; } && !$@) {
9 $get_term_size = sub {
10 return Term::Size::chars($_[0]);
11 };
12 }
13 # we try poor man's ioctl - stolen from perlfaq8
14 else {
15 eval { require 'sys/ioctl.ph'; 1; };
16 eval { require 'sys/termios.ph'; 1; };
17 if(defined &TIOCGWINSZ) {
18 $get_term_size = sub {
19 my $winsize = '';
20 unless(ioctl($_[0], &TIOCGWINSZ, $winsize) =~ /^0/) {
21 return;
22 }
23 my ($row, $col, $xpixel, $ypixel) = unpack('S4', $winsize);
24 return($col,$row);
25 };
26 } else {
27 # we don't have a way to get the terminal size
28 $get_term_size = sub {
29 return (undef, undef);
30 }
31 }
32 }
33
34 sub get_term_size
35 {
36 my __PACKAGE__ $this = shift;
37 my ($c,$r);
38 if(defined $get_term_size) {
39 ($c,$r) = &$get_term_size($this->{out});
40 } else {
41 ($c,$r) = ($Term::Completion::DEFAULTS{columns},
42 $Term::Completion::DEFAULTS{rows});
43 }
44 return (
45 (defined $this->{columns} ? $this->{columns} : $c),
46 (defined $this->{rows} ? $this->{rows} : $r)
47 );
48 }
49
50 1;
51
52 __END__