GetSize.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 2 Podpod n/a totaltotal 0.0% 0 / 46 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #
2 # Try as hard as we can to guess the number of rows and columns
3 # in the display.
4 #
5 # Use a "nice" approach if available, wallow if we must.
6 # Michael Edmonson 10/1/98
7 #
8  
9 package Games::Rezrov::GetSize;
10  
11 use strict;
12 use Exporter;
13  
14 @Games::Rezrov::GetSize::ISA = qw(Exporter);
15 @Games::Rezrov::GetSize::EXPORT = qw(get_size);
16  
17 $Games::Rezrov::GetSize::DEBUG = 0;
18  
19 eval 'use Term::ReadKey';
20 if (!$@) {
21 #
22 # use Term::ReadKey
23 #
24 print STDERR "term::readkey\n" if $Games::Rezrov::GetSize::DEBUG;
25  
26 eval << 'DONE'
27 sub get_size {
28 my @terminal = GetTerminalSize();
29 return @terminal ? ($terminal[0], $terminal[1]) : undef;
30 }
31 DONE
32 } elsif ($ENV{"COLUMNS"} and $ENV{"ROWS"}) {
33 #
34 # use environment variables
35 #
36 print STDERR "environment vars\n" if $Games::Rezrov::GetSize::DEBUG;
37 eval << 'DONE'
38 sub get_size {
39 return ($ENV{"COLUMNS"}, $ENV{"ROWS"});
40 }
41 DONE
42 } else {
43 foreach ("/bin/", "/usr/bin/") {
44 my $fn = $_ . "/stty";
45 $Games::Rezrov::GetSize::stty_prog = $fn, last if -x $fn;
46 }
47 if ($Games::Rezrov::GetSize::stty_prog) {
48 #
49 # use stty
50 #
51 print STDERR "stty\n" if $Games::Rezrov::GetSize::DEBUG;
52 eval << 'DONE'
53 sub get_size {
54 my ($columns, $rows);
55 my $data = `$Games::Rezrov::GetSize::stty_prog -a`;
56 foreach (["rows", \$rows],
57 ["columns", \$columns]) {
58 my ($what, $ref) = @{$_};
59 if ($data =~ /$what\s+=*\s*(\d+)/) {
60 $$ref = $1;
61 } elsif ($data =~ /(\d+)\s+$what/) {
62 $$ref = $1;
63 }
64 }
65 return ($columns, $rows);
66 }
67 DONE
68 } else {
69 #
70 # give up
71 #
72 print STDERR "giving up\n" if $Games::Rezrov::GetSize::DEBUG;
73 eval << 'DONE'
74 sub get_size {
75 return undef;
76 }
77 DONE
78 }
79 }
80  
81  
82 1;