ask($question,$default)
ask_yesno($question)
ask_defined($question,$default)
ask_match($question,$default,$pattern)
ask_integer($question,$default)
ask_float($question,$default)
ask_password($username)
ask_date(\@date)
ask_date_span(\@start,\@end)
ask_money_figure($amount,$currency,\@valid_currencies)
choose_one($label,\@choices)
choose_many($label,\@choices)
take_note(\$note)
ask_getopts(\%opts,@order)
ASCOPE::Term - Aaron's widget for doing things on the command line.
my $term = ASCOPE::Term->new();
if ($term->ask_yesno("Do something")) { my $answer = $term->choose_from_list("Choose me",\@options); }
This is Aaron's widget for doing things on the command line. While it is true that the world really doesn't need anymore terminal thingies, apparently I do.
It is really just a wrapper/helper module for a variety of Term::* modules with an interface that I like.
For the time being I will probably not send this package to the CPAN. If people want me to, I will reconsider.
new()
Returns an object. Woot!
ask($question,$default)
Returns user input for $question.
ask_yesno($question)
Returns true is answer begins with a ``y'' or equals ``1'', otherwise returns false.
Requires the user to return *something*.
ask_defined($question,$default)
Requires the user to return something that's been defined (translation: 0 may not pass a boolean test, but it *is* defined).
ask_match($question,$default,$pattern)
Require the user to return something that matches $pattern.
ask_integer($question,$default)
Prompt the user to return an integer.
Return the int if they do or undef otherwise.
ask_float($question,$default)
Prompt the user to return an floating point number.
Return the floatif they do or undef otherwise.
ask_password($username)
Prompts the user for a password and uses the Term::ReadKey package to hide user input.
Returns the password.
ask_date(\@date)
Prompt the use for a valid date.
Returns an array reference containing YYYY,MM,DD
The return value for this method may change in subsequent releases.
ask_date_span(\@start,\@end)
Prompt the use for two valid dates. Make sure that dates are chronological
Returns an array reference containing YYYY-MM-DD, YYYY-MM-DD
The return value for this method may change in subsequent releases
ask_money_figure($amount,$currency,\@valid_currencies)
Prompt the user for a money amount and a currency.
If no list of valid currencies is provided the user will br prompted to provide one.
Returns an array reference containing the amount followed by the currency.
choose_one($label,\@choices)
Prompt the user to choose one item from a set list.
Lists with eleven, or more, items are presented ten at a time along with the following options when applicable:
>> next
Display next (n) items
<< prev
Display previous (n) items
// done
Return any choices the user may have already made
\\ cancel
Return undef
|| show
Display the list of items the user has chosen
For example :
213 ->perl -I./lib ./t/005-choose_many.t +------------------------------------+ | 1 - 10 of 11 possible choices | +------------------------------------+ | * cow | | * dog | | * cat | | * bird | | * apple | | * boo | | * poo | | * zoo | | * hump | | * bump | +------------------------------------+ | >> next // done \\ cancel || show | +------------------------------------+ [choose]
The method uses the Term::Complete package in an effort to minimize unnecessary typing.
Returns a string.
choose_many($label,\@choices)
Prompt the user to choose one or more items from a set list.
See docs for $pkg->choose_one()
for details.
Returns an array reference.
take_note(\$note)
Prompt the user for a note -- anything that spans multiple lines -- or edit an existing one.
The following characters, followed by a new line, are treated as ``special'' :
End of note
!. (bang-dot)Delete current line
\n (newline)Insert new line
When the user passes an existing note, it is split on newlines and each is passed to the user for editing.
Returns a string
ask_getopts(\%opts,@order)
Prompt the user for bunch of stuff using Getopt::Long.
$opts is the associative array.
The key is expected to use the same format that the Getopt::Long::GetOptions manpage uses for keys.
The value for the key is an array reference whose values are :
Reference. Required.
This is a reference to the variable where the result is stored.
promptString.
If present this string will be printed to STDOUT when prompting the user for input. If not defined, the the key name for the current array ref will be used.
defaultCode reference.
This can be used to define a default value based on previous user input that is not already available at compile time.
The return value of your anonymous sub must be passed as a reference. Currently, the function is only smart about handling scalar refs.
If you return an array ref, for instance, hoping that the user will be required to choose from that list, you'll be disappointed. It's on the list.
If no default is provided then the default value is assumed to be any value already defined in result.
If @order is not defined, then the user will be prompted for each key in $opts alphabetically.
Example:
my %opts = ( "username" => "bob", "email" => undef, );
$term->ask_getopts({ "username=s" => [ \$opts{'username'}], "email=s" => [ \$opts{'email'}, "email address", sub { return \"$opts{'username'}\@bob.com"; }, ], "username","email", });
# would produce:
asc @ localhost in /home/asc/bin/perl/debug 122 ->./term-ref username? [bob] asc email address? [asc@bob.com] $VAR1 = { 'email' => 'asc@bob.com', 'username' => 'asc', };
This method still isn't very smart about lists.
0.2
$Date: 2003/06/23 12:51:05 $
Aaron Straup Cope
Memoize
This release works much better in an Emacs shell than earlier versions however there are still bugs. It basically doesn't work at all in eshell mode.
Copyright (c) 2001-2003, Aaron Straup Cope. All Rights Reserved.
This is free software, you may use it and distribute it under the same terms as Perl itself.