GNU Readline
Developer(s) | Brian Fox, Chet Ramey |
---|---|
Repository | |
Written in | C |
Operating system | Various |
Type | Library |
License | GNU General Public License |
Website | Official 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
External links
- GNU readline homepage
- The Tecla command-line editing library - readline replacement with an MIT-style licence
- Editline Library (libedit) - readline replacement with a BSD-style licence
- Haskeline - pure Haskell readline replacement with a BSD3 licence
- rlwrap - tools that provides readline functionality while running a command that does not already have it