No description, website, or topics provided.
Perl6
Latest commit 2ed240c Dec 16, 2016 @kuerbis 0.015
Permalink
Failed to load latest commit information.
lib/Term 0.015 Dec 16, 2016
t 0.001 Mar 21, 2016
xt 0.001 Mar 21, 2016
.gitignore 0.001 Mar 21, 2016
.travis.yml 0.001 Mar 21, 2016
Changes 0.015 Dec 16, 2016
META6.json 0.009 May 15, 2016
README.md 0.015 Dec 16, 2016

README.md

Build Status

NAME

Term::Form - Read lines from STDIN.

VERSION

Version 0.015

SYNOPSIS

use Term::Form :readline, :fillform;

my @aoa = (
    [ 'name'           ],
    [ 'year'           ],
    [ 'color', 'green' ],
    [ 'city'           ]
);


# Functional interface:

my $line = readline( 'Prompt: ', { default => 'abc' } );

my @filled_form = fillform( @aoa, { auto-up => 0 } );


# OO interface:

my $new = Term::Form.new();

$line = $new.readline( 'Prompt: ', { default => 'abc' } );

@filled_form = $new.fillform( @aoa, { auto-up => 0 } );

FUNCTIONAL INTERFACE

Importing the subroutines explicitly (:name_of_the_subroutine) might become compulsory (optional for now) with the next release.

DESCRIPTION

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.

fillform reads a list of lines from STDIN.

Keys

BackSpace or Strg-H: Delete the character behind the cursor.

Delete or Strg-D: Delete the character at point. Return nothing if the input puffer is empty.

Strg-U: Delete the text backward from the cursor to the beginning of the line.

Strg-K: Delete the text from the cursor to the end of the line.

Right-Arrow: Move forward a character.

Left-Arrow: Move back a character.

Home or Strg-A: Move to the start of the line.

End or Strg-E: Move to the end of the line.

Only in fillform:

Up-Arrow: Move up one row.

Down-Arrow: Move down one row.

Page-Up or Strg-B: Move back one page.

Page-Down or Strg-F: Move forward one page.

CONSTRUCTOR

The constructor method new can be called with optional named arguments:

  • defaults

Expects as its value a hash. Sets the defaults for the instance. See #OPTIONS.

  • win

Expects as its value a window object created by ncurses initscr.

If set, readline and fillform use this global window instead of creating their own without calling endwin to restores the terminal before returning.

ROUTINES

readline

readline reads a line from STDIN.

The fist argument is the prompt string.

The optional second argument is a hash to set the different options. The keys/options are

With the optional second argument it can be passed the default value (see option default) as string or it can be passed the options as a hash. The options are

  • 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.

default: 0

  • header

With the option header it can be set a header-string which is shown on top of the output.

fillform

fillform reads a list of lines from STDIN.

The first argument is 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. The keys/options are

  • header

With the option header it can be set a header-string which 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 on a "readline". If the last "readline" row is reached, the cursor jumps to the first "readline" row if ENTER was pressed. If after an ENTER the cursor has jumped to the first "readline" row and auto-up is set to 1, ENTER doesn't move the cursor to the next row until the cursor is moved with another key.

With auto-up set to 2 ENTER moves the cursor to the top menu entry if the cursor is on a "readline".

default: 0

  • ro

Set form-rows to readonly.

Expected value: an array with the indexes of the rows which should be readonly.

default: empty array

  • confirm

Set the name of the "confirm" menu entry.

default: E<lt>E<lt>

  • back

Set the name of the "back" menu entry.

The "back" menu entry is not available if back is not defined or set to an empty string.

default: undefined

To close the form and get the modified list select the "confirm" menu entry. If the "back" menu entry is chosen to close the form, fillform returns nothing.

REQUIREMENTS

See Term::Choose#REQUIREMENTS.

AUTHOR

Matthäus Kiem cuer2s@gmail.com

CREDITS

Thanks to the people from Perl-Community.de, from stackoverflow and from #perl6 on irc.freenode.net for the help.

LICENSE AND COPYRIGHT

Copyright (C) 2016 Matthäus Kiem.

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.