Term::ReadLine::Gnu - Perl extension for the GNU Readline/History Library


Term-ReadLine-Gnu documentation Contained in the Term-ReadLine-Gnu distribution.

Index


Code Index:

NAME

Top

Term::ReadLine::Gnu - Perl extension for the GNU Readline/History Library

SYNOPSIS

Top

  use Term::ReadLine;
  $term = new Term::ReadLine 'ProgramName';
  while ( defined ($_ = $term->readline('prompt>')) ) {
    ...
  }

DESCRIPTION

Top

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"|"Standard Methods" and "Term::ReadLine::Gnu Functions"|"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"|"Term::ReadLine::Gnu Functions" and "Term::ReadLine::Gnu Variables"|"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)

free_keymap(MAP)
	void	rl_free_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

save_state(READLINE_STATE)
	NOT IMPLEMENTED YET!
	int	rl_save_state(struct readline_state *sp)	# GRL 6.0

restore_state(READLINE_STATE)
	NOT IMPLEMENTED YET!
	int	rl_restore_state(struct readline_state *sp)	# GRL 6.0

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)

	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

echo_signal_char
	void	rl_echo_signal_char(int sig)	# GRL 6.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 = '\0')

history_tokenize(LINE)
	(@str)	history_tokenize(str line)

history_arg_extract(LINE, [FIRST [,LAST]])
	str history_arg_extract(str line, int first = 0, int last = '$')

Term::ReadLine::Gnu Variables

Following GNU Readline/History Library variables can be accessed from Perl program. See 'GNU Readline Library Manual' and ' GNU History Library Manual' for each variable. You can access them with Attribs methods. Names of keys in this hash conform to standard conventions with the leading rl_ stripped.

Examples:

    $attribs = $term->Attribs;
    $v = $attribs->{library_version};	# rl_library_version
    $v = $attribs->{history_base};	# history_base

Readline Variables
	str rl_line_buffer
	int rl_point
	int rl_end
	int rl_mark
	int rl_done
	int rl_num_chars_to_read (GRL 4.2)
	int rl_pending_input
	int rl_dispatching (GRL 4.2)
	int rl_erase_empty_line (GRL 4.0)
	str rl_prompt (read only)
	str rl_display_prompt (GRL 6.0)
	int rl_already_prompted (GRL 4.1)
	str rl_library_version (read only)
	int rl_readline_version (read only)
	int rl_gnu_readline_p (GRL 4.2)
	str rl_terminal_name
	str rl_readline_name
	filehandle rl_instream
	filehandle rl_outstream
	int rl_prefer_env_winsize (GRL 5.1)
	pfunc rl_last_func (GRL 4.2)
	pfunc rl_startup_hook
	pfunc rl_pre_input_hook (GRL 4.0)
	pfunc rl_event_hook
	pfunc rl_getc_function
	pfunc rl_redisplay_function
	pfunc rl_prep_term_function (GRL 4.2)
	pfunc rl_deprep_term_function (GRL 4.2)
	Keymap rl_executing_keymap (read only)
	Keymap rl_binding_keymap (read only)
	str rl_executing_macro (GRL 4.2)
	int rl_readline_state (GRL 4.2)
	int rl_explicit_arg (GRL 4.2)
	int rl_numeric_arg (GRL 4.2)
	int rl_editing_mode (GRL 4.2)

Signal Handling Variables
	int rl_catch_signals (GRL 4.0)
	int rl_catch_sigwinch (GRL 4.0)

Completion Variables
	pfunc rl_completion_entry_function
	pfunc rl_attempted_completion_function
	pfunc rl_filename_quoting_function
	pfunc rl_filename_dequoting_function
	pfunc rl_char_is_quoted_p
	int rl_completion_query_items
	str rl_basic_word_break_characters
	str rl_basic_quote_characters
	str rl_completer_word_break_characters
	pfunc rl_completion_word_break_hook (GRL 5.0)
	str rl_completer_quote_characters
	str rl_filename_quote_characters
	str rl_special_prefixes
	int rl_completion_append_character
	int rl_completion_suppress_append (GRL 4.3)
	int rl_completion_quote_charactor (GRL 5.0)
	int rl_completion_suppress_quote (GRL 5.0)
	int rl_completion_found_quote (GRL 5.0)
	int rl_completion_mark_symlink_dirs (GRL 4.3)
	int rl_ignore_completion_duplicates
	int rl_filename_completion_desired
	int rl_filename_quoting_desired
	int rl_attempted_completion_over (GRL 4.2)
	int rl_sort_completion_matches (GRL 6.0)
	int rl_completion_type (GRL 4.2)
	int rl_completion_invoking_key (GRL 6.0)
	int rl_inhibit_completion
	pfunc rl_ignore_some_completion_function
	pfunc rl_directory_completion_hook
	pfunc rl_completion_display_matches_hook (GRL 4.0)

