Plack-App-MCCS
view release on metacpan or search on metacpan
local/lib/perl5/x86_64-linux-thread-multi/Term/ReadKey.pm view on Meta::CPAN
if ( ref( \$file ) eq 'GLOB' ) { return $file; } # Glob is good
# print "Caller = ",(caller(1))[0],"\n";
return \*{ ( ( caller(1) )[0] ) . "::$file" };
}
sub GetTerminalSize
{
my $file = normalizehandle( ( @_ > 0 ? $_[0] : \*STDOUT ) );
my (@results, @fail);
if ( &termsizeoptions() & 1 ) # VIO
{
@results = GetTermSizeVIO($file);
push( @fail, "VIOGetMode call" );
}
elsif ( &termsizeoptions() & 2 ) # GWINSZ
{
@results = GetTermSizeGWINSZ($file);
push( @fail, "TIOCGWINSZ ioctl" );
}
elsif ( &termsizeoptions() & 4 ) # GSIZE
{
@results = GetTermSizeGSIZE($file);
push( @fail, "TIOCGSIZE ioctl" );
}
elsif ( &termsizeoptions() & 8 ) # WIN32
{
@results = GetTermSizeWin32($file);
push( @fail, "Win32 GetConsoleScreenBufferInfo call" );
}
else
{
@results = ();
}
if ( @results < 4 and $UseEnv )
{
my ($C) = defined( $ENV{COLUMNS} ) ? $ENV{COLUMNS} : 0;
my ($L) = defined( $ENV{LINES} ) ? $ENV{LINES} : 0;
if ( ( $C >= 2 ) and ( $L >= 2 ) )
{
@results = ( $C + 0, $L + 0, 0, 0 );
}
push( @fail, "COLUMNS and LINES environment variables" );
}
if ( @results < 4 && $^O ne 'MSWin32')
{
my ($prog) = "resize";
# Workaround for Solaris path silliness
if ( -f "/usr/openwin/bin/resize" ) {
$prog = "/usr/openwin/bin/resize";
}
my ($resize) = scalar(`$prog 2>/dev/null`);
if (defined $resize
and ( $resize =~ /COLUMNS\s*=\s*(\d+)/
or $resize =~ /setenv\s+COLUMNS\s+'?(\d+)/ )
)
{
$results[0] = $1;
if ( $resize =~ /LINES\s*=\s*(\d+)/
or $resize =~ /setenv\s+LINES\s+'?(\d+)/ )
{
$results[1] = $1;
@results[ 2, 3 ] = ( 0, 0 );
}
else
{
@results = ();
}
}
else
{
@results = ();
}
push( @fail, "resize program" );
}
if ( @results < 4 && $^O ne 'MSWin32' )
{
my ($prog) = "stty size";
my ($stty) = scalar(`$prog 2>/dev/null`);
if (defined $stty
and ( $stty =~ /(\d+) (\d+)/ )
)
{
$results[0] = $2;
$results[1] = $1;
@results[ 2, 3 ] = ( 0, 0 );
}
else
{
@results = ();
}
push( @fail, "stty program" );
}
if ( @results != 4 )
{
carp("Unable to get Terminal Size."
. join( "", map( " The $_ didn't work.", @fail ) ));
return undef;
}
@results;
}
# blockoptions:
#nodelay
#select
sub ReadKey {
my $File = normalizehandle((@_>1?$_[1]:\*STDIN));
if (defined $_[0] && $_[0] > 0) {
if ($_[0]) { return undef if &selectfile($File,$_[0]) == 0 }
}
if (defined $_[0] && $_[0] < 0) { &setnodelay($File,1); }
my $value = getc $File;
if (defined $_[0] && $_[0] < 0) { &setnodelay($File,0); }
$value;
}
sub ReadLine {
( run in 0.512 second using v1.01-cache-2.11-cpan-437f7b0c052 )