SYNOPSIS

PREREQUISITES

You must have Text::Wrap and Term::ReadKey available on your system.

DESCRIPTION

This main function of this module is to accept interactive input. You specify the type of inputs allowed, a prompt, help text and defaults and it will deal with the user interface, (and the user!), by displaying the prompt, showing the default, and checking to be sure that the response is one of the legal choices. Additional 'types' that could be added would be a phone type, a social security type, a generic numeric pattern type...

FUNCTIONS

prompt

This is the main function of the module. Its first argument determines its usage and is one of the following single characters:

This will create a menu with numbered items to select. You replace the normal prompt argument with a hash reference containing this information:

prompt

The prompt string.

title

Text printed above the menu.

items

An array reference to the list of text items to display. They will be numbered ascending in the order presented.

order

If set to 'across', the item numbers run across the menu:

1) foo 2) bar 3) baz
4) biff 5) spork 6) boof
7) akak

If set to 'down', the item numbers run down the menu:

1) foo 4) biff 7) akak
2) bar 5) spork
3) baz 6) boof

'down' is the default.

rows,cols

Forces the number of rows and columns. Otherwise, the number of rows and columns is determined from the number of items and the maximum length of an item with its number.

Usually, you would set rows = 1 or cols = 1 to force a non-wrapped layout. Setting both in tandem is untested. Cavet programmer.

display_base,return_base

Internally, the items are indexed the 'Perl' way, from 0 to scalar -1. The display_base is the number added to the index on the menu display. The return_base is the number added to the index before the reply is returned to the programmer.

The defaults are 1 and 0, respectively.

accept_multiple_selections

When set to logical true (1 will suffice), more than one menu item may be selected. The return from prompt() will be an array or array ref, depending on how it is called.

The default is 0. The return value is a single scalar containing the selection.

accept_empty_selection

When set to logical true (1 will suffice), if no items are selected, the menu will not be repeated and the 'empty' selection will be returned. The value of an 'empty' selection is an empty array or a reference to same, if accept_multiple_selections is in effect, or undef if not.

separator

A regular expression that defines what characters are allowed between multiple responses. The default is to allow all non-numeric characters to be separators. That can cause problems when a user mistakenly enters the lead letter of the menu item instead of the item number. You are better off replacing the default with something more reasonable, such as:

before parsing. NOTE: Do not set this option if you are including whitespace as a legal separator.

ignore_empties

When set, consecutive separators will not result in an empty entry. For example, without setting this option:

1,,8,9

will result in a return of

(1,'',8,9)

When set, the return will be:

(1,8,9)

which is probably what you want.

Other Functions and Variables

termwrap

Part of Term::Prompt is the optionally exported function termwrap, which is used to wrap lines to the width of the currently selected filehandle (or to STDOUT or STDERR if the width of the current filehandle cannot be determined). It uses the GetTerminalSize function from Term::ReadKey then Text::Wrap.

MULTILINE_INDENT

This package variable holds the string to be used to indent lines of a multiline prompt, after the first line. The default is "\t", which is how the module worked before the variable was exposed. If you do not want ANY indentation:

$Term::Prompt::MULTILINE_INDENT = '';

Text and Help Prompts

What, you might ask, is the difference between a 'text prompt' and a 'help prompt'? Think about the case where the 'legal_options' look something like: '1-1000'. Now consider what happens when you tell someone that '0' is not between 1-1000 and that the possible choices are: :) 1 2 3 4 5 ..... This is what the 'help prompt' is for.

It will work off of unique parts of 'legal_options'.

Changed by Allen - if you capitalize the type of prompt, it will be treated as a true 'help prompt'; that is, it will be printed ONLY if the menu has to be redisplayed due to and entry error. Otherwise, it will be treated as a list of options and displayed only the first time the menu is displayed.

Capitalizing the type of prompt will also mean that a return may be accepted as a response, even if there is no default; whether it actually is will depend on the type of prompt. Menus, for example, do not do this.

AUTHOR

Original Author: Mark Henderson (henderson@mcs.anl.gov or systems@mcs.anl.gov). Derived from im_prompt2.pl, from anlpasswd (see ftp://info.mcs.anl.gov/pub/systems/), with permission.

SEE ALSO

COPYRIGHT AND LICENSE

Copyright (C) 2004 by Matthew O. Persico

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.1 or, at your option, any later version of Perl 5 you may have available.

Module Install Instructions

To install Term::Prompt, simply copy and paste either of the commands in to your terminal