Update of /cvsroot/fink/fink/perlmod/Fink In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12551
Modified Files: ChangeLog CLI.pm Log Message: Add $timeout param to CLI::prompt() and CLI::prompt_selection_new(). Index: ChangeLog =================================================================== RCS file: /cvsroot/fink/fink/perlmod/Fink/ChangeLog,v retrieving revision 1.805 retrieving revision 1.806 diff -u -d -r1.805 -r1.806 --- ChangeLog 14 Jan 2005 19:21:08 -0000 1.805 +++ ChangeLog 17 Jan 2005 03:47:27 -0000 1.806 @@ -1,3 +1,7 @@ +2005-01-16 Daniel Macks <[EMAIL PROTECTED]> + + * CLI.pm: Add $timeout param to prompt() and prompt_selection_new(). + 2005-01-14 Daniel Macks <[EMAIL PROTECTED]> * PkgVersion.pm: Re-add missing \n in get_description. Index: CLI.pm =================================================================== RCS file: /cvsroot/fink/fink/perlmod/Fink/CLI.pm,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- CLI.pm 2 Jan 2005 15:56:49 -0000 1.15 +++ CLI.pm 17 Jan 2005 03:47:27 -0000 1.16 @@ -166,13 +166,17 @@ my $answer = prompt $prompt; my $answer = prompt $prompt, $default; + my $answer = prompt $prompt, $default, $timeout; Ask the user a question and return the answer. The user is prompted via STDOUT/STDIN using $prompt (which is word-wrapped). If the user returns a null string or Fink is configured to automatically accept defaults (i.e., bin/fink was invoked with the -y or --yes option), the default answer $default is returned (or a null string if no $default -is not defined). +is not defined). The optional $timeout argument 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. =cut @@ -180,10 +184,10 @@ my $prompt = shift; my $default_value = shift; $default_value = "" unless defined $default_value; - my ($answer); + my $timeout = shift || 0; - $answer = &get_input("$prompt [$default_value]", 0); - chomp($answer); + my $answer = &get_input("$prompt [$default_value]", $timeout); + chomp $answer; $answer = $default_value if $answer eq ""; return $answer; } @@ -200,7 +204,7 @@ is true, otherwise it is false. If the user returns a null string or Fink is configured to automatically accept defaults (i.e., bin/fink was invoked with the -y or --yes option), the default answer is -returned. The optional $timeout argument establishes a wait period +returned. The optional $timeout argument 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. @@ -211,11 +215,11 @@ my $default_value = shift; $default_value = 1 unless defined $default_value; my $timeout = shift || 0; - my ($answer, $meaning); + my $meaning; while (1) { - $answer = &get_input("$prompt [".($default_value ? "Y/n" : "y/N")."]", $timeout); - chomp($answer); + my $answer = &get_input("$prompt [".($default_value ? "Y/n" : "y/N")."]", $timeout); + chomp $answer; if ($answer eq "") { $meaning = $default_value; last; @@ -234,6 +238,7 @@ =item prompt_selection_new my $answer = prompt_selection_new $prompt, [EMAIL PROTECTED], @choices; + my $answer = prompt_selection_new $prompt, [EMAIL PROTECTED], @choices, $timeout; Ask the user a multiple-choice question and return the answer. The user is prompted via STDOUT/STDIN using $prompt (which is @@ -250,13 +255,19 @@ @default = ["label", $label]; # first choice with label $label @default = ["value", $label]; # first choice with value $value +The optional $timeout argument 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. + =cut sub prompt_selection_new { my $prompt = shift; my $default = shift; my @choices = @_; - my ($count, $index, $answer, $default_value); + my $timeout = shift || 0; + + my ($count, $answer, $default_value); if (@choices/2 != int(@choices/2)) { confess "Odd number of elements in [EMAIL PROTECTED]"; @@ -274,7 +285,7 @@ } $count = 0; - for ($index = 0; $index <= $#choices; $index+=2) { + for (my $index = 0; $index <= $#choices; $index+=2) { $count++; print "\n($count) $choices[$index]"; if (!defined $default_value && ( @@ -291,7 +302,7 @@ $default_value = 1 if !defined $default_value; print "\n\n"; - $answer = &get_input("$prompt [$default_value]", 0); + $answer = &get_input("$prompt [$default_value]", $timeout); chomp($answer); if (!$answer) { $answer = 0; ------------------------------------------------------- The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt _______________________________________________ Fink-commits mailing list Fink-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/fink-commits