Front page | perl.perl6.internals |
Postings from January 2002
[maybe PATCH] use Term::ReadLine where possible
Thread Next
From:
Nicholas Clark
Date:
January 21, 2002 10:07
Subject:
[maybe PATCH] use Term::ReadLine where possible
Message ID:
20020121175251.GA1726@Bagpuss.unfortu.net
I think that this is a good idea, but there may be arguments against it.
The stub Term::ReadLine has been in perl since pre 5.004, so it's quite safe
to use it. However, to actually get line editing one needs to have installed
either Term::ReadLine::Perl or Term::ReadLine::Gnu. Attached patch makes
Configure.pl use Term::ReadLine to give interactive editing if there's a real
Term::ReadLine present, else Configure.pl continues to use the old way.
I think that this is easier to use than cut and paste or the rem:{} add:{}
syntax that &prompt appears to offer.
Tested with Term::ReadLine::Gnu and Term::ReadLine::Perl
(and I don't know why Term::ReadLine::Perl later decided that it could do
multi-line editing when it initially was doing sideways scrolling)
Nicholas Clark
--
ENOCHOCOLATE http://www.ccl4.org/~nick/CV.html
--- Configure.pl.orig Sun Jan 20 22:57:28 2002
+++ Configure.pl Mon Jan 21 17:25:28 2002
@@ -13,10 +13,9 @@
use Getopt::Long;
use ExtUtils::Manifest qw(manicheck);
use File::Copy;
-
+use Term::ReadLine; # The stub is present from earlier than 5.004
use Parrot::BuildUtil;
-
#
# Read the array and scalar forms of the version.
# from the VERSION file.
@@ -287,15 +286,17 @@
# Ask questions
#
-prompt("What C compiler do you want to use?", 'cc');
-prompt("How about your linker?", 'ld');
-prompt("What flags would you like passed to your C compiler?", 'ccflags');
-prompt("What flags would you like passed to your linker?", 'ldflags');
-prompt("Which libraries would you like your C compiler to include?", 'libs');
-prompt("How big would you like integers to be?", 'iv');
-prompt("And your floats?", 'nv');
-prompt("What is your native opcode type?", 'opcode_t');
+my $term = initialise_term();
+prompt($term, "What C compiler do you want to use?", 'cc');
+prompt($term, "How about your linker?", 'ld');
+prompt($term, "What flags would you like passed to your C compiler?",
+ 'ccflags');
+prompt($term, "Which libraries would you like your C compiler to include?",
+ 'libs');
+prompt($term, "How big would you like integers to be?", 'iv');
+prompt($term, "And your floats?", 'nv');
+prompt($term, "What is your native opcode type?", 'opcode_t');
{
my(@ops)=glob("*.ops");
@@ -326,7 +327,7 @@
Which opcode files would you like?
END
- prompt($msg, 'ops');
+ prompt($term, $msg, 'ops');
}
@@ -428,7 +429,7 @@
next unless $opt; # Ignore blank lines
$c{cc_warn} .= " $opt";
}
- prompt("What gcc warning flags do you want to use?", 'cc_warn');
+ prompt($term, "What gcc warning flags do you want to use?", 'cc_warn');
}
#
@@ -708,21 +709,29 @@
sub prompt {
return if $opt_defaults;
- my($message, $field)=(@_);
+ my($term, $message, $field)=(@_);
my($input);
- print "$message [$c{$field}] ";
- chomp($input=<STDIN>);
+ if ($term) {
+ # Term::ReadLine::Gnu does a multiline edit just like bash.
+ # Term::ReadLine::Perl does a sideways scrolling single line like ksh.
+ print "$message [$c{$field}]\n";
+ $input = $term->readline("", $c{$field});
+ $term->addhistory($input) if /\S/ and !$term->Features->{autohistory};
+ } else {
+ print "$message [$c{$field}] ";
+ chomp($input=<STDIN>);
- if($input =~ s/^\+//) {
- $input="$c{$field} $input";
- }
- else {
- if($input =~ s/:rem\{(.*?)\}//) {
- $c{$field} =~ s/$_//g for split / /, $1;
+ if($input =~ s/^\+//) {
+ $input="$c{$field} $input";
}
+ else {
+ if($input =~ s/:rem\{(.*?)\}//) {
+ $c{$field} =~ s/$_//g for split / /, $1;
+ }
- if($input =~ s/:add\{(.*?)\}//) {
- $input="$c{$field} $1 $input";
+ if($input =~ s/:add\{(.*?)\}//) {
+ $input="$c{$field} $1 $input";
+ }
}
}
@@ -816,8 +825,32 @@
exit 1;
}
- else {
- print <<"END";
+}
+
+#
+# initialise_term()
+#
+
+sub initialise_term {
+ my $term = Term::ReadLine->new ('Parrot configuration');
+ undef $term if $term && $term->ReadLine eq "Term::ReadLine::Stub";
+
+ if ($term) {
+ my $type = $term->ReadLine;
+ print <<"END";
+Okay, we found everything. Next you'll need to answer
+a few questions about your system. You have
+${ type} installed, so I'll use that to let
+you edit your answers interactively. I'll put the
+default in square brackets, and also prime the input
+line with the default. Just hit enter straight away to
+accept the default, or edit it to suit. Like Perl 5's
+Configure you can also chose the default by entering a
+zero length line.
+
+END
+ } else {
+ print <<"END";
Okay, we found everything. Next you'll need to answer
a few questions about your system. Defaults are in square
brackets, and you can hit enter to accept them. If you
@@ -827,8 +860,8 @@
END
}
+ return $term;
}
-
#
# compiletestc()
Thread Next
-
[maybe PATCH] use Term::ReadLine where possible
by Nicholas Clark