Module rl_sys::readline
[−]
[src]
GNU Readline API
This chapter describes the interface between the GNU Readline Library and other programs. If you are a programmer, and you wish to include the features found in GNU Readline such as completion, line editing, and interactive history manipulation in your own programs, this section is for you.
Many programs provide a command line interface, such as mail, ftp, and sh. For such programs, the default behaviour of Readline is sufficient. This section describes how to use Readline in the simplest way possible, perhaps to replace calls in your code to gets() or fgets().
The function readline()
prints a prompt prompt
and then reads and returns a single line of
text from the user. If prompt is NULL or the empty string, no prompt is displayed. The line
readline returns is allocated with malloc(); the caller should free() the line when it has
finished with it. The declaration for readline in ANSI C is:
char *readline (const char *prompt);
So, one might say
char *line = readline ("Enter a line: ");
in order to read a line of text from the user. The line returned has the final newline removed, so only the text remains.
If readline encounters an EOF while reading the line, and the line is empty at that point, then
(char *)NULL
is returned. Otherwise, the line is ended just as if a newline had been
typed.
If you want the user to be able to get at the line later, (with C-p
for example), you must
call add_history()
to save the line away in a history list of such lines.
For full details on the GNU History Library, see the associated manual.
Modules
binding | |
charin | |
funmap | |
keymap | |
misc | |
modtext | |
naming | |
redisplay | |
termmgmt | |
undo | |
util | |
vars |
Structs
IOFile |
I/O File Type |
IOMarker |
I/O Marker |
KeymapEntry |
Keymap Entry |
ReadlineState |
Readline State |
UndoList |
Undo List |
Functions
callback_handler_install | |
callback_handler_remove |
Restore the terminal to its initial state and remove the line handler. This may be called from
within a callback as well as independently. If the |
callback_read_char |
Whenever an application determines that keyboard input is available, it should call
|
readline |
Wraps the libreadline readline function. The argument is the prompt to use. |
Type Definitions
CommandFunction |
Readline Command Function Type |
GetcFunction |
Readline getc Function Type |
HandlerFunction |
Readline Callback Handler |
HookFunction |
Readline Hook Function Type |
Keymap |
Keymap |
KeymapEntryArray |
Keymap Entry Array |
PrepFunction |
Readline prep Function Type |
VoidFunction |
Readline void Function Type |