| Term::ReadLine::Zoid(3pm) | User Contributed Perl Documentation | Term::ReadLine::Zoid(3pm) |
Term::ReadLine::Zoid - another ReadLine package
# In your app:
use Term::ReadLine;
my $term = Term::ReadLine->new("my app");
my $prompt = "eval: ";
my $OUT = $term->OUT || \*STDOUT;
while ( defined ($_ = $term->readline($prompt)) ) {
# Think while (<STDIN>) {}
my $res = eval($_);
warn $@ if $@;
print $OUT $res, "\n" unless $@;
}
# In some rc file
export PERL_RL=Zoid
This package provides a set of modules that form an interactive input buffer written in plain perl with minimal dependencies. It features almost all key-bindings described in the posix spec for the sh(1) utility with some extensions like multiline editing; this includes a vi-command mode with a save-buffer (for copy-pasting) and an undo-stack.
Historically this code was part of the Zoidberg shell, but this implementation is complete independent from zoid and uses the Term::ReadLine interface, so it can be used with other perl programs.
( The documentation sometimes referes to 'the application', this is the program using the ReadLine module for input. )
The Term::ReadLine interface module uses the "PERL_RL" variable to decide which module to load; so if you want to use this module for all your perl applications, try something like:
export PERL_RL=Zoid
The function name is given between parenthesis, these can be used for privat key maps.
The default key mapping is as follows:
Note that the delete_char_or_eof function does what delete_char should do to be compatible with GNU readline lib.
There is no default completion included in this package, so unless you define a custom expansion it doesn't do anything. See the "completion_function" option.
Uses the PAGER environment variable to find a suitable pager when there are more completions to be shown then would fit on the screen.
See also the "autolist" and "maxcomplete" options.
If _all_ lines in the buffer end with a single '\', the newline is considered escaped you can continue typing on the next line. This behaviour can be a bit unexpected because this module has multiline support which historic readline implementations have not, historically the escaping of a newline is done by the application not by the library. The suppress this behaviour, and let the application do it's thing, disable the "automultiline" option.
To enter the real multiline editing mode, press 'escape m', see Term::ReadLine::Zoid::MultiLine.
WARNING: control or escape chars in the editline can cause unexpected results
The following keys are different in mutline mode, the others fall back to the default behaviour.
The hash with options can be accessed with the "Attribs" method. These can be modified from the rc-file (see "FILES") or can be set from the "PERL_RL" environment variable. For example to disable the "autolist" feature you can set "PERL_RL='Zoid autolist=0'" before you start the application.
( Also they can be altered interactively using the mini-buffer of the command mode, see Term::ReadLine::Zoid::ViCommand. )
When there are multiple lines in the buffer they all need to start with the comment string for the buffer to be regarded as a comment.
The function will get the following arguments: $word, $buffer, $start. Where $word is the word before the cursor, while $buffer is the complete text on the command line; $start is the offset of $word in $buffer.
The function should return a list of possible completions of $word. The completion list is checked for double entries.
There is no default.
FIXME tell about the meta fields for advanced completion
If this option is set to the string 'pager' the user is asked when the number of completions is to big to fit on screen and a pager would be used.
Although the "PS1" prompt (as specified as an argument to the "readline()" method) can contain newlines, the PS2 prompt can't.
This module reads a rc-file on initialisation, either $HOME/.perl_rl_zoid_rc, $HOME/.zoid/perl_rl_zoid_rc or /etc/perl_rl_zoid_rc. The rc-file is a perl script with access to the Term::ReadLine::Zoid object through the method "current()". If you want to have different behaviour for different applications, try to check for "$rl->{appname}".
# in for example ~/.perl_rl_zoid_rc
my $rl = Term::ReadLine::Zoid->current();
# set low latency
$rl->Attribs()->{low_latency} = 1;
# alias control-space to escape
$rl->bindchr( chr(0), 'escape' );
# create an ad hoc macro
$rl->bindkey('^P', sub { $rl->press('mplayer -vo sdl ') } );
Functions specified by the Term::ReadLine documentation.
The prompt only supports the escape "!" for the history number of the current line, use "!!" for a literal "!". All other escapes you need to parse yourself, before supplying the prompt. The prompt defaults to "$appname !> ".
If you want to do more with your prompt see Env::PS1.
$preput can be used to set some text on the edit line already.
If "autohistory" is set this method will be called automatically by "readline".
Be aware that the naming scheme is quite arbitrary, this module uses the same names as Term::ReadLine::Gnu for common features.
If $sub is not a reference it is considered an alias; these aliases are not recursive.
For alphanumeric characters the name is the character itself, special characters have long speaking names and control characters are prefixed with a '^'.
Binding combination with the meta- or alt-key is not supported (see "NOTES").
Methods for use in overload classes.
Avoid using these methods from the application.
FIXME minimum subroutines new mode-class
FIXME how to set up a keymap
FIXME how to add a keymap/mode
With most modern keymappings the combination of the meta key (alt) with a letter is identical with an escape character followed by that letter.
Some functioality may in time be moved to the ::Base package.
UTF8 support, or general charset support, would be nice but at the moment I lack the means to test these things. If anyone has ideas or suggestions about this please contact me.
Line wrap doesn't always displays the last character on the line right, no functional bug though.
If the buffer size exceeds the screen size some bugs appear in the rendering.
Please mail the author if you find any other bugs.
Jaap Karssenberg || Pardus [Larus] <pardus@cpan.org>
Copyright (c) 2004 Jaap G Karssenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Term::ReadLine::Zoid::ViCommand, Term::ReadLine::Zoid::MultiLine, Term::ReadLine::Zoid::ISearch, Term::ReadLine::Zoid::FileBrowse, Term::ReadLine::Zoid::Base, Term::ReadLine, Env::PS1, Zoidberg
| 2022-06-17 | perl v5.34.0 |