Update of /cvsroot/fink/fink/perlmod/Fink
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22750
Modified Files:
Tag: branch_0_23
CLI.pm ChangeLog Configure.pm
Log Message:
backport prompt_selection to branch_0_23 in preparation for revising the
mirror selection dialog
Index: CLI.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/CLI.pm,v
retrieving revision 1.10.2.1
retrieving revision 1.10.2.2
diff -u -d -r1.10.2.1 -r1.10.2.2
--- CLI.pm 2 Jan 2005 16:14:52 -0000 1.10.2.1
+++ CLI.pm 15 Apr 2005 16:23:05 -0000 1.10.2.2
@@ -40,6 +40,7 @@
# as well as any optionally exported functions
@EXPORT_OK = qw(&print_breaking &print_breaking_stderr
&prompt &prompt_boolean
&prompt_selection_new
+ &prompt_selection
&print_optionlist
&get_term_width);
}
@@ -342,6 +343,106 @@
return $choices[2*$answer-1];
}
+=item prompt_selection
+
+ my $answer = prompt_selection $prompt, %options;
+
+Ask the user a multiple-choice question and return the answer. The
+user is prompted via STDOUT/STDIN using $prompt (which is
+word-wrapped) and a list of choices. The choices are numbered
+(beginning with 1) and the user selects by number.
+
+The %options are given as option => value pairs. The following
+options are known:
+
+ choices (required)
+
+ The option 'choices' must be a reference to an ordered pairwise
+ array [ label1 => value1, label2 => value2, ... ]. The labels
will
+ be displayed to the user; the values are the return values if
that
+ option is chosen.
+
+ default (optional)
+
+ If the option 'default' is given, then it determines which
choice
+ will be returned if no input is detected.
+
+ This can occur if the user enters a null string, or if Fink
+ is configured to automatically accept defaults (i.e., bin/fink
+ was invoked with the -y or --yes option).
+
+ The following formats are recognized for the 'default' option:
+
+ @default = []; # choice 1
+ @default = ["number", $number]; # choice $number
+ @default = ["label", $label]; # first choice with label
$label
+ @default = ["value", $label]; # first choice with value
$value
+
+ Default value: choice 1
+
+ timeout (optional)
+
+ The 'timeout' option establishes a wait period (in seconds) for
+ the prompt, after which the default answer will be used.
+ If a timeout is given, any existing alarm() is destroyed.
+
+ Default value: no timeout
+
+=cut
+
+sub prompt_selection {
+ my $prompt = shift;
+ my %opts = (default => [], timeout => 0, @_);
+ my @choices = @{$opts{choices}};
+ my $default = $opts{default};
+
+ my ($count, $answer, $default_value);
+
+ if (@choices/2 != int(@choices/2)) {
+ confess 'Odd number of elements in @choices';
+ }
+
+ if (!defined $default->[0]) {
+ $default_value = 1;
+ } elsif ($default->[0] eq "number") {
+ $default_value = $default->[1];
+ $default_value = 1 if $default_value < 1 || $default_value >
@choices/2;
+ } elsif ($default->[0] =~ /^(label|value)$/) {
+ # will be handled later
+ } else {
+ confess "Unknown default type ",$default->[0];
+ }
+
+ $count = 0;
+ for (my $index = 0; $index <= $#choices; $index+=2) {
+ $count++;
+ print "\n($count) $choices[$index]";
+ if (!defined $default_value && (
+ (
+ ($default->[0] eq "label" &&
$choices[$index] eq $default->[1])
+ ||
+ ($default->[0] eq "value" &&
$choices[$index+1] eq $default->[1])
+ )
+ )) {
+ $default_value = $count;
+ }
+
+ }
+ $default_value = 1 if !defined $default_value;
+ print "\n\n";
+
+ $answer = &get_input("$prompt [$default_value]", $opts{timeout});
+ chomp($answer);
+ if (!$answer) {
+ $answer = 0;
+ }
+ $answer = int($answer);
+ if ($answer < 1 || $answer > $count) {
+ $answer = $default_value;
+ }
+ return $choices[2*$answer-1];
+}
+
=item get_term_width
my $width = get_term_width;
Index: Configure.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/Configure.pm,v
retrieving revision 1.27.2.3
retrieving revision 1.27.2.4
diff -u -d -r1.27.2.3 -r1.27.2.4
--- Configure.pm 2 Jan 2005 16:14:53 -0000 1.27.2.3
+++ Configure.pm 15 Apr 2005 16:23:06 -0000 1.27.2.4
@@ -25,7 +25,7 @@
use Fink::Config qw($config $basepath $libpath);
use Fink::Services qw(&read_properties &read_properties_multival &filename);
-use Fink::CLI qw(&prompt &prompt_boolean &prompt_selection_new
&print_breaking);
+use Fink::CLI qw(&prompt &prompt_boolean &prompt_selection_new
&prompt_selection &print_breaking);
use strict;
use warnings;
Index: ChangeLog
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/ChangeLog,v
retrieving revision 1.723.2.24
retrieving revision 1.723.2.25
diff -u -d -r1.723.2.24 -r1.723.2.25
--- ChangeLog 11 Apr 2005 22:28:30 -0000 1.723.2.24
+++ ChangeLog 15 Apr 2005 16:23:05 -0000 1.723.2.25
@@ -1,3 +1,8 @@
+2005-04-15 Dave Morrison <[EMAIL PROTECTED]>
+
+ * CLI.pm, Configure.pm: backport prompt_selection to branch_0_23
+ in preparation for revising the mirror selection dialog
+
2005-04-11 Dave Morrison <[EMAIL PROTECTED]>
* PkgVersion.pm: add a default for CXXFLAGS for recent distributions
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Fink-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fink-commits