History Variables
	int history_base
	int history_length
	int history_max_entries (called `max_input_history'. read only)
	int history_write_timestamps (GRL 5.0)
	char history_expansion_char
	char history_subst_char
	char history_comment_char
	str history_word_delimiters (GRL 4.2)
	str history_no_expand_chars
	str history_search_delimiter_chars
	int history_quotes_inhibit_expansion
	pfunc history_inhibit_expansion_function

Function References
	rl_getc
	rl_redisplay
	rl_callback_read_char
	rl_display_match_list
	rl_filename_completion_function
	rl_username_completion_function
	list_completion_function
	shadow_redisplay
	Tk_getc

Custom Completion

In this section variables and functions for custom completion is described with examples.

Most of descriptions in this section is cited from GNU Readline Library manual.

rl_completion_entry_function

This variable holds reference refers to a generator function for completion_matches().

A generator function is called repeatedly from completion_matches(), returning a string each time. The arguments to the generator function are TEXT and STATE. TEXT is the partial word to be completed. STATE is zero the first time the function is called, allowing the generator to perform any necessary initialization, and a positive non-zero integer for each subsequent call. When the generator function returns undef this signals completion_matches() that there are no more possibilities left.

If the value is undef, built-in filename_completion_function is used.

A sample generator function, list_completion_function, is defined in Gnu.pm. You can use it as follows;

    use Term::ReadLine;
    ...
    my $term = new Term::ReadLine 'sample';
    my $attribs = $term->Attribs;
    ...
    $attribs->{completion_entry_function} =
	$attribs->{list_completion_function};
    ...
    $attribs->{completion_word} =
	[qw(reference to a list of words which you want to use for completion)];
    $term->readline("custom completion>");

See also completion_matches.

rl_attempted_completion_function

A reference to an alternative function to create matches.

The function is called with TEXT, LINE_BUFFER, START, and END. LINE_BUFFER is a current input buffer string. START and END are indices in LINE_BUFFER saying what the boundaries of TEXT are.

If this function exists and returns null list or undef, or if this variable is set to undef, then an internal function rl_complete() will call the value of $rl_completion_entry_function to generate matches, otherwise the array of strings returned will be used.

The default value of this variable is undef. You can use it as follows;

    use Term::ReadLine;
    ...
    my $term = new Term::ReadLine 'sample';
    my $attribs = $term->Attribs;
    ...
    sub sample_completion {
        my ($text, $line, $start, $end) = @_;
        # If first word then username completion, else filename completion
        if (substr($line, 0, $start) =~ /^\s*$/) {
    	    return $term->completion_matches($text,
					     $attribs->{'username_completion_function'});
        } else {
    	    return ();
        }
    }
    ...
    $attribs->{attempted_completion_function} = \&sample_completion;

completion_matches(TEXT, ENTRY_FUNC)

Returns an array of strings which is a list of completions for TEXT. If there are no completions, returns undef. The first entry in the returned array is the substitution for TEXT. The remaining entries are the possible completions.

ENTRY_FUNC is a generator function which has two arguments, and returns a string. The first argument is TEXT. The second is a state argument; it is zero on the first call, and non-zero on subsequent calls. ENTRY_FUNC returns a undef to the caller when there are no more matches.

If the value of ENTRY_FUNC is undef, built-in filename_completion_function is used.

completion_matches is a Perl wrapper function of an internal function completion_matches(). See also $rl_completion_entry_function.

completion_function

A variable whose content is a reference to a function which returns a list of candidates to complete.

This variable is compatible with Term::ReadLine::Perl and very easy to use.

    use Term::ReadLine;
    ...
    my $term = new Term::ReadLine 'sample';
    my $attribs = $term->Attribs;
    ...
    $attribs->{completion_function} = sub {
	my ($text, $line, $start) = @_;
	return qw(a list of candidates to complete);
    }

list_completion_function(TEXT, STATE)

A sample generator function defined by Term::ReadLine::Gnu. Example code at rl_completion_entry_function shows how to use this function.

Term::ReadLine::Gnu Specific Features

Term::ReadLine::Gnu Specific Functions

CallbackHandlerInstall(PROMPT, LHANDLER)

This method provides the function rl_callback_handler_install() with the following addtional feature compatible with readline method; ornament feature, Term::ReadLine::Perl compatible completion function, histroy expansion, and addition to history buffer.

call_function(FUNCTION, [COUNT [,KEY]])
	int	rl_call_function(FunctionPtr|str function, count = 1, key = -1)

rl_get_all_function_names

Returns a list of all function names.

shadow_redisplay

A redisplay function for password input. You can use it as follows;

	$attribs->{redisplay_function} = $attribs->{shadow_redisplay};
	$line = $term->readline("password> ");

rl_filename_list

Returns candidates of filename to complete. This function can be used with completion_function and is implemented for the compatibility with Term::ReadLine::Perl.

list_completion_function

See the description of section "Custom Completion"|"Custom Completion".

Term::ReadLine::Gnu Specific Variables

do_expand

When true, the history expansion is enabled. By default false.

completion_function

See the description of section "Custom Completion"|"Custom Completion".

completion_word

A reference to a list of candidates to complete for list_completion_function.

Term::ReadLine::Gnu Specific Commands

history-expand-line

The equivalent of the Bash history-expand-line editing command.

operate-and-get-next

The equivalent of the Korn shell operate-and-get-next-history-line editing command and the Bash operate-and-get-next.

This command is bound to \C-o by default for the compatibility with the Bash and Term::ReadLine::Perl.

display-readline-version

Shows the version of Term::ReadLine::Gnu and the one of the GNU Readline Library.

change-ornaments

Change ornaments interactively.

FILES

Top

~/.inputrc

Readline init file. Using this file it is possible that you would like to use a different set of key bindings. When a program which uses the Readline library starts up, the init file is read, and the key bindings are set.

Conditional key binding is also available. The program name which is specified by the first argument of new method is used as the application construct.

For example, when your program call new method like this;

	...
	$term = new Term::ReadLine 'PerlSh';
	...

your ~/.inputrc can define key bindings only for it as follows;

	...
	$if PerlSh
	Meta-Rubout: backward-kill-word
	"\C-x\C-r": re-read-init-file
        "\e[11~": "Function Key 1"
	$endif
	...

EXPORTS

Top

None.

SEE ALSO

Top

GNU Readline Library Manual
GNU History Library Manual
Term::ReadLine
Term::ReadLine::Perl (Term-ReadLine-Perl-xx.tar.gz)
eg/* and t/* in the Term::ReadLine::Gnu distribution

effective perl programming
	http://www.usenix.org/publications/login/2000-7/features/effective.html

This article demonstrates how to integrate Term::ReadLine::Gnu into an interactive command line program.

eijiro (Japanese)
	http://bulknews.net/lib/columns/02_eijiro/column.html

A command line interface to Eijiro, Japanese-English dictionary service on WWW.

Works which use Term::ReadLine::Gnu

Perl Debugger
	perl -d

The Perl Shell (psh)
	http://www.focusresearch.com/gregor/psh/

The Perl Shell is a shell that combines the interactive nature of a Unix shell with the power of Perl.

A programmable completion feature compatible with bash is implemented.

SPP (Synopsys Plus Perl)
	http://www.stanford.edu/~jsolomon/SPP/

SPP (Synopsys Plus Perl) is a Perl module that wraps around Synopsys' shell programs. SPP is inspired by the original dc_perl written by Steve Golson, but it's an entirely new implementation. Why is it called SPP and not dc_perl? Well, SPP was written to wrap around any of Synopsys' shells.

PFM (Personal File Manager for Unix/Linux)
	http://p-f-m.sourceforge.net/

Pfm is a terminal-based file manager written in Perl, based on PFM.COM for MS-DOS (originally by Paul Culley and Henk de Heer).

The soundgrab
	http://rawrec.sourceforge.net/soundgrab/soundgrab.html

soundgrab is designed to help you slice up a big long raw audio file (by default 44.1 kHz 2 channel signed sixteen bit little endian) and save your favorite sections to other files. It does this by providing you with a cassette player like command line interface.

PDL (The Perl Data Language)
	http://pdl.perl.org/index_en.html

PDL (``Perl Data Language'') gives standard Perl the ability to compactly store and speedily manipulate the large N-dimensional data arrays which are the bread and butter of scientific computing.

PIQT (Perl Interactive DBI Query Tool)
	http://piqt.sourceforge.net/

PIQT is an interactive query tool using the Perl DBI database interface. It supports ReadLine, provides a built in scripting language with a Lisp like syntax, an online help system, and uses wrappers to interface to the DBD modules.

Ghostscript Shell
	http://www.panix.com/~jdf/gshell/

It provides a friendly way to play with the Ghostscript interpreter, including command history and auto-completion of Postscript font names and reserved words.

vshnu (the New Visual Shell)
	http://www.cs.indiana.edu/~kinzler/vshnu/

A visual shell and CLI shell supplement.

If you know any other works which can be listed here, please let me know.

AUTHOR

Top

Hiroo Hayashi <hiroo.hayashi@computer.org>

http://www.perl.org/CPAN/authors/Hiroo_HAYASHI/

TODO

Top

GTK+ support in addition to Tk.

BUGS

Top

rl_add_defun() can define up to 16 functions.

Ornament feature works only on prompt strings. It requires very hard hacking of display.c:rl_redisplay() in GNU Readline library to ornament input line.

newTTY() is not tested yet.


Term-ReadLine-Gnu documentation Contained in the Term-ReadLine-Gnu distribution.
#
#	Gnu.pm --- The GNU Readline/History Library wrapper module
#
#	$Id: Gnu.pm,v 1.101 2010/05/02 10:39:19 hiroo Exp $
#
#	Copyright (c) 2009 Hiroo Hayashi.  All rights reserved.
#
#	This program is free software; you can redistribute it and/or
#	modify it under the same terms as Perl itself.
#
#	Some of documentation strings in this file are cited from the
#	GNU Readline/History Library Manual.

package Term::ReadLine::Gnu;

use strict;
use Carp;

# This module can't be loaded directly.
BEGIN {
    if (not defined $Term::ReadLine::VERSION) {
        croak <<END;
It is invalid to load Term::ReadLine::Gnu directly.  Please consult
the Term::ReadLine documentation for more information.
END
    }
}

{
    use Exporter ();
    use DynaLoader;
    use vars qw($VERSION @ISA @EXPORT_OK);

    $VERSION = '1.20';

    # Term::ReadLine::Gnu::AU makes a function in
    # `Term::ReadLine::Gnu::XS' as a method.
    # The namespace of Term::ReadLine::Gnu::AU is searched before ones
    # of other classes
    @ISA = qw(Term::ReadLine::Gnu::AU Term::ReadLine::Stub
	      Exporter DynaLoader);

    @EXPORT_OK = qw(RL_PROMPT_START_IGNORE RL_PROMPT_END_IGNORE
		    NO_MATCH SINGLE_MATCH MULT_MATCH
		    ISFUNC ISKMAP ISMACR
		    UNDO_DELETE UNDO_INSERT UNDO_BEGIN UNDO_END
		    RL_STATE_NONE RL_STATE_INITIALIZING
		    RL_STATE_INITIALIZED RL_STATE_TERMPREPPED
		    RL_STATE_READCMD RL_STATE_METANEXT
		    RL_STATE_DISPATCHING RL_STATE_MOREINPUT
		    RL_STATE_ISEARCH RL_STATE_NSEARCH
		    RL_STATE_SEARCH RL_STATE_NUMERICARG
		    RL_STATE_MACROINPUT RL_STATE_MACRODEF
		    RL_STATE_OVERWRITE RL_STATE_COMPLETING
		    RL_STATE_SIGHANDLER RL_STATE_UNDOING
		    RL_STATE_INPUTPENDING RL_STATE_TTYCSAVED
		    RL_STATE_CALLBACK RL_STATE_VIMOTION
		    RL_STATE_MULTIKEY RL_STATE_VICMDONCE
		    RL_STATE_DONE);

    bootstrap Term::ReadLine::Gnu $VERSION; # DynaLoader
}
require Term::ReadLine::Gnu::XS;

