2015-02-01 21:59:24 +08:00
|
|
|
Editline
|
|
|
|
========
|
|
|
|
[![Travis Status]][Travis] [![Coverity Status]][Coverity Scan]
|
2014-09-14 09:50:37 +08:00
|
|
|
|
2015-02-01 22:28:20 +08:00
|
|
|
|
|
|
|
Table of Contents
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
* [Introduction](#introduction)
|
|
|
|
* [API](#api)
|
|
|
|
* [Example](#example)
|
|
|
|
* [Build & Install](#build--install)
|
|
|
|
* [Origin & References](#origin--references)
|
|
|
|
|
|
|
|
|
2015-01-29 06:13:20 +08:00
|
|
|
Introduction
|
|
|
|
------------
|
2014-09-14 09:50:37 +08:00
|
|
|
|
2017-11-30 00:58:42 +08:00
|
|
|
This is a small [line editing][] library. It can be linked into almost
|
|
|
|
any program to provide command line editing and history functions. It
|
2017-12-27 20:14:39 +08:00
|
|
|
is call compatible with the [FSF readline][] library, but at a fraction
|
2017-11-30 00:58:42 +08:00
|
|
|
of the size, and as a result fewer features. It is also distributed
|
2015-09-10 17:07:14 +08:00
|
|
|
under a much more liberal [LICENSE][].
|
2014-09-14 09:50:37 +08:00
|
|
|
|
2017-11-30 00:58:42 +08:00
|
|
|
The small size (<30k), lack of dependencies (ncurses not needed!), and
|
|
|
|
the free license should make this library interesting to many embedded
|
2015-01-29 06:13:20 +08:00
|
|
|
developers.
|
2014-09-14 09:50:37 +08:00
|
|
|
|
2015-01-29 06:13:20 +08:00
|
|
|
Editline has several optional build-time features that can be enabled by
|
2017-11-30 00:58:42 +08:00
|
|
|
supplying different options to the GNU configure script. See the output
|
|
|
|
from <kbd>configure --help</kbd> for details. Some useful hints on how
|
|
|
|
to use the library is available in the `examples/` directory.
|
2014-09-14 09:50:37 +08:00
|
|
|
|
2015-09-10 17:07:14 +08:00
|
|
|
Editline is maintained collaboratively at [GitHub][].
|
2015-02-01 22:28:20 +08:00
|
|
|
|
2014-09-14 09:50:37 +08:00
|
|
|
|
2017-12-27 20:15:12 +08:00
|
|
|
Example
|
|
|
|
-------
|
|
|
|
|
|
|
|
Here is a very brief example to illustrate how one can use Editline to
|
|
|
|
create a simple CLI, use Ctrl-D to exit the program. More examples are
|
|
|
|
availble in the source tree.
|
|
|
|
|
|
|
|
1. Build and install the library, preferably using a [release tarball][]
|
|
|
|
The configure script defaults to a `/usr/local` prefix.
|
|
|
|
|
|
|
|
tar xf editline-1.15.3.tar.xz
|
|
|
|
cd editline-1.15.3/
|
|
|
|
./configure --prefix=/usr
|
|
|
|
make all
|
|
|
|
sudo make install
|
|
|
|
|
|
|
|
2. Place the below source code in a separate project directory,
|
|
|
|
e.g. `~/src/example.c`
|
|
|
|
|
|
|
|
```C
|
|
|
|
#include <stdlib.h>
|
2017-12-27 20:27:59 +08:00
|
|
|
#include <editline.h>
|
2017-12-27 20:15:12 +08:00
|
|
|
|
|
|
|
int main (void)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
while ((p = readline("CLI> ")) != NULL) {
|
|
|
|
puts(p);
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
3. Compile the example, either by hard-coding the paths to the include
|
|
|
|
file and the library:
|
|
|
|
|
|
|
|
cd ~/src/
|
|
|
|
make LDLIBS=-leditline example
|
|
|
|
|
|
|
|
In this example I use `make` and rely on its implicit (built-in) rules
|
|
|
|
to handle all the magic with `gcc`, but you may want to create your own
|
|
|
|
Makefile for the project. In particular if you don't change the default
|
|
|
|
prefix (above), because then you need to specify the search path for the
|
|
|
|
include file(s) and the library manually. A simple `~/src/Makefile`:
|
|
|
|
|
|
|
|
CFLAGS = -I/usr/local/include
|
|
|
|
LDFLAGS = -L/usr/local/lib
|
|
|
|
LDLIBS = -leditline
|
|
|
|
|
|
|
|
all: example
|
|
|
|
|
|
|
|
Then simply type `make` from your `~/src/` directory. You can also use
|
|
|
|
`pkg-config` for your `~/src/Makefile`:
|
|
|
|
|
|
|
|
CFLAGS = $(shell pkg-config --cflags libeditline)
|
|
|
|
LDFLAGS = $(shell pkg-config --libs-only-L libeditline)
|
|
|
|
LDLIBS = $(shell pkg-config --libs-only-l libeditline)
|
|
|
|
|
|
|
|
all: example
|
|
|
|
|
|
|
|
Then simply type <kbd>make</kbd>, like above. However, in most `.rpm`
|
|
|
|
based distributions `pkg-config` doesn't search in `/usr/local` anymore,
|
|
|
|
so you need to call make like this:
|
|
|
|
|
|
|
|
PKG_CONFIG_LIBDIR=/usr/local/lib/pkgconfig make
|
|
|
|
|
|
|
|
|
2015-01-29 06:13:20 +08:00
|
|
|
API
|
|
|
|
---
|
2014-09-14 09:50:37 +08:00
|
|
|
|
2017-12-27 20:14:39 +08:00
|
|
|
Here is the libeditline interfaces. It has a small compatibility layer
|
2015-09-10 17:07:14 +08:00
|
|
|
to [FSF readline][], which may not be entirely up-to-date.
|
2015-02-01 21:59:24 +08:00
|
|
|
|
|
|
|
```C
|
|
|
|
/* Editline specific global variables. */
|
2015-04-06 21:20:26 +08:00
|
|
|
int el_no_echo; /* Do not echo input characters */
|
2015-02-01 21:59:24 +08:00
|
|
|
int el_no_hist; /* Disable auto-save of and access to history,
|
|
|
|
* e.g. for password prompts or wizards */
|
2015-04-06 21:20:26 +08:00
|
|
|
int el_hist_size; /* Size of history scrollback buffer, default: 15 */
|
2015-02-01 21:59:24 +08:00
|
|
|
|
|
|
|
/* Editline specific functions. */
|
|
|
|
char * el_find_word(void);
|
|
|
|
void el_print_columns(int ac, char **av);
|
|
|
|
el_status_t el_ring_bell(void);
|
|
|
|
el_status_t el_del_char(void);
|
|
|
|
|
2015-04-06 21:20:26 +08:00
|
|
|
/* Callback function for key binding */
|
|
|
|
typedef el_status_t el_keymap_func_t(void);
|
|
|
|
|
|
|
|
/* Bind key to a callback, use CTL('f') to change Ctrl-F, for example */
|
2015-02-01 21:59:24 +08:00
|
|
|
el_status_t el_bind_key(int key, el_keymap_func_t function);
|
|
|
|
el_status_t el_bind_key_in_metamap(int key, el_keymap_func_t function);
|
|
|
|
|
|
|
|
/* For compatibility with FSF readline. */
|
|
|
|
int rl_point;
|
|
|
|
int rl_mark;
|
|
|
|
int rl_end;
|
|
|
|
int rl_inhibit_complete;
|
|
|
|
char *rl_line_buffer;
|
|
|
|
const char *rl_readline_name;
|
|
|
|
|
2017-11-30 14:45:38 +08:00
|
|
|
void (*rl_deprep_term_function)(void);
|
|
|
|
void rl_deprep_terminal(void);
|
2015-02-01 21:59:24 +08:00
|
|
|
void rl_reset_terminal(const char *terminal_name);
|
|
|
|
|
2017-11-30 14:45:38 +08:00
|
|
|
void rl_initialize(void);
|
|
|
|
void rl_uninitialize(void); /* Free all internal memory */
|
|
|
|
|
2015-02-01 21:59:24 +08:00
|
|
|
void rl_save_prompt(void);
|
|
|
|
void rl_restore_prompt(void);
|
|
|
|
void rl_set_prompt(const char *prompt);
|
|
|
|
|
|
|
|
void rl_clear_message(void);
|
|
|
|
void rl_forced_update_display(void);
|
|
|
|
|
|
|
|
/* Main function to use, saves history by default */
|
|
|
|
char *readline(const char *prompt);
|
|
|
|
|
|
|
|
/* Use to save a read line to history, when el_no_hist is set */
|
|
|
|
void add_history(const char *line);
|
|
|
|
|
|
|
|
/* Load and save editline history from/to a file. */
|
|
|
|
int read_history(const char *filename);
|
|
|
|
int write_history(const char *filename);
|
|
|
|
|
|
|
|
/* Magic completion API, see examples/cli.c for more info */
|
|
|
|
rl_complete_func_t *rl_set_complete_func(rl_complete_func_t *func);
|
|
|
|
rl_list_possib_func_t *rl_set_list_possib_func(rl_list_possib_func_t *func);
|
2017-12-11 15:55:12 +08:00
|
|
|
|
|
|
|
/* Alternate interface to plain readline(), for event loops */
|
|
|
|
void rl_callback_handler_install (const char *prompt, rl_vcpfunc_t *lhandler);
|
|
|
|
void rl_callback_read_char (void);
|
|
|
|
void rl_callback_handler_remove (void);
|
2015-02-01 21:59:24 +08:00
|
|
|
```
|
2014-09-14 09:50:37 +08:00
|
|
|
|
|
|
|
|
2015-02-01 22:28:20 +08:00
|
|
|
Build & Install
|
|
|
|
---------------
|
|
|
|
|
|
|
|
Editline was originally designed for older UNIX systems and Plan 9. The
|
|
|
|
current maintainer works exclusively on GNU/Linux systems, so it may use
|
2017-11-30 00:58:42 +08:00
|
|
|
GCC and GNU Make specific extensions here and there. This is not on
|
2015-09-10 17:07:14 +08:00
|
|
|
purpose and patches or pull requests to correct this are most welcome!
|
2015-02-01 22:28:20 +08:00
|
|
|
|
2015-09-10 17:07:14 +08:00
|
|
|
1. Configure editline with default features: <kbd>./configure</kbd>
|
|
|
|
2. Build the library and examples: <kbd>make all</kbd>
|
|
|
|
3. Install using <kbd>make install</kbd>
|
2015-02-01 22:28:20 +08:00
|
|
|
|
2017-11-30 00:58:42 +08:00
|
|
|
The `$DESTDIR` environment variable is honored at install. For more
|
|
|
|
options, see <kbd>./configure --help</kbd>
|
|
|
|
|
2017-12-27 20:15:12 +08:00
|
|
|
Remember to run `ldconfig` after install to update the linker cache. If
|
|
|
|
you've installed to a non-standard location (`--prefix`) you may also
|
|
|
|
have to update your `/etc/ld.so.conf`, or use `pkg-confg` to build your
|
|
|
|
application (above).
|
|
|
|
|
|
|
|
**NOTE:** RedHat/Fedora/CentOS and other `.rpm`-based distributions do
|
|
|
|
not consider `/usr/local` as standard path anymore. So make sure to
|
|
|
|
`./configure --prefix=/usr`, otherwise the build system use the GNU
|
|
|
|
default, which is `/usr/local`. The Debian based distributions, like
|
|
|
|
Ubuntu, do not have this problem.
|
|
|
|
|
2015-02-01 22:28:20 +08:00
|
|
|
|
2015-01-29 06:13:20 +08:00
|
|
|
Origin & References
|
|
|
|
--------------------
|
|
|
|
|
2017-11-30 00:58:42 +08:00
|
|
|
This [line editing][] library was created by [Rich Salz][] and Simmule
|
|
|
|
Turner and in 1992. It is distributed under a “C News-like” license,
|
|
|
|
similar to the [BSD license][]. Rich's latest version is however under
|
|
|
|
the Apache license. For details on the licensing terms of this version
|
|
|
|
of the software, see [LICENSE][].
|
|
|
|
|
|
|
|
This version of the editline library was forked from the [Minix 3][]
|
|
|
|
source tree and is *not* related to the similarily named NetBSD version
|
|
|
|
that [Jess Thrysøe][jess] disitributes to the world outside *BSD. The
|
|
|
|
libraries have much in common, but the latter is heavily refactored and
|
|
|
|
also relies on libtermcap (usually supplied by ncurses), whereas this
|
2016-05-31 20:42:10 +08:00
|
|
|
library only uses termios from the standard C library.
|
2015-10-22 07:02:25 +08:00
|
|
|
|
2017-11-30 00:58:42 +08:00
|
|
|
Patches and bug fixes from the following forks, based on the original
|
|
|
|
[comp.sources.unix][] posting, have been merged:
|
2015-01-29 06:13:20 +08:00
|
|
|
|
2015-09-10 17:07:14 +08:00
|
|
|
* Debian [libeditline][]
|
|
|
|
* [Heimdal][]
|
|
|
|
* [Festival][] speech-tools
|
|
|
|
* [Steve Tell][]'s editline patches
|
2015-01-29 06:13:20 +08:00
|
|
|
|
2017-11-30 00:58:42 +08:00
|
|
|
The version numbering scheme today follows that of the Debian version,
|
|
|
|
details available in the [ChangeLog.md][]. The current [maintainer][]
|
|
|
|
was unaware of the Debian version for quite some time, so a different
|
|
|
|
name and versioning scheme was used. In June 2009 this was changed to
|
|
|
|
line up alongside Debian, with the intent is to eventually merge the
|
|
|
|
efforts.
|
2015-02-01 21:59:24 +08:00
|
|
|
|
2015-09-10 17:07:14 +08:00
|
|
|
Outstanding issues are listed in the [TODO.md][] file.
|
2015-02-01 21:59:24 +08:00
|
|
|
|
2015-02-01 22:28:20 +08:00
|
|
|
[GitHub]: https://github.com/troglobit/editline
|
|
|
|
[line editing]: https://github.com/troglobit/editline/blob/master/doc/README
|
2017-12-27 20:15:12 +08:00
|
|
|
[release tarball]: https://github.com/troglobit/editline/releases
|
2015-02-01 21:59:24 +08:00
|
|
|
[maintainer]: http://troglobit.com
|
|
|
|
[LICENSE]: https://github.com/troglobit/editline/blob/master/LICENSE
|
2015-02-01 22:28:20 +08:00
|
|
|
[TODO.md]: https://github.com/troglobit/editline/blob/master/TODO.md
|
2015-09-10 17:09:37 +08:00
|
|
|
[ChangeLog.md]: https://github.com/troglobit/editline/blob/master/ChangeLog.md
|
2015-02-01 21:59:24 +08:00
|
|
|
[FSF readline]: http://www.gnu.org/software/readline/
|
2017-11-30 00:58:42 +08:00
|
|
|
[Rich Salz]: https://github.com/richsalz/editline/
|
|
|
|
[comp.sources.unix]: http://ftp.cs.toronto.edu/pub/white/pub/rc/editline.shar
|
2015-10-22 07:02:25 +08:00
|
|
|
[Minix 3]: http://www.cise.ufl.edu/~cop4600/cgi-bin/lxr/http/source.cgi/lib/editline/
|
|
|
|
[jess]: http://thrysoee.dk/editline/
|
2015-02-01 21:59:24 +08:00
|
|
|
[BSD license]: http://en.wikipedia.org/wiki/BSD_licenses
|
|
|
|
[libeditline]: http://packages.qa.debian.org/e/editline.html
|
|
|
|
[Heimdal]: http://www.h5l.org
|
|
|
|
[Festival]: http://festvox.org/festival/
|
|
|
|
[Steve Tell]: http://www.cs.unc.edu/~tell/dist.html
|
|
|
|
[Travis]: https://travis-ci.org/troglobit/editline
|
|
|
|
[Travis Status]: https://travis-ci.org/troglobit/editline.png?branch=master
|
|
|
|
[Coverity Scan]: https://scan.coverity.com/projects/2982
|
|
|
|
[Coverity Status]: https://scan.coverity.com/projects/2982/badge.svg
|