X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FTerm%2FReadLine.pm;h=8c58694fd8a0e2a6f2599ff231126ab36bb79df6;hb=045ac3170cd33a7002e5d26e4859e94ca400926d;hp=491ce79cbe4ca9400ce9afdb3ddca403e0b41bbf;hpb=b75c8c73cd7f3c92a16e03fb046f4e2a99363bc7;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Term/ReadLine.pm b/lib/Term/ReadLine.pm index 491ce79..8c58694 100644 --- a/lib/Term/ReadLine.pm +++ b/lib/Term/ReadLine.pm @@ -6,11 +6,11 @@ no real package is found, substitutes stubs instead of basic functions. =head1 SYNOPSIS use Term::ReadLine; - $term = new Term::ReadLine 'Simple Perl calc'; - $prompt = "Enter your arithmetic expression: "; - $OUT = $term->OUT || STDOUT; + my $term = new Term::ReadLine 'Simple Perl calc'; + my $prompt = "Enter your arithmetic expression: "; + my $OUT = $term->OUT || \*STDOUT; while ( defined ($_ = $term->readline($prompt)) ) { - $res = eval($_), "\n"; + my $res = eval($_), "\n"; warn $@ if $@; print $OUT $res, "\n" unless $@; $term->addhistory($_) if /\S/; @@ -41,7 +41,7 @@ where $term is a return value of Term::ReadLine-EInit. returns the actual package that executes the commands. Among possible values are C, C, -C. +C. =item C @@ -157,6 +157,22 @@ empty, the best available package is loaded. (Note that processing of C for ornaments is in the discretion of the particular used C package). +=head1 CAVEATS + +It seems that using Term::ReadLine from Emacs minibuffer doesn't work +quite right and one will get an error message like + + Cannot open /dev/tty for read at ... + +One possible workaround for this is to explicitly open /dev/tty like this + + open (FH, "/dev/tty" ) + or eval 'sub Term::ReadLine::findConsole { ("&STDIN", "&STDERR") }'; + die $@ if $@; + close (FH); + +or you can try using the 4-argument form of Term::ReadLine->new(). + =cut use strict; @@ -225,7 +241,7 @@ sub new { #local (*FIN, *FOUT); my ($FIN, $FOUT, $ret); if (@_==2) { - my($console, $consoleOUT) = findConsole; + my($console, $consoleOUT) = $_[0]->findConsole; open(FIN, "<$console"); open(FOUT,">$consoleOUT"); @@ -295,6 +311,8 @@ if (defined &Term::ReadLine::Gnu::readline) { @ISA = qw(Term::ReadLine::Gnu Term::ReadLine::Stub); } elsif (defined &Term::ReadLine::Perl::readline) { @ISA = qw(Term::ReadLine::Perl Term::ReadLine::Stub); +} elsif (defined $which && defined &{"Term::ReadLine::$which\::readline"}) { + @ISA = "Term::ReadLine::$which"; } else { @ISA = qw(Term::ReadLine::Stub); }