Term::ReadLine::Zoid - another ReadLine package |
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 the Term::ReadLine manpage 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 the Term::ReadLine manpage 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:
undef
if the line is empty, else it deletes a char.
For a multiline buffer, ends editing and returns the lines
to the application if the cursor is on the last line and this line
is empty, else it deletes a char.
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 surpress 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 the Term::ReadLine::Zoid::MultiLine manpage.
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.
undef
.
undef
if the buffer is completely empty.
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 the Term::ReadLine::Zoid::ViCommand manpage. )
COLUMNS
and LINES
are kept up to date. By default enabled.
print "\cG"
, which makes the terminal ring a bell.
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.
$readline::rl_completion_function
will be checked if this option
isn't defined.
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
readline()
, also other
modes return to this mode if you exit them.
The default is 'insert' which is the single-line insert mode.
If you always want to edit in multiline mode set this option to 'multiline'.
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.
undef
all lines are ignored.
Defaults to ``0''.
"> "
.
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 intialisation, 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 the Term::ReadLine manpage documentation.
new($appname, $IN, $OUT)
ReadLine()
readline($prompt, $preput)
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 the Env::PS1 manpage.
$preput
can be used to set some text on the edit line allready.
addhistory($line)
AddHistory($line)
If autohistory is set this method will be called automaticly by readline.
IN()
OUT()
MinLine($value)
$value
and returns old value.
findConsole()
Attribs()
Features()
Be aware that the naming scheme is quite arbitrary, this module uses the same names as Term::ReadLine::Gnu for common features.
SetHistory(@hist)
GetHistory()
TermSize()
continue()
readline()
call.
Can be used to build a custom auto-mulitline feature.
current()
bindkey($key, $sub, $map)
$map
argument is optional and can be either
``default'', ``command'', ``isearch'' or ``multiline''.
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.
switch_mode($mode)
$mode
; changes the key map and
reblesses the object if the _on_switch
key returns a class name.
reset()
save()
restore($save)
set_history($int)
$int
in the buffer.
longest_match(@completion)
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.
the Term::ReadLine::Zoid::ViCommand manpage, the Term::ReadLine::Zoid::MultiLine manpage, the Term::ReadLine::Zoid::ISearch manpage, the Term::ReadLine::Zoid::FileBrowse manpage, the Term::ReadLine::Zoid::Base manpage, the Term::ReadLine manpage, the Env::PS1 manpage, Zoidberg
Term::ReadLine::Zoid - another ReadLine package |