#	Global Variables

use vars qw(%Attribs %Features);

# Each variable in the GNU Readline Library is tied to an entry of
# this hash (%Attribs).  By accessing the hash entry, you can read
# and/or write the variable in the GNU Readline Library.  See the
# package definition of Term::ReadLine::Gnu::Var and following code
# for more details.

# Normal (non-tied) entries
%Attribs  = (
	     MinLength => 1,
	     do_expand => 0,
	     completion_word => [],
	     term_set => ['', '', '', ''],
	    );
%Features = (
	     appname => 1, minline => 1, autohistory => 1,
	     getHistory => 1, setHistory => 1, addHistory => 1,
	     readHistory => 1, writeHistory => 1,
	     preput => 1, attribs => 1, newTTY => 1,
	     tkRunning => Term::ReadLine::Stub->Features->{'tkRunning'},
	     ornaments => Term::ReadLine::Stub->Features->{'ornaments'},
	     stiflehistory => 1,
	    );

sub Attribs { \%Attribs; }
sub Features { \%Features; }

# keep rl_readline_version value for efficiency
my $readline_version;

#
#	GNU Readline/History Library constant definition
#	These are included in @EXPORT_OK.

# I can define these variables in XS code to use the value defined in
# readline.h, etc.  But it needs some calling convention change and
# will cause compatiblity problem. I hope the definition of these
# constant value will not be changed.

