Gnu(3) User Contributed Perl Documentation Gnu(3)
NAME
Term::ReadLine::Gnu - Perl extension for the GNU Readline/History Library
SYNOPSIS
use Term::ReadLine;
$term = new Term::ReadLine 'ProgramName';
while ( defined ($_ = $term->readline('prompt>')) ) {
...
}
DESCRIPTION
Overview
This is an implementation of Term::ReadLine using the GNU Readline/History Library.
For basic functions object oriented interface is provided. These are described in the section "Standard Methods" and ""Term::ReadLine::Gnu"
Functions".
This package also has the interface with the almost all functions and variables which are documented in the GNU Readline/History Library
Manual. They are documented in the section ""Term::ReadLine::Gnu" Functions" and ""Term::ReadLine::Gnu" Variables" briefly. For more
detail of the GNU Readline/History Library, see 'GNU Readline Library Manual' and 'GNU History Library Manual'.
The sample programs under "eg/" directory and test programs under "t/" directory in the "Term::ReadLine::Gnu" distribution include many
example of this module.
Standard Methods
These methods are standard methods defined by Term::ReadLine.
"ReadLine"
returns the actual package that executes the commands. If you have installed this package, possible value is "Term::ReadLine::Gnu".
"new(NAME,[IN[,OUT]])"
returns the handle for subsequent calls to following functions. Argument is the name of the application. Optionally can be followed
by two arguments for "IN" and "OUT" file handles. These arguments should be globs.
"readline(PROMPT[,PREPUT])"
gets an input line, with actual "GNU Readline" support. Trailing newline is removed. Returns "undef" on "EOF". "PREPUT" is an
optional argument meaning the initial value of input.
The optional argument "PREPUT" is granted only if the value "preput" is in "Features".
"PROMPT" may include some escape sequences. Use "RL_PROMPT_START_IGNORE" to begin a sequence of non-printing characters, and
"RL_PROMPT_END_IGNORE" to end of such a sequence.
"AddHistory(LINE1, LINE2, ...)"
adds the lines to the history of input, from where it can be used if the actual "readline" is present.
"IN", "OUT"
return the file handles for input and output or "undef" if "readline" input and output cannot be used for Perl.
"MinLine([MAX])"
If argument "MAX" is specified, it is an advice on minimal size of line to be included into history. "undef" means do not include
anything into history. Returns the old value.
"findConsole"
returns an array with two strings that give most appropriate names for files for input and output using conventions "<$in", ">$out".
"Attribs"
returns a reference to a hash which describes internal configuration (variables) of the package. Names of keys in this hash conform to
standard conventions with the leading "rl_" stripped.
See section "Variables" for supported variables.
"Features"
Returns a reference to a hash with keys being features present in current implementation. Several optional features are used in the
minimal interface: "appname" should be present if the first argument to "new" is recognized, and "minline" should be present if
"MinLine" method is not dummy. "autohistory" should be present if lines are put into history automatically (maybe subject to
"MinLine"), and "addHistory" if "AddHistory" method is not dummy. "preput" means the second argument to "readline" method is
processed. "getHistory" and "setHistory" denote that the corresponding methods are present. "tkRunning" denotes that a Tk application
may run while ReadLine is getting input.
"Term::ReadLine::Gnu" Functions
All these GNU Readline/History Library functions are callable via method interface and have names which conform to standard conventions
with the leading "rl_" stripped.
Almost methods have lower level functions in "Term::ReadLine::Gnu::XS" package. To use them full qualified name is required. Using method
interface is preferred.
Readline Convenience Functions
Naming Function
"add_defun(NAME, FUNC [,KEY=-1])"
Add name to the Perl function "FUNC". If optional argument "KEY" is specified, bind it to the "FUNC". Returns reference to
"FunctionPtr".
Example:
# name name `reverse-line' to a function reverse_line(),
# and bind it to "C-t"
$term->add_defun('reverse-line', &reverse_line, ord "ct");
Selecting a Keymap
"make_bare_keymap"
Keymap rl_make_bare_keymap()
"copy_keymap(MAP)"
Keymap rl_copy_keymap(Keymap|str map)
"make_keymap"
Keymap rl_make_keymap()
"discard_keymap(MAP)"
Keymap rl_discard_keymap(Keymap|str map)
"get_keymap"
Keymap rl_get_keymap()
"set_keymap(MAP)"
Keymap rl_set_keymap(Keymap|str map)
"get_keymap_by_name(NAME)"
Keymap rl_get_keymap_by_name(str name)
"get_keymap_name(MAP)"
str rl_get_keymap_name(Keymap map)
Binding Keys
"bind_key(KEY, FUNCTION [,MAP])"
int rl_bind_key(int key, FunctionPtr|str function,
Keymap|str map = rl_get_keymap())
Bind "KEY" to the "FUNCTION". "FUNCTION" is the name added by the "add_defun" method. If optional argument "MAP" is
specified, binds in "MAP". Returns non-zero in case of error.
"bind_key_if_unbound(KEY, FUNCTION [,MAP])"
int rl_bind_key_if_unbound(int key, FunctionPtr|str function,
Keymap|str map = rl_get_keymap()) #GRL5.0
"unbind_key(KEY [,MAP])"
int rl_unbind_key(int key, Keymap|str map = rl_get_keymap())
Bind "KEY" to the null function. Returns non-zero in case of error.
"unbind_function(FUNCTION [,MAP])"
int rl_unbind_function(FunctionPtr|str function,
Keymap|str map = rl_get_keymap())
"unbind_command(COMMAND [,MAP])"
int rl_unbind_command(str command,
Keymap|str map = rl_get_keymap())
"bind_keyseq(KEYSEQ, FUNCTION [,MAP])"
int rl_bind_keyseq(str keyseq, FunctionPtr|str function,
Keymap|str map = rl_get_keymap()) # GRL 5.0
"set_key(KEYSEQ, FUNCTION [,MAP])"
int rl_set_key(str keyseq, FunctionPtr|str function,
Keymap|str map = rl_get_keymap())
"bind_keyseq_if_unbound(KEYSEQ, FUNCTION [,MAP])"
int rl_bind_keyseq_if_unbound(str keyseq, FunctionPtr|str function,
Keymap|str map = rl_get_keymap()) # GRL 5.0
"generic_bind(TYPE, KEYSEQ, DATA, [,MAP])"
int rl_generic_bind(int type, str keyseq,
FunctionPtr|Keymap|str data,
Keymap|str map = rl_get_keymap())
"parse_and_bind(LINE)"
void rl_parse_and_bind(str line)
Parse "LINE" as if it had been read from the ~/.inputrc file and perform any key bindings and variable assignments found. For
more detail see 'GNU Readline Library Manual'.
"read_init_file([FILENAME])"
int rl_read_init_file(str filename = '~/.inputrc')
Associating Function Names and Bindings
"named_function(NAME)"
FunctionPtr rl_named_function(str name)
"get_function_name(FUNCTION)"
str rl_get_function_name(FunctionPtr function)
"function_of_keyseq(KEYMAP [,MAP])"
(FunctionPtr|Keymap|str data, int type)
rl_function_of_keyseq(str keyseq,
Keymap|str map = rl_get_keymap())
"invoking_keyseqs(FUNCTION [,MAP])"
(@str) rl_invoking_keyseqs(FunctionPtr|str function,
Keymap|str map = rl_get_keymap())
"function_dumper([READABLE])"
void rl_function_dumper(int readable = 0)
"list_funmap_names"
void rl_list_funmap_names()
"funmap_names"
(@str) rl_funmap_names()
"add_funmap_entry(NAME, FUNCTION)"
int rl_add_funmap_entry(char *name, FunctionPtr|str function)
Allowing Undoing
"begin_undo_group"
int rl_begin_undo_group()
"end_undo_group"
int rl_end_undo_group()
"add_undo(WHAT, START, END, TEXT)"
int rl_add_undo(int what, int start, int end, str text)
"free_undo_list"
void rl_free_undo_list()
"do_undo"
int rl_do_undo()
"modifying([START [,END]])"
int rl_modifying(int start = 0, int end = rl_end)
Redisplay
"redisplay"
void rl_redisplay()
"forced_update_display"
int rl_forced_update_display()
"on_new_line"
int rl_on_new_line()
"on_new_line_with_prompt"
int rl_on_new_line_with_prompt() # GRL 4.1
"reset_line_state"
int rl_reset_line_state()
rl_show_char(C)
int rl_show_char(int c)
"message(FMT[, ...])"
int rl_message(str fmt, ...)
"crlf"
int rl_crlf() # GRL 4.2
"clear_message"
int rl_clear_message()
"save_prompt"
void rl_save_prompt()
"restore_prompt"
void rl_restore_prompt()
"expand_prompt(PROMPT)"
int rl_expand_prompt(str prompt) # GRL 4.2
"set_prompt(PROMPT)"
int rl_set_prompt(const str prompt) # GRL 4.2
Modifying Text
"insert_text(TEXT)"
int rl_insert_text(str text)
"delete_text([START [,END]])"
int rl_delete_text(int start = 0, int end = rl_end)
"copy_text([START [,END]])"
str rl_copy_text(int start = 0, int end = rl_end)
"kill_text([START [,END]])"
int rl_kill_text(int start = 0, int end = rl_end)
"push_macro_input(MACRO)"
int rl_push_macro_input(str macro)
Character Input
"read_key"
int rl_read_key()
"getc(STREAM)"
int rl_getc(FILE *STREAM)
stuff_char(C)
int rl_stuff_char(int c)
execute_next(C)
int rl_execute_next(int c) # GRL 4.2
"clear_pending_input()"
int rl_clear_pending_input() # GRL 4.2
"set_keyboard_input_timeout(uSEC)"
int rl_set_keyboard_input_timeout(int usec) # GRL 4.2
Terminal Management
"prep_terminal(META_FLAG)"
void rl_prep_terminal(int META_FLAG) # GRL 4.2
"deprep_terminal()"
void rl_deprep_terminal() # GRL 4.2
"tty_set_default_bindings(KMAP)"
void rl_tty_set_default_bindings([Keymap KMAP]) # GRL 4.2
"tty_unset_default_bindings(KMAP)"
void rl_tty_unset_default_bindings([Keymap KMAP]) # GRL 5.0
"reset_terminal([TERMINAL_NAME])"
int rl_reset_terminal(str terminal_name = getenv($TERM)) # GRL 4.2
Utility Functions
"replace_line(TEXT [,CLEAR_UNDO]"
int rl_replace_line(str text, int clear_undo) # GRL 4.3
"initialize"
int rl_initialize()
"ding"
int rl_ding()
alphabetic(C)
int rl_alphabetic(int C)
"display_match_list(MATCHES [,LEN [,MAX]])"
void rl_display_match_list(@matches, len = $#maches, max) # GRL 4.0
Since the first element of an array @matches as treated as a possible completion, it is not displayed. See the descriptions of
"completion_matches()".
When "MAX" is ommited, the max length of an item in @matches is used.
Miscellaneous Functions
"macro_bind(KEYSEQ, MACRO [,MAP])"
int rl_macro_bind(const str keyseq, const str macro, Keymap map)
"macro_dumper(READABLE)"
int rl_macro_dumper(int readline)
"variable_bind(VARIABLE, VALUE)"
int rl_variable_bind(const str variable, const str value)
"variable_value(VARIABLE)"
str rl_variable_value(const str variable) # GRL 5.1
"variable_dumper(READABLE)"
int rl_variable_dumper(int readline)
"set_paren_blink_timeout(uSEC)"
int rl_set_paren_blink_timeout(usec) # GRL 4.2
"get_termcap(cap)"
str rl_get_termcap(cap)
Alternate Interface
"callback_handler_install(PROMPT, LHANDLER)"
void rl_callback_handler_install(str prompt, pfunc lhandler)
"callback_read_char"
void rl_callback_read_char()
"callback_handler_remove"
void rl_callback_handler_remove()
Readline Signal Handling
"cleanup_after_signal"
void rl_cleanup_after_signal() # GRL 4.0
"free_line_state"
void rl_free_line_state() # GRL 4.0
"reset_after_signal"
void rl_reset_after_signal() # GRL 4.0
"resize_terminal"
void rl_resize_terminal() # GRL 4.0
"set_screen_size(ROWS, COLS)"
void rl_set_screen_size(int ROWS, int COLS) # GRL 4.2
"get_screen_size()"
(int rows, int cols) rl_get_screen_size() # GRL 4.2
"reset_screen_size()"
void rl_reset_screen_size() # GRL 5.1
"set_signals"
int rl_set_signals() # GRL 4.0
"clear_signals"
int rl_clear_signals() # GRL 4.0
Completion Functions
"complete_internal([WHAT_TO_DO])"
int rl_complete_internal(int what_to_do = TAB)
"completion_mode(FUNCTION)"
int rl_completion_mode(FunctionPtr|str function)
"completion_matches(TEXT [,FUNC])"
(@str) rl_completion_matches(str text,
pfunc func = filename_completion_function)
"filename_completion_function(TEXT, STATE)"
str rl_filename_completion_function(str text, int state)
"username_completion_function(TEXT, STATE)"
str rl_username_completion_function(str text, int state)
"list_completion_function(TEXT, STATE)"
str list_completion_function(str text, int state)
History Functions
Initializing History and State Management
"using_history"
void using_history()
History List Management
"addhistory(STRING[, STRING, ...])"
void add_history(str string)
"StifleHistory(MAX)"
int stifle_history(int max|undef)
stifles the history list, remembering only the last "MAX" entries. If "MAX" is undef, remembers all entries. This is a
replacement of unstifle_history().
"unstifle_history"
int unstifle_history()
This is equivalent with 'stifle_history(undef)'.
"SetHistory(LINE1 [, LINE2, ...])"
sets the history of input, from where it can be used if the actual "readline" is present.
"add_history_time(STRING)"
void add_history_time(str string) # GRL 5.0
"remove_history(WHICH)"
str remove_history(int which)
"replace_history_entry(WHICH, LINE)"
str replace_history_entry(int which, str line)
"clear_history"
void clear_history()
"history_is_stifled"
int history_is_stifled()
Information About the History List
"where_history"
int where_history()
"current_history"
str current_history()
"history_get(OFFSET)"
str history_get(offset)
"history_get_time(OFFSET)"
time_t history_get_time(offset)
"history_total_bytes"
int history_total_bytes()
"GetHistory"
returns the history of input as a list, if actual "readline" is present.
Moving Around the History List
"history_set_pos(POS)"
int history_set_pos(int pos)
"previous_history"
str previous_history()
"next_history"
str next_history()
Searching the History List
"history_search(STRING [,DIRECTION])"
int history_search(str string, int direction = -1)
"history_search_prefix(STRING [,DIRECTION])"
int history_search_prefix(str string, int direction = -1)
"history_search_pos(STRING [,DIRECTION [,POS]])"
int history_search_pos(str string,
int direction = -1,
int pos = where_history())
Managing the History File
"ReadHistory([FILENAME [,FROM [,TO]]])"
int read_history(str filename = '~/.history',
int from = 0, int to = -1)
int read_history_range(str filename = '~/.history',
int from = 0, int to = -1)
adds the contents of "FILENAME" to the history list, a line at a time. If "FILENAME" is false, then read from ~/.history.
Start reading at line "FROM" and end at "TO". If "FROM" is omitted or zero, start at the beginning. If "TO" is omitted or
less than "FROM", then read until the end of the file. Returns true if successful, or false if not. "read_history()" is an
aliase of "read_history_range()".
"WriteHistory([FILENAME])"
int write_history(str filename = '~/.history')
writes the current history to "FILENAME", overwriting "FILENAME" if necessary. If "FILENAME" is false, then write the history
list to ~/.history. Returns true if successful, or false if not.
"append_history(NELEMENTS [,FILENAME])"
int append_history(int nelements, str filename = '~/.history')
"history_truncate_file([FILENAME [,NLINES]])"
int history_truncate_file(str filename = '~/.history',
int nlines = 0)
History Expansion
"history_expand(LINE)"
(int result, str expansion) history_expand(str line)
Note that this function returns "expansion" in scalar context.
"get_history_event(STRING, CINDEX [,QCHAR])"
(str text, int cindex) = get_history_event(str string,
int cindex,
char qchar = '