A small replacement for GNU readline() for UNIX
Go to file
Joachim Nilsson 256e288331 Update CHANGELOG and README slightly, bump version to 1.15.0-rc1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-04-06 15:24:34 +02:00
debian Bump version for release, v1.14.2 2014-09-14 04:27:38 +02:00
doc Minor cleanup before release. 2010-03-09 21:18:03 +01:00
examples Add support for disabling default SIGINT and EOF behavior. 2015-04-06 14:53:47 +02:00
include Add support for el_no_hist to disable access to and auto-save of history. 2014-11-04 22:47:55 +01:00
m4 Cleanup configure.ac and regenerate default configure files. 2013-07-08 16:47:03 +02:00
man editline.3: Update man page slightly and fix example formatting. 2015-02-01 14:58:17 +01:00
src Rename define CONFIG_ANNOYING_NOISE --> CONFIG_TERMINAL_BELL 2015-04-06 15:24:28 +02:00
.gitignore Update .gitignore 2010-07-18 02:50:09 +02:00
.travis.yml Add missing security token to Coverity Scan. 2014-09-17 05:57:41 +02:00
aclocal.m4 Cleanup configure.ac and regenerate default configure files. 2013-07-08 16:47:03 +02:00
CHANGELOG Rename NEWS --> CHANGELOG 2015-01-28 23:14:53 +01:00
CHANGELOG.md Update CHANGELOG and README slightly, bump version to 1.15.0-rc1 2015-04-06 15:24:34 +02:00
config.guess Cleanup configure.ac and regenerate default configure files. 2013-07-08 16:47:03 +02:00
config.h.in Rename define CONFIG_ANNOYING_NOISE --> CONFIG_TERMINAL_BELL 2015-04-06 15:24:28 +02:00
config.sub Cleanup configure.ac and regenerate default configure files. 2013-07-08 16:47:03 +02:00
configure Update CHANGELOG and README slightly, bump version to 1.15.0-rc1 2015-04-06 15:24:34 +02:00
configure.ac Update CHANGELOG and README slightly, bump version to 1.15.0-rc1 2015-04-06 15:24:34 +02:00
depcomp Add standard GNU configure and build system (autoconf+automake). 2008-06-07 21:03:48 +02:00
INSTALL Update build instructions with info on --prefix 2010-08-08 17:20:36 +02:00
install-sh Cleanup configure.ac and regenerate default configure files. 2013-07-08 16:47:03 +02:00
LICENSE New replacement LICENSE and README files. 2008-06-07 17:44:13 +02:00
ltmain.sh Cleanup configure.ac and regenerate default configure files. 2013-07-08 16:47:03 +02:00
Make.os9 Restore previously discarded (and incomplete) OS9 backend files. 2010-08-03 00:14:48 +02:00
Makefile.am Update to keepachangelog.com format and add to install+dist 2015-01-28 23:33:50 +01:00
Makefile.in Update to keepachangelog.com format and add to install+dist 2015-01-28 23:33:50 +01:00
missing Add standard GNU configure and build system (autoconf+automake). 2008-06-07 21:03:48 +02:00
README Create Markdown versions of README and NEWS and update for release 2014-09-14 04:24:18 +02:00
README.md Update CHANGELOG and README slightly, bump version to 1.15.0-rc1 2015-04-06 15:24:34 +02:00
TODO Rename TODO --> TODO.md and add compat symlink. 2015-02-03 21:25:31 +01:00
TODO.md Minor touch-up. 2015-02-03 21:34:15 +01:00

Editline

Travis Status Coverity Status

Table of Contents

Introduction

This is a small line editing library. It can be linked into almost any program to provide command line editing and history functions. It is call compatible with the FSF readline library, but at a fraction of the size, and as a result fewer features. It is also distributed under a much more liberal LICENSE.

The small size (<30k), lack of dependencies (no ncurses needed!), and the free license should make this library interesting to many embedded developers.

Editline has several optional build-time features that can be enabled by by supplying different options to the GNU configure script. See the output from configure --help for details. In the examples/ directory you can find some small code snippets used for testing.

Editline is maintained collaboratively at GitHub.

API

Here is the interface to editline. It has a small compatibility layer to FSF readline, which may not be entirely up-to-date.

    /* Editline specific global variables. */
    int         el_no_echo;   /* Do not echo input characters */
    int         el_no_hist;   /* Disable auto-save of and access to history,
                               * e.g. for password prompts or wizards */
    int         el_hist_size; /* Size of history scrollback buffer, default: 15 */
    
    /* 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);
    
    /* 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 */
    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;
    
    void rl_initialize(void);
    void rl_reset_terminal(const char *terminal_name);

    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);

Example

Here is a very brief example to illustrate how one can use Editline to create a simple CLI. More examples are availble in the source tree.

    #include <stdlib.h>

    extern char *readline(char *prompt);

    int main (void)
    {
        char *p;

        while ((p = readline("CLI> ")) != NULL) {
            puts(p);
            free(p);
        }

        return 0;
    }

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 GCC and GNU Make specific extensions here and there. This is not on purpose and patches/pull-requests to correct this are most welcome.

  • ./configure: Configure editline with default features
  • make all: Build the library and examples
  • make install: Honors $prefix and $DESTDIR environment variables, but see also ./configure --help

Origin & References

This line editing library was created by Simmule Turner and Rich Salz in in 1992. It is distributed under a “C News-like” license, similar to the BSD license. For details, see the file LICENSE.

This version of the editline library is forked from the Minix 3 source tree. Patches and bug fixes from the following forks, all based on the original comp.sources.unix posting, have been merged:

The version numbering scheme today follows that of the Debian version, which can be seen in the CHANGELOG.md. The Debian version was unknown to the current maintainer for quite some time, so a different name and different versioning scheme was used. In June 2009 this was changed to line up alongside Debian, the intent is to eventually merge the efforts.

Outstanding issues are listed in the TODO.md file.