# for non-printing characters in prompt string
sub RL_PROMPT_START_IGNORE	{ "\001"; }
sub RL_PROMPT_END_IGNORE	{ "\002"; }

# for rl_filename_quoting_function
sub NO_MATCH	 { 0; }
sub SINGLE_MATCH { 1; }
sub MULT_MATCH   { 2; }

# for rl_generic_bind, rl_function_of_keyseq
sub ISFUNC	{ 0; }
sub ISKMAP	{ 1; }
sub ISMACR	{ 2; }

# for rl_add_undo
sub UNDO_DELETE	{ 0; }
sub UNDO_INSERT	{ 1; }
sub UNDO_BEGIN	{ 2; }
sub UNDO_END	{ 3; }

# for rl_readline_state
sub RL_STATE_NONE		{ 0x00000; } # no state; before first call
sub RL_STATE_INITIALIZING	{ 0x00001; } # initializing
sub RL_STATE_INITIALIZED	{ 0x00002; } # initialization done
sub RL_STATE_TERMPREPPED	{ 0x00004; } # terminal is prepped
sub RL_STATE_READCMD		{ 0x00008; } # reading a command key
sub RL_STATE_METANEXT		{ 0x00010; } # reading input after ESC
sub RL_STATE_DISPATCHING	{ 0x00020; } # dispatching to a command
sub RL_STATE_MOREINPUT		{ 0x00040; } # reading more input in a command function
sub RL_STATE_ISEARCH		{ 0x00080; } # doing incremental search
sub RL_STATE_NSEARCH		{ 0x00100; } # doing non-inc search
sub RL_STATE_SEARCH		{ 0x00200; } # doing a history search
sub RL_STATE_NUMERICARG		{ 0x00400; } # reading numeric argument
sub RL_STATE_MACROINPUT		{ 0x00800; } # getting input from a macro
sub RL_STATE_MACRODEF		{ 0x01000; } # defining keyboard macro
sub RL_STATE_OVERWRITE		{ 0x02000; } # overwrite mode
sub RL_STATE_COMPLETING		{ 0x04000; } # doing completion
sub RL_STATE_SIGHANDLER		{ 0x08000; } # in readline sighandler
sub RL_STATE_UNDOING		{ 0x10000; } # doing an undo
# The following RL_STATE_* are defined since TRL 6.0
sub RL_STATE_INPUTPENDING	{ 0x020000; } #	rl_execute_next called
sub RL_STATE_TTYCSAVED		{ 0x040000; } #	tty special chars saved
sub RL_STATE_CALLBACK		{ 0x080000; } #	using the callback interface
sub RL_STATE_VIMOTION		{ 0x100000; } #	reading vi motion arg
sub RL_STATE_MULTIKEY		{ 0x200000; } #	reading multiple-key command
sub RL_STATE_VICMDONCE		{ 0x400000; } #	entered vi command mode at least once
# The value was changed since TRL 6.0
sub RL_STATE_DONE		{ $readline_version < 0x0600 ? 0x80000 : 0x800000; } # done; accepted line

