NAME

Term::ReadLine::Tiny - Read a line from STDIN.

VERSION

Version 0.002

SYNOPSIS

use Term::ReadLine::Tiny;

my $new = Term::ReadLine::Tiny->new( 'name' );
my $line = $new->readline( 'Prompt: ', { default => 'abc' } );

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.

A Strg-D removes the input-puffer if any, else it causes readline to return nothing.

BackSpace (or Strg-H) deletes the last character of the string.

Term::ReadLine::Tiny is new so things may change in the next release.

METHODS

new

The new method returns a Term::ReadLine::Tiny object.

my $new = Term::ReadLine::Tiny->new( 'name' );

The argument is the name of the application.

config

The method config sets the defaults for the current Term::ReadLine::Tiny object.

$new->config( \%options );

The available options are:

  • asterix

    Sets the default asterix.

    Allowed values: a decoded string.

    Default: '*'.

  • default

    Sets the default default string.

    Allowed values: a decoded string.

    Default: not set.

  • no_echo

    Sets the default value for no_echo.

    Allowed values: 0 or 1.

    Default: 0.

Options not available in the readline method:

  • compat

    If compat is set to 1, the return value of readline is not decoded else the return value of readline is decoded if the OS is a 'MSWin32' OS or if Term::ReadKey::ReadKey returns strings where utf8::is_utf8 is true.

    Setting the environment variable READLINE_TINY_COMPAT to a true value has the same effect as setting compat to 1 unless compat is defined. If compat is defined READLINE_TINY_COMPAT has no meaning.

    Allowed values: 0 or 1.

    Default: no set

  • reinit_encoding

    To get the right encoding Term::ReadLine::Tiny 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.

    Allowed values: an encoding which is recognized by the Encode module.

    Default: not set.

readline

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

  • asterix

    Sets the string, which is displayed instead of a character when no_echo is enabled. To get no output at all in the no_echo mode set asterix to the empty string.

  • default

    Sets a initial value of input.

  • no_echo

    If no_echo is enabled, asterisk strings are displayed instead of the characters.

See "config" for the default and allowed values.

REQUIREMENTS

Perl version

Requires Perl version 5.10.1 or greater.

Encoding layer for STDOUT

For a correct output it is required an appropriate encoding layer for STDOUT.

MSWin32: Adding print "\e(U" to the code disables the Windows own codepage conversion (e.g. to make the script more portable). See "Escape_sequences_for_Select_Character_Set" in Win32::Console::ANSI for more details.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Term::ReadLine::Tiny

AUTHOR

Matthäus Kiem <cuer2s@gmail.com>

CREDITS

Thanks to the Perl-Community.de and the people form stackoverflow for the help.

LICENSE AND COPYRIGHT

Copyright 2014 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.