EDITLINE(3) BSD Library Functions Manual EDITLINE(3)
NAME
editline, elinit, elend, elreset, elgets, elgetc, elpush, elparse,
elset, elsource, elresize, elline, elinsertstr, eldeletestr,
historyinit, historyend, history -- line editor and history functions
LIBRARY
Command Line Editor Library (libedit, -ledit)
SYNOPSIS
##include <>
EditLine *
elinit(const char *prog, FILE *fin, FILE *fout, FILE *ferr);
void
elend(EditLine *e);
void
elreset(EditLine *e);
const char *
elgets(EditLine *e, int *count);
int
elgetc(EditLine *e, char *ch);
void
elpush(EditLine *e, const char *str);
int
elparse(EditLine *e, int argc, const char *argv[]);
int
elset(EditLine *e, int op, ...);
int
elget(EditLine *e, int op, void *result);
int
elsource(EditLine *e, const char *file);
void
elresize(EditLine *e);
const LineInfo *
elline(EditLine *e);
int
elinsertstr(EditLine *e, const char *str);
void
eldeletestr(EditLine *e, int count);
History *
historyinit();
void
historyend(History *h);
int
history(History *h, HistEvent *ev, int op, ...);
DESCRIPTION
The editline library provides generic line editing and history functions,
similar to those found in sh(1).
These functions are available in the libedit library (which needs the
libtermcap library). Programs should be linked with -ledit -ltermcap.
LINE EDITING FUNCTIONS
The line editing functions use a common data structure, EditLine, which
is created by elinit() and freed by elend().
The following functions are available:
elinit()
Initialise the line editor, and return a data structure to be used
by all other line editing functions. prog is the name of the
invoking program, used when reading the editrc(5) file to determine
which settings to use. fin, fout and ferr are the input, output,
and error streams (respectively) to use. In this documentation,
references to ``the tty'' are actually to this input/output stream
combination.
elend()
Clean up and finish with e, assumed to have been created with
elinit().
elreset()
Reset the tty and the parser. This should be called after an error
which may have upset the tty's state.
elgets()
Read a line from the tty. count is modified to contain the number
of characters read. Returns the line read if successful, or NUL
if no characters were read or if an error occurred.
elgetc()
Read a character from the tty. ch is modified to contain the char-
acter read. Returns the number of characters read if successful,
-1 otherwise.
elpush()
Pushes str back onto the input stream. This is used by the macro
expansion mechanism. Refer to the description of bind -s in
editrc(5) for more information.
elparse()
Parses the argv array (which is argc elements in size) to execute
builtin editline commands. If the command is prefixed with
``prog'': then elparse() will only execute the command if ``prog''
matches the prog argument supplied to elinit(). The return value
is -1 if the command is unknown, 0 if there was no error or
``prog'' didn't match, or 1 if the command returned an error.
Refer to editrc(5) for more information.
elset()
Set editline parameters. op determines which parameter to set, and
each operation has its own parameter list.
The following values for op are supported, along with the required
argument list:
ELPROMPT, char *(*f)(EditLine *)
Define prompt printing function as f, which is to return a
string that contains the prompt.
ELRPROMPT, char *(*f)(EditLine *)
Define right side prompt printing function as f, which is to
return a string that contains the prompt.
ELTERMINAL, const char *type
Define terminal type of the tty to be type, or to TERM if
type is NUL.
ELEDITOR, const char *mode
Set editing mode to mode, which must be one of ``emacs'' or
``vi''.
ELSIGNAL, int flag
If flag is non-zero, editline will install its own signal
handler for the following signals when reading command input:
SIGCONT, SIGHUP, SIGINT, SIGQUIT, SIGSTOP, SIGTERM, SIGTSTP,
and SIGWINCH. Otherwise, the current signal handlers will be
used.
ELBIND, const char *, ..., NUL
Perform the bind builtin command. Refer to editrc(5) for
more information.
ELECHOTC, const char *, ..., NUL
Perform the echotc builtin command. Refer to editrc(5) for
more information.
ELSETC, const char *, ..., NUL
Perform the settc builtin command. Refer to editrc(5) for
more information.
ELSETY, const char *, ..., NUL
Perform the setty builtin command. Refer to editrc(5) for
more information.
ELTELTC, const char *, ..., NUL
Perform the telltc builtin command. Refer to editrc(5) for
more information.
ELADFN, const char *name, const char *help, unsigned char
(*func)(EditLine *e, int ch)
Add a user defined function, func(), referred to as name
which is invoked when a key which is bound to name is
entered. help is a description of name. At invocation time,
ch is the key which caused the invocation. The return value
of func() should be one of:
CNORM Add a normal character.
CNEWLINE End of line was entered.
CEOF EOF was entered.
CARGHACK Expecting further command input as arguments,
do nothing visually.
CREFRESH Refresh display.
CREFRESHBEP
Refresh display, and beep.
CURSOR Cursor moved, so update and perform CREFRESH.
CREDISPLAY Redisplay entire input line. This is useful if
a key binding outputs extra information.
CEROR An error occurred. Beep, and flush tty.
CFATAL Fatal error, reset tty to known state.
ELHIST, History *(*func)(History *, int op, ...), const char *ptr
Defines which history function to use, which is usually
history(). ptr should be the value returned by
historyinit().
ELEDITMODE, int flag
If flag is non-zero, editing is enabled (the default). Note
that this is only an indication, and does not affect the
operation of editline. At this time, it is the caller's
responsibility to check this (using elget()) to determine if
editing should be enabled or not.
ELGETCFN, int (*f)(EditLine *, char *c)
Define the character reading function as f, which is to
return the number of characters read and store them in c.
This function is called internally by elgets() and
elgetc(). The builtin function can be set or restored with
the special function name ``ELBUILTINGETCFN''.
ELCLIENTDATA, void *data
Register data to be associated with this EditLine structure.
It can be retrieved with the corresponding elget() call.
elget()
Get editline parameters. op determines which parameter to retrieve
into result. Returns 0 if successful, -1 otherwise.
The following values for op are supported, along with actual type
of result:
ELPROMPT, char *(*f)(EditLine *)
Return a pointer to the function that displays the prompt.
ELRPROMPT, char *(*f)(EditLine *)
Return a pointer to the function that displays the rightside
prompt.
ELEDITOR, const char *
Return the name of the editor, which will be one of ``emacs''
or ``vi''.
ELSIGNAL, int *
Return non-zero if editline has installed private signal han-
dlers (see elget() above).
ELEDITMODE, int *
Return non-zero if editing is enabled.
ELGETCFN, int (**f)(EditLine *, char *)
Return a pointer to the function that read characters, which
is equal to ``ELBUILTINGETCFN'' in the case of the default
builtin function.
ELCLIENTDATA, void **data
Retrieve data previously registered with the corresponding
elset() call.
ELUNBUFERED, int
Sets or clears unbuffered mode. In this mode, elgets() will
return immediately after processing a single character.
ELPREPTERM, int
Sets or clears terminal editing mode.
elsource()
Initialise editline by reading the contents of file. elparse() is
called for each line in file. If file is NUL, try $PWD/.editrc
then $HOME/.editrc. Refer to editrc(5) for details on the format
of file.
elresize()
Must be called if the terminal size changes. If ELSIGNAL has been
set with elset(), then this is done automatically. Otherwise,
it's the responsibility of the application to call elresize() on
the appropriate occasions.
elline()
Return the editing information for the current line in a LineInfo
structure, which is defined as follows:
typedef struct lineinfo {
const char *buffer; /* address of buffer */
const char *cursor; /* address of cursor */
const char *lastchar; /* address of last character */
} LineInfo;
elinsertstr()
Insert str into the line at the cursor. Returns -1 if str is empty
or won't fit, and 0 otherwise.
eldeletestr()
Delete num characters before the cursor.
HISTORY LIST FUNCTIONS
The history functions use a common data structure, History, which is cre-
ated by historyinit() and freed by historyend().
The following functions are available:
historyinit()
Initialise the history list, and return a data structure to be used
by all other history list functions.
historyend()
Clean up and finish with h, assumed to have been created with
historyinit().
history()
Perform operation op on the history list, with optional arguments
as needed by the operation. ev is changed accordingly to opera-
tion. The following values for op are supported, along with the
required argument list:
HSETSIZE, int size
Set size of history to size elements.
HGETSIZE
Get number of events currently in history.
HEND
Cleans up and finishes with h, assumed to be created with
historyinit().
HCLEAR
Clear the history.
HFUNC, void *ptr, historygfunt first, historygfunt next,
historygfunt last, historygfunt prev, historygfunt
curr, historysfunt set, historyvfunt clear,
historyefunt enter, historyefunt add
Define functions to perform various history operations. ptr
is the argument given to a function when it's invoked.
HFIRST
Return the first element in the history.
HLAST
Return the last element in the history.
HPREV
Return the previous element in the history.
HNEXT
Return the next element in the history.
HCUR
Return the current element in the history.
HSET
Set the cursor to point to the requested element.
HAD, const char *str
Append str to the current element of the history, or perform
the HENTER operation wth argument str if there is no current
element.
HAPEND, const char *str
Append str to the last new element of the history.
HENTER, const char *str
Add str as a new element to the history, and, if necessary,
removing the oldest entry to keep the list to the created
size. If HSETUNIQUE was has been called with a non-zero
arguments, the element will not be entered into the history
if its contents match the ones of the current history ele-
ment. If the element is entered history() returns 1, if it
is ignored as a duplicate returns 0. Finally history()
returns -1 if an error occurred.
HPREVSTR, const char *str
Return the closest previous event that starts with str.
HNEXTSTR, const char *str
Return the closest next event that starts with str.
HPREVEVENT, int e
Return the previous event numbered e.
HNEXTEVENT, int e
Return the next event numbered e.
HLOAD, const char *file
Load the history list stored in file.
HSAVE, const char *file
Save the history list to file.
HSETUNIQUE, int unique
Set if the adjacent identical event strings should not be
entered into the history.
HGETUNIQUE
Retrieve the current setting if if adjacent elements should
be entered into the history.
history() returns >= 0 if the operation succeeds op succeeds. Oth-
erwise, -1 is returned and ev is updated to contain more details
about the error.
SEE ALSO
sh(1), signal(3), termcap(3), editrc(5)
HISTORY
The editline library first appeared in 4.4BSD. CREDISPLAY appeared in
NetBSD 1.3. CREFRESHBEP, ELEDITMODE and the readline emulation
appeared in NetBSD 1.4. ELRPROMPT appeared in NetBSD 1.5.
AUTHORS
The editline library was written by Christos Zoulas. Luke Mewburn wrote
this manual and implemented CREDISPLAY, CREFRESHBEP, ELEDITMODE,
and ELRPROMPT. Jaromir Dolecek implemented the readline emulation.
BUGS
The tokenization functions are not publicly defined in .
At this time, it is the responsibility of the caller to check the result
of the ELEDITMODE operation of elget() (after an elsource() or
elparse()) to determine if editline should be used for further input.
I.e., ELEDITMODE is purely an indication of the result of the most
recent editrc(5) edit command.
BSD October 17, 2003 BSD
|