#
#	Methods Definition
#

sub ReadLine { 'Term::ReadLine::Gnu'; }

# The origin of this function is Term::ReadLine::Perl.pm by Ilya Zakharevich.
sub new {
    my $this = shift;		# Package
    my $class = ref($this) || $this;

    my $name = shift;

    my $self = \%Attribs;
    bless $self, $class;

    # set rl_readline_name before .inputrc is read in rl_initialize()
    $Attribs{readline_name} = $name;

    # some version of Perl cause segmentation fault, if XS module
    # calls setenv() before the 1st assignment to $ENV{}.
    $ENV{_TRL_DUMMY} = '';

    # initialize the GNU Readline Library and termcap library
    $self->initialize();

    # enable ornaments to be compatible with perl5.004_05(?)
    unless ($ENV{PERL_RL} and $ENV{PERL_RL} =~ /\bo\w*=0/) {
	local $^W = 0;		# Term::ReadLine is not warning flag free
	# Without the next line Term::ReadLine::Stub::ornaments is used.
	# Why does Term::ReadLine::Gnu::AU selects it at first?!!!
	# If you know why this happens, please let me know.  Thanks.
	undef &Term::ReadLine::Gnu::ornaments;
	$self->ornaments(1);
    }

    if (!@_) {
	my ($IN,$OUT) = $self->findConsole();
	open(IN,"<$IN")   || croak "Cannot open $IN for read";
	open(OUT,">$OUT") || croak "Cannot open $OUT for write";
	# borrowed from Term/ReadLine.pm
	my $sel = select(OUT);
	$| = 1;				# for DB::OUT
	select($sel);
	$Attribs{instream} = \*IN;
	$Attribs{outstream} = \*OUT;
    } else {
	$Attribs{instream} = shift;
	$Attribs{outstream} = shift;
    }
    $readline_version = $Attribs{readline_version};

    $self;
}

sub DESTROY {}

