Jump to content

GNU Readline

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 124.168.145.191 (talk) at 12:06, 2 September 2011 (→‎Criticism: Unsourced statements - citation needed). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

GNU readline
Developer(s)Brian Fox, Chet Ramey
Repository
Written inC
Operating systemVarious
TypeLibrary
LicenseGNU General Public License
WebsiteOfficial website

GNU readline is a software library that provides line-editing and history capabilities for interactive programs with a command-line interface, such as Bash. It allows users to move the text cursor, search the command history, control a kill ring (a more flexible version of a copy/paste clipboard) and use tab completion on a text terminal.

Readline key bindings are taken from the text editor Emacs, but can be customized. As a cross-platform library, readline allows applications on various systems to exhibit identical line-editing behavior.

Criticism

Many programs[citation needed] use readline as an optional feature, allowing the user to specify whether or not to link with the readline library at build time, because GNU readline is a large library with many dependencies[citation needed].

The readline library is licensed under the GNU General Public License (GPL) which is a software license that requires that any derivative work also be licensed with the GPL (see copyleft). This makes linking non-GPL software with readline problematic.[neutrality is disputed][citation needed] Other implementations exist for this reason, which often mimick the readline library API, such as the BSD-licensed libedit.

Sample code

The following code is in C :

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <readline/readline.h>
#include <readline/history.h>

int main()
{
    char* input, shell_prompt[100];

    for(;;)
    {
        // getting the current user 'n path
        snprintf(shell_prompt, sizeof(shell_prompt), "%s:%s $ ", getenv("USER"), getcwd(NULL, 1024));
        // inputing...
        input = readline(shell_prompt);
        // eof
        if (!input)
            break;
	// path autocompletion when tabulation hit
        rl_bind_key('\t', rl_complete);
        // adding the previous input into history
        add_history(input);

        /*do stuff*/
    }
}

References