Term::ReadLine::readline
Wraps what was initially Perl4 (and now partially Perl4) into a fake Perl5 pseudo-module.
The mismatch of the package name, readline and file name Term::ReadLine::readline was intentional to make is harder to abuse this (very fragile) code...
readline
InitKeymap(*keymap, 'default', 'name', bindings...)
_unescape($string) -> List of keys
_unescape($string)
This internal function that takes $string possibly containing escape sequences, and converts to a series of octal keys.
$string
It has special rules for dealing with readline-specific escape-sequence commands.
New-style key bindings are enclosed in double-quotes. Characters are taken verbatim except the special cases:
\C-x Control x (for any x) \M-x Meta x (for any x) \e Escape \* Set the keymap default (JP: added this) (must be the last character of the sequence) \x x (unless it fits the above pattern)
Special case "\C-\M-x", should be treated like "\M-\C-x".
actually_do_binding($function1, \@sequence1, ...)
Actually inserts the binding for @sequence to $function into the current map. @sequence is an array of character ordinals.
@sequence
$function
If sequence is more than one element long, all but the last will cause meta maps to be created.
sequence
$Function will have an implicit F_ prepended to it.
$Function
F_
Accepts an array as pairs ($keyspec, $function, [$keyspec, $function]...). and maps the associated bindings to the current KeyMap.
$keyspec should be the name of key sequence in one of two forms:
$keyspec
Old (GNU readline documented) form: M-x to indicate Meta-x C-x to indicate Ctrl-x M-C-x to indicate Meta-Ctrl-x x simple char x
where 'x' above can be a single character, or the special:
special means -------- ----- space space ( ) spc space ( ) tab tab (\t) del delete (0x7f) rubout delete (0x7f) newline newline (\n) lfd newline (\n) ret return (\r) return return (\r) escape escape (\e) esc escape (\e)
New form: "chars" (note the required double-quotes)
where each char in the list represents a character in the sequence, except for the special sequences:
\\C-x Ctrl-x \\M-x Meta-x \\M-C-x Meta-Ctrl-x \\e escape. \\x x (if not one of the above)
$function should be in the form BeginningOfLine or beginning-of-line.
BeginningOfLine
beginning-of-line
It is an error for the function to not be known....
As an example, the following lines in .inputrc will bind one's xterm arrow keys:
"\e[[A": previous-history "\e[[B": next-history "\e[[C": forward-char "\e[[D": backward-char
read_an_init_file(inputrc_file)
Reads and executes inputrc_file which does things like Sets input key bindings in key maps.
If there was a problem return 0. Otherwise return 1;
A version readline for a dumb terminal, that is one that doesn't have many terminal editing capabilities.
&readline::readline($prompt, $default)
The main routine to call interactively read lines.
$default can be omitted. The next input line is returned or undef on EOF.
$default
undef
ctrl($ord)
Returns the ordinal number for the corresponding control code.
For example ctrl(ord('a')) returns the ordinal for Ctrl-A or 1. ctrl(ord('A')) does the same thing.
substr_with_props($prompt, $string, $from, $len, $ket, $bsel, $esel)
Gives the substr() of $prompt.$string with embedded face-change commands.
$prompt.$string
redisplay()
Updates the screen to reflect the current value if $line.
$line
For the purposes of this routine, we prepend the prompt to a local copy of $line so that we display the prompt as well. We then modify it to reflect that some characters have different sizes. That is, control-C is represented as ^C, tabs are expanded, etc.
^C
This routine is somewhat complicated by two-byte characters.... must make sure never to try do display just half of one.
Note: If an argument is given, it is used instead of the prompt.
This is some nasty code.
get_command(*keymap, $ord_command_char)
If the *keymap) has an entry for $ord_command_char, it is returned. Otherwise, the default command in $Keymap{'default'} is returned if that exists. If $Keymap{'default'} is false, 'F_Ding' is returned.
*keymap
$ord_command_char
$Keymap{'default'}
'F_Ding'
do_command(*keymap, $numericarg, $key)
If the *keymap has an entry for $key, it is executed. Otherwise, the default command for the keymap is executed.
$key
savestate()
Save whatever state we wish to save as an anonymous array. The only other function that needs to know about its encoding is getstate/preserve_state.
preserve_tate()
F_SelfInsert($count, $ord)
$ord is an ASCII ordinal; inserts $count of them into $line.
$ord
$count
Return the line as-is to the user.
Insert into history list if:
bigger than the minimal length
not same as last entry
rl_set($var_name, $value_string)
Sets the named variable as per the given value, if both are appropriate. Allows the user of the package to set such things as HorizontalScrollMode and EditingMode. Value_string may be of the form
HorizontalScrollMode horizontal-scroll-mode
Also called during the parsing of ~/.inputrc for "set var value" lines.
The previous value is returned, or undef on error.
Consider the following example for how to add additional variables accessible via rl_set (and hence via ~/.inputrc).
Want:
We want an external variable called "FooTime" (or "foo-time"). It may have values "January", "Monday", or "Noon". Internally, we'll want those values to translate to 1, 2, and 12.
How:
Have an internal variable $var_FooTime that will represent the current internal value, and initialize it to the default value. Make an array %var_FooTime whose keys and values are are the external (January, Monday, Noon) and internal (1, 2, 12) values:
$var_FooTime = $var_FooTime{'January'} = 1; #default $var_FooTime{'Monday'} = 2; $var_FooTime{'Noon'} = 12;
OnSecondByte($index)
Returns true if the byte at $index into $line is the second byte of a two-byte character.
$index
CharSize($index)
Returns the size of the character at the given $index in the current line. Most characters are just one byte in length. However, if the byte at the index and the one after both have the high bit set and $_rl_japanese_mb is set, those two bytes are one character of size two.
Assumes that $index points to the first of a 2-byte char if not pointing to a 1-byte char.
TODO: handle Unicode
WordBreak(index)
Returns true if the character at index into $line is a basic word break character, false otherwise.
kills from D=$_[0] to $_[1] (to the killbuffer if $_[2] is true)
Returns true if $D at the end of the line.
Move forward (right) $count characters.
Move backward (left) $count characters.
Go to beginning of line.
Move to the end of the line.
Move to the end of this/next word. Done as many times as $count says.
Move to the beginning of this/next word. Done as many times as $count says.
Refresh the input line.
Clear the screen and refresh the line. If given a numeric arg other than 1, simply refreshes the line.
Insert the next character read verbatim.
Insert a tab.
Accept the current line and fetch from the history the next line relative to current line for default.
Removes $count chars to left of cursor (if not at beginning of line). If $count > 1, deleted chars saved to kill buffer.
Removes the $count chars from under the cursor. If there is no line and the last command was different, tells readline to return EOF. If there is a line, and the cursor is at the end of it, and we're in tcsh completion mode, then list possible completions. If $count > 1, deleted chars saved to kill buffer.
Kill to previous whitespace.
Kill line from cursor to beginning of line.
delete characters from cursor to end of line.
Delete characters from cursor to beginning of line.
TextInsert($count, $string)
Delete characters to the end of the current word. If not on a word, delete to ## the end of the next word.
Delete characters backward to the start of the current word, or, if currently ## not on a word (or just at the start of a word), to the start of the ## previous word.
Abort the current input.
If the character that got us here is upper case, do the lower-case equivalent command.
do the equiv with control key... If the character that got us here is upper case, do the lower-case equivalent command.
do the equiv with meta key...
If the character that got us here is Alt-Char, do the Esc Char equiv...
Undo one level.
Replace the current line to some "before" state.
Delete characteres from cursor to end of line and enter VI input mode.
To install Term::ReadLine::Perl5, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Term::ReadLine::Perl5
CPAN shell
perl -MCPAN -e shell install Term::ReadLine::Perl5
For more information on module installation, please visit the detailed CPAN module installation guide.