# to peacify -w
$Term::ReadLine::registered = $Term::ReadLine::registered;

sub readline {			# should be ReadLine
    my $self = shift;
    my ($prompt, $preput) = @_;

    # contributed fix for Perl debugger
    # make sure the outstream fd inside the readline library is
    # in sync (see http://bugs.debian.org/236018)
    $Attribs{outstream} = $Attribs{outstream};

    # ornament support (now prompt only)
    $prompt = ${$Attribs{term_set}}[0] . $prompt . ${$Attribs{term_set}}[1];

    # `completion_function' support for compatibility with
    # Term:ReadLine::Perl.  Prefer $completion_entry_function, since a
    # program which uses $completion_entry_function should know
    # Term::ReadLine::Gnu and have better completion function using
    # the variable.
    $Attribs{completion_entry_function} = $Attribs{_trp_completion_function}
	if (!defined $Attribs{completion_entry_function}
	    && defined $Attribs{completion_function});

    # TkRunning support
    if (not $Term::ReadLine::registered and $Term::ReadLine::toloop
	and defined &Tk::DoOneEvent) {
	$self->register_Tk;
	$Attribs{getc_function} = $Attribs{Tk_getc};
    }

    # call readline()
    my $line;
    if (defined $preput) {
	my $saved_startup_hook = $Attribs{startup_hook};
	$Attribs{startup_hook} = sub {
	    $self->rl_insert_text($preput);
	    &$saved_startup_hook
		if defined $saved_startup_hook;
	};
	$line = $self->rl_readline($prompt);
	$Attribs{startup_hook} = $saved_startup_hook;
    } else {
	$line = $self->rl_readline($prompt);
    }
    return undef unless defined $line;

    # history expansion
    if ($Attribs{do_expand}) {
	my $result;
	($result, $line) = $self->history_expand($line);
	my $outstream = $Attribs{outstream};
	print $outstream "$line\n" if ($result);

	# return without adding line into history
	if ($result < 0 || $result == 2) {
	    return '';		# don't return `undef' which means EOF.
	}
    }

    # add to history buffer
    $self->add_history($line)
	if (defined $self->{MinLength} && $self->{MinLength} > 0
	    && length($line) >= $self->{MinLength});

    return $line;
}

use vars '*addhistory';
*addhistory = \&AddHistory;	# for backward compatibility

sub AddHistory {
    my $self = shift;
    foreach (@_) {
	$self->add_history($_);
    }
}

sub IN  { $Attribs{instream}; }
sub OUT { $Attribs{outstream}; }

sub MinLine {
    my $self = shift;
    my $old_minlength = $self->{MinLength};
    $self->{MinLength} = shift;
    $old_minlength;
}

# findConsole is defined in ReadLine.pm.

# Not tested yet.  How do I use this?
sub newTTY {
    my ($self, $in, $out) = @_;
    $Attribs{instream}  = $in;
    $Attribs{outstream} = $out;
    my $sel = select($out);
    $| = 1;			# for DB::OUT
    select($sel);
}

# documented later
sub CallbackHandlerInstall {
    my $self = shift;
    my ($prompt, $lhandler) = @_;

    $Attribs{_callback_handler} = $lhandler;

    # ornament support (now prompt only)
    $prompt = ${$Attribs{term_set}}[0] . $prompt . ${$Attribs{term_set}}[1];

    $Attribs{completion_entry_function} = $Attribs{_trp_completion_function}
	if (!defined $Attribs{completion_entry_function}
	    && defined $Attribs{completion_function});

    $self->rl_callback_handler_install($prompt,
				       \&Term::ReadLine::Gnu::XS::_ch_wrapper);
}


#
#	Additional Supported Methods
#

# Documentation is after '__END__' for efficiency.

# for backward compatibility
use vars qw(*AddDefun *BindKey *UnbindKey *ParseAndBind *StifleHistory);
*AddDefun = \&add_defun;
*BindKey = \&bind_key;
*UnbindKey = \&unbind_key;
*ParseAndBind = \&parse_and_bind;
*StifleHistory = \&stifle_history;

sub SetHistory {
    my $self = shift;
    $self->clear_history();
    $self->AddHistory(@_);
}

sub GetHistory {
    my $self = shift;
    $self->history_list();
}

sub ReadHistory {
    my $self = shift;
    ! $self->read_history_range(@_);
}

sub WriteHistory {
    my $self = shift;
    ! $self->write_history(@_);
}

#
#	Access Routines for GNU Readline/History Library Variables
#
package Term::ReadLine::Gnu::Var;
use Carp;
use strict;
use vars qw(%_rl_vars);

