Loading AI tools
Software library From Wikipedia, the free encyclopedia
GNU Readline is a software library that provides in-line editing and history capabilities for interactive programs with a command-line interface, such as Bash. It is currently maintained by Chet Ramey as part of the GNU Project.
Original author(s) | Brian Fox |
---|---|
Developer(s) | Chet Ramey |
Initial release | 1989 |
Stable release | |
Preview release | |
Repository | |
Written in | C |
Type | Library |
License | 2009: GPL-3.0-or-later[a] 1997: GPL-2.0-or-later[b] 1994: GPL-1.0-or-later[c] |
Website | www |
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. As a cross-platform library, readline allows applications on various systems to exhibit identical line-editing behavior.
Readline supports both Emacs and vi editing modes, which determine how keyboard input is interpreted as editor commands. See Editor war § Comparison.
Emacs editing mode key bindings are taken from the text editor Emacs.
On some systems, Esc must be used instead of Alt, because the Alt shortcut conflicts with another shortcut. For example, pressing Alt+f in Xfce's terminal emulator window does not move the cursor forward one word, but activates "File" in the menu of the terminal window, unless that is disabled in the emulator's settings.
clear
).bg
. To bring it back from background or suspension fg ['process name or job id']
(foreground) can be issued.GNU Readline is notable for being a free software library which is licensed under the GNU General Public License (GPL). Free software libraries are far more often licensed under the GNU Lesser General Public License (LGPL), for example, the GNU C Library, GNU gettext and FLTK. A developer of an application who chooses to link to an LGPLv3 licensed library can use any license that does not: "restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications".[4] But linking to a GPLv3 licensed library such as Readline requires the entire combined resulting application to be licensed under the GPLv3 when distributed, to comply with section 5 of the GPL.[5][6]
This licensing was chosen by the FSF on the hopes that it would encourage software to switch to the GPL.[7] An important example of an application changing its licensing to comply with the copyleft conditions of GNU Readline is CLISP, an implementation of Common Lisp. Originally released in 1987, it changed to the GPL license in 1992,[8] after an email exchange between one of CLISP's original authors, Bruno Haible, and Richard Stallman, in which Stallman argued[9] that the linking of readline in CLISP meant that Haible was required to re-license CLISP under the GPL if he wished to distribute the implementation of CLISP which used readline.[10]
Another response has been to not use this in some projects, making text input use the primitive Unix terminal driver for editing.
Alternative libraries have been created with other licenses so they can be used by software projects which want to implement command line editing functionality, but be released with a non-GPL license.
The following code is in C and must be linked against the readline library by passing a -lreadline flag to the compiler:
#include <stdlib.h>
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
int main()
{
// Configure readline to auto-complete paths when the tab key is hit.
rl_bind_key('\t', rl_complete);
// Enable history
using_history();
while (1) {
// Display prompt and read input
char* input = readline("prompt> ");
// Check for EOF.
if (!input)
break;
// Add input to readline history.
add_history(input);
// Do stuff...
// Free buffer that was allocated by readline
free(input);
}
return 0;
}
Non-C programming languages that provide language bindings for readline include
readline
module;readline
module;[19]Term::ReadLine
module, specifically Term::ReadLine::Gnu
for GNU ReadLine.Support for readline alternatives differ among these bindings.
SIGINT
[3]Seamless Wikipedia browsing. On steroids.
Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.
Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.