If we use @{[]} (a.k.a. baby-cart) interpolation, we got warnings
[p5sagit/p5-mst-13.2.git] / lib / Term / ReadLine.pm
index 48eb991..c1d1762 100644 (file)
@@ -209,13 +209,15 @@ sub addhistory {}
 
 sub findConsole {
     my $console;
+    my $consoleOUT;
 
     if ($^O eq 'MacOS') {
         $console = "Dev:Console";
     } elsif (-e "/dev/tty") {
        $console = "/dev/tty";
     } elsif (-e "con" or $^O eq 'MSWin32') {
-       $console = "con";
+       $console = 'CONIN$';
+       $consoleOUT = 'CONOUT$';
     } else {
        $console = "sys\$command";
     }
@@ -231,10 +233,10 @@ sub findConsole {
       }
     }
 
-    my $consoleOUT = $console;
+    $consoleOUT = $console unless defined $consoleOUT;
     $console = "&STDIN" unless defined $console;
     if (!defined $consoleOUT) {
-      $consoleOUT = defined fileno(STDERR) ? "&STDERR" : "&STDOUT";
+      $consoleOUT = defined fileno(STDERR) && $^O ne 'MSWin32' ? "&STDERR" : "&STDOUT";
     }
     ($console,$consoleOUT);
 }
@@ -247,8 +249,13 @@ sub new {
   if (@_==2) {
     my($console, $consoleOUT) = $_[0]->findConsole;
 
-    open(FIN, "<$console"); 
-    open(FOUT,">$consoleOUT");
+
+    # the Windows CONIN$ needs GENERIC_WRITE mode to allow
+    # a SetConsoleMode() if we end up using Term::ReadKey
+    open FIN, (  $^O eq 'MSWin32' && $console eq 'CONIN$' ) ? "+<$console" :
+                                                              "<$console";
+    open FOUT,">$consoleOUT";
+
     #OUT->autoflush(1);                # Conflicts with debugger?
     my $sel = select(FOUT);
     $| = 1;                            # for DB::OUT
@@ -287,9 +294,16 @@ sub Attribs { {} }
 my %features = (tkRunning => 1, ornaments => 1, 'newTTY' => 1);
 sub Features { \%features }
 
+sub get_line {
+  my $self = shift;
+  my $in = $self->IN;
+  local ($/) = "\n";
+  return scalar <$in>;
+}
+
 package Term::ReadLine;                # So late to allow the above code be defined?
 
-our $VERSION = '1.02';
+our $VERSION = '1.03';
 
 my ($which) = exists $ENV{PERL_RL} ? split /\s+/, $ENV{PERL_RL} : undef;
 if ($which) {