%_rl_vars
    = (
       rl_line_buffer				=> ['S', 0],
       rl_prompt				=> ['S', 1],
       rl_library_version			=> ['S', 2],
       rl_terminal_name				=> ['S', 3],
       rl_readline_name				=> ['S', 4],
       rl_basic_word_break_characters		=> ['S', 5],
       rl_basic_quote_characters		=> ['S', 6],
       rl_completer_word_break_characters	=> ['S', 7],
       rl_completer_quote_characters		=> ['S', 8],
       rl_filename_quote_characters		=> ['S', 9],
       rl_special_prefixes			=> ['S', 10],
       history_no_expand_chars			=> ['S', 11],
       history_search_delimiter_chars		=> ['S', 12],
       rl_executing_macro			=> ['S', 13], # GRL4.2
       history_word_delimiters			=> ['S', 14], # GRL4.2
       rl_display_prompt			=> ['S', 15], # GRL6.0

       rl_point					=> ['I', 0],
       rl_end					=> ['I', 1],
       rl_mark					=> ['I', 2],
       rl_done					=> ['I', 3],
       rl_pending_input				=> ['I', 4],
       rl_completion_query_items		=> ['I', 5],
       rl_completion_append_character		=> ['C', 6],
       rl_ignore_completion_duplicates		=> ['I', 7],
       rl_filename_completion_desired		=> ['I', 8],
       rl_filename_quoting_desired		=> ['I', 9],
       rl_inhibit_completion			=> ['I', 10],
       history_base				=> ['I', 11],
       history_length				=> ['I', 12],
       history_max_entries			=> ['I', 13],
       max_input_history			=> ['I', 13], # before GRL 4.2
       history_write_timestamps			=> ['I', 14], # GRL 5.0
       history_expansion_char			=> ['C', 15],
       history_subst_char			=> ['C', 16],
       history_comment_char			=> ['C', 17],
       history_quotes_inhibit_expansion		=> ['I', 18],
       rl_erase_empty_line			=> ['I', 19], # GRL 4.0
       rl_catch_signals				=> ['I', 20], # GRL 4.0
       rl_catch_sigwinch			=> ['I', 21], # GRL 4.0
       rl_already_prompted			=> ['I', 22], # GRL 4.1
       rl_num_chars_to_read			=> ['I', 23], # GRL 4.2
       rl_dispatching				=> ['I', 24], # GRL 4.2
       rl_gnu_readline_p			=> ['I', 25], # GRL 4.2
       rl_readline_state			=> ['I', 26], # GRL 4.2
       rl_explicit_arg				=> ['I', 27], # GRL 4.2
       rl_numeric_arg				=> ['I', 28], # GRL 4.2
       rl_editing_mode				=> ['I', 29], # GRL 4.2
       rl_attempted_completion_over		=> ['I', 30], # GRL 4.2
       rl_completion_type			=> ['I', 31], # GRL 4.2
       rl_readline_version			=> ['I', 32], # GRL 4.2a
       rl_completion_suppress_append		=> ['I', 33], # GRL 4.3
       rl_completion_quote_character		=> ['C', 34], # GRL 5.0
       rl_completion_suppress_quote		=> ['I', 35], # GRL 5.0
       rl_completion_found_quote		=> ['I', 36], # GRL 5.0
       rl_completion_mark_symlink_dirs		=> ['I', 37], # GRL 4.3
       rl_prefer_env_winsize			=> ['I', 38], # GRL 5.1
       rl_sort_completion_matches		=> ['I', 39], # GRL 6.0
       rl_completion_invoking_key		=> ['C', 40], # GRL 6.0

       rl_startup_hook				=> ['F', 0],
       rl_event_hook				=> ['F', 1],
       rl_getc_function				=> ['F', 2],
       rl_redisplay_function			=> ['F', 3],
       rl_completion_entry_function		=> ['F', 4],
       rl_attempted_completion_function		=> ['F', 5],
       rl_filename_quoting_function		=> ['F', 6],
       rl_filename_dequoting_function		=> ['F', 7],
       rl_char_is_quoted_p			=> ['F', 8],
       rl_ignore_some_completions_function	=> ['F', 9],
       rl_directory_completion_hook		=> ['F', 10],
       history_inhibit_expansion_function	=> ['F', 11],
       rl_pre_input_hook			=> ['F', 12], # GRL 4.0
       rl_completion_display_matches_hook	=> ['F', 13], # GRL 4.0
       rl_completion_word_break_hook		=> ['F', 14], # GRL 5.0
       rl_prep_term_function			=> ['F', 15], # GRL 4.2
       rl_deprep_term_function			=> ['F', 16], # GRL 4.2

       rl_instream				=> ['IO', 0],
       rl_outstream				=> ['IO', 1],

       rl_executing_keymap			=> ['K', 0],
       rl_binding_keymap			=> ['K', 1],

       rl_last_func                             => ['LF', 0],
      );

