Term::Form - Read lines from STDIN.
Version 0.313
use Term::Form; my $new = Term::Form->new( 'name' ); my $line = $new->readline( 'Prompt: ', { default => 'abc' } ); my $aoa = [ [ 'name' ], [ 'year' ], [ 'color', 'green' ], [ 'city' ] ]; my $modified_list = $new->fill_form( $aoa );
readline reads a line from STDIN. As soon as Return is pressed readline returns the read string without the newline character - so no chomp is required.
readline
Return
chomp
fill_form reads a list of lines from STDIN.
fill_form
This module is intended to cope with Unicode (multibyte character/grapheme cluster).
BackSpace or Strg-H: Delete the character behind the cursor.
BackSpace
Strg-H
Delete or Strg-D: Delete the character at point. Return nothing if the input puffer is empty.
Delete
Strg-D
Strg-U: Delete the text backward from the cursor to the beginning of the line.
Strg-U
Strg-K: Delete the text from the cursor to the end of the line.
Strg-K
Right-Arrow: Move forward a character.
Right-Arrow
Left-Arrow: Move back a character.
Left-Arrow
Home or Strg-A: Move to the start of the line.
Home
Strg-A
End or Strg-E: Move to the end of the line.
End
Strg-E
Only in fill_form:
Up-Arrow: Move up one row.
Up-Arrow
Down-Arrow: Move down one row.
Down-Arrow
Page-Up or Strg-B: Move back one page.
Page-Up
Strg-B
Page-Down or Strg-F: Move forward one page.
Page-Down
Strg-F
The new method returns a Term::Form object.
new
Term::Form
my $new = Term::Form->new();
The method config overwrites the defaults for the current Term::Form object.
config
$new->config( \%options );
The available options are: the options from readline and fill_form and
compat
If compat is set to 1, the return value of readline is not decoded else the return value of readline is decoded. With fill_form the second elements (values) of the arrays are returned encoded if compat is set to 1, else they are returned decoded.
1
Setting the environment variable READLINE_SIMPLE_COMPAT to a true value has the same effect as setting compat to 1 unless compat is defined. If compat is defined, READLINE_SIMPLE_COMPAT has no meaning.
Allowed values: 0 or 1.
0
default: no set
reinit_encoding
To get the right encoding Term::Form uses Encode::Locale. Passing an encoding to reinit_encoding changes the encoding reported by Encode::Locale. See "reinit-encoding" in Encode::Locale for more details.
Encode::Locale
Allowed values: an encoding which is recognized by the Encode module.
default: not set
readline reads a line from STDIN.
$line = $new->readline( $prompt, [ \%options ] );
The fist argument is the prompt string.
The optional second argument is the default string (see option default) if it is not a reference. If the second argument is a hash-reference, the hash is used to set the different options. The keys/options are
clear_screen
If enabled, the screen is cleared before the output.
default: disabled
info
Expects as is value a string. If set, the string is printed on top of the output of readline.
default
Set a initial value of input.
no_echo
- if set to 0, the input is echoed on the screen.
- if set to 1, "*" are displayed instead of the characters.
*
- if set to 2, no output is shown apart from the prompt string.
2
default: 0
$new_list = $new->fill_form( $aoa, { prompt => 'Required:' } );
The first argument is a reference to an array of arrays. The arrays have 1 or 2 elements: the first element is the key and the optional second element is the value. The key is used as the prompt string for the "readline", the value is used as the default value for the "readline" (initial value of input).
The optional second argument is a hash-reference. The keys/options are
Expects as is value a string. If set, the string is printed on top of the output of fill_form.
prompt
If prompt is set, a main prompt string is shown on top of the output.
default: undefined
auto_up
With auto_up set to 0 or 1 pressing ENTER moves the cursor to the next line (if the cursor is not on the "back" or "confirm" row). If the last row is reached, the cursor jumps to the first data row if ENTER is pressed. While with auto_up set to 0 the cursor loops through the rows until a key other than ENTER is pressed with auto_up set to 1 after one loop an ENTER moves the cursor to the top menu entry ("back") if no other key than ENTER was pressed.
ENTER
With auto_up set to 2 an ENTER moves the cursor to the top menu entry (except the cursor is on the "confirm" row).
If auto_up is set to 0 or 1 the initially cursor position is on the first data row while when set to 2 the initially cursor position is on the first menu entry ("back").
default: 1
read_only
Set a form-row to read only.
Expected value: a reference to an array with the indexes of the rows which should be read only.
default: empty array
confirm
Set the name of the "confirm" menu entry.
default: Confirm
Confirm
back
Set the name of the "back" menu entry.
The "back" menu entry can be disabled by setting back to an empty string.
default: Back
Back
To close the form and get the modified list (reference to an array or arrays) as the return value select the "confirm" menu entry. If the "back" menu entry is chosen to close the form, fill_form returns nothing.
Requires Perl version 5.8.3 or greater.
It is required a terminal which uses a monospaced font.
Unless the OS is MSWin32 the terminal has to understand ANSI escape sequences.
It is required to use appropriate I/O encoding layers. If the encoding layer for STDIN doesn't match the terminal's character set, readline will break if a non ascii character is entered.
You can find documentation for this module with the perldoc command.
perldoc Term::Form
Matthäus Kiem <cuer2s@gmail.com>
Thanks to the Perl-Community.de and the people form stackoverflow for the help.
Copyright 2014-2018 Matthäus Kiem.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For details, see the full text of the licenses in the file LICENSE.
To install Term::Form, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Term::Form
CPAN shell
perl -MCPAN -e shell install Term::Form
For more information on module installation, please visit the detailed CPAN module installation guide.