sub TIESCALAR {
    my $class = shift;
    my $name = shift;
    return bless \$name, $class;
}

sub FETCH {
    my $self = shift;
    confess "wrong type" unless ref $self;

    my $name = $$self;
    if (! defined $_rl_vars{$name}) {
	confess "Term::ReadLine::Gnu::Var::FETCH: Unknown variable name `$name'\n";
	return undef ;
    }

    my ($type, $id) = @{$_rl_vars{$name}};
    if ($type eq 'S') {
	return _rl_fetch_str($id);
    } elsif ($type eq 'I') {
	return _rl_fetch_int($id);
    } elsif ($type eq 'C') {
	return chr(_rl_fetch_int($id));
    } elsif ($type eq 'F') {
	return _rl_fetch_function($id);
    } elsif ($type eq 'IO') {
	return _rl_fetch_iostream($id);
    } elsif ($type eq 'K') {
	return _rl_fetch_keymap($id);
    } elsif ($type eq 'LF') {
        return _rl_fetch_last_func();
    } else {
	carp "Term::ReadLine::Gnu::Var::FETCH: Illegal type `$type'\n";
	return undef;
    }
}

sub STORE {
    my $self = shift;
    confess "wrong type" unless ref $self;

    my $name = $$self;
    if (! defined $_rl_vars{$name}) {
	confess "Term::ReadLine::Gnu::Var::STORE: Unknown variable name `$name'\n";
	return undef ;
    }

    my $value = shift;
    my ($type, $id) = @{$_rl_vars{$name}};
    if ($type eq 'S') {
	if ($name eq 'rl_line_buffer') {
	    return _rl_store_rl_line_buffer($value);
	} else {
	    return _rl_store_str($value, $id);
	}
    } elsif ($type eq 'I') {
	return _rl_store_int($value, $id);
    } elsif ($type eq 'C') {
	return chr(_rl_store_int(ord($value), $id));
    } elsif ($type eq 'F') {
	return _rl_store_function($value, $id);
    } elsif ($type eq 'IO') {
	return _rl_store_iostream($value, $id);
    } elsif ($type eq 'K' || $type eq 'LF') {
	carp "Term::ReadLine::Gnu::Var::STORE: read only variable `$name'\n";
	return undef;
    } else {
	carp "Term::ReadLine::Gnu::Var::STORE: Illegal type `$type'\n";
	return undef;
    }
}

package Term::ReadLine::Gnu;
use Carp;
use strict;

#
#	set value of %Attribs
#

#	Tie all Readline/History variables
foreach (keys %Term::ReadLine::Gnu::Var::_rl_vars) {
    my $name;
    ($name = $_) =~ s/^rl_//;	# strip leading `rl_'
    tie $Attribs{$name},  'Term::ReadLine::Gnu::Var', $_;
}

#	add reference to some functions
{
    my ($name, $fname);
    no strict 'refs';		# allow symbolic reference
    map {
	($name = $_) =~ s/^rl_//; # strip leading `rl_'
	$fname = 'Term::ReadLine::Gnu::XS::' . $_;
	$Attribs{$name} = \&$fname; # symbolic reference
    } qw(rl_getc
	 rl_redisplay
	 rl_callback_read_char
	 rl_display_match_list
	 rl_filename_completion_function
	 rl_username_completion_function
	 list_completion_function
         _trp_completion_function);
    # auto-split subroutine cannot be processed in the map loop above
    use strict 'refs';
    $Attribs{shadow_redisplay} = \&Term::ReadLine::Gnu::XS::shadow_redisplay;
    $Attribs{Tk_getc} = \&Term::ReadLine::Gnu::XS::Tk_getc;
    $Attribs{list_completion_function} = \&Term::ReadLine::Gnu::XS::list_completion_function;
}

package Term::ReadLine::Gnu::AU;
use Carp;
no strict qw(refs vars);

sub AUTOLOAD {
    { $AUTOLOAD =~ s/.*:://; }	# preserve match data
    my $name;
    if (exists $Term::ReadLine::Gnu::XS::{"rl_$AUTOLOAD"}) {
	$name = "Term::ReadLine::Gnu::XS::rl_$AUTOLOAD";
    } elsif (exists $Term::ReadLine::Gnu::XS::{"$AUTOLOAD"}) {
	$name = "Term::ReadLine::Gnu::XS::$AUTOLOAD";
    } else {
	croak "Cannot do `$AUTOLOAD' in Term::ReadLine::Gnu";
    }
    local $^W = 0;		# Why is this line necessary ?
    *$AUTOLOAD = sub { shift; &$name(@_); };
    goto &$AUTOLOAD;
}
1;
__END__