GNU readline
GNU readline
|
|
---|---|
Basic data
|
|
Maintainer | Chet Ramey |
developer | Brian Fox, Chet Ramey |
Current version |
8.0 ( January 7, 2019 ) |
operating system | cross-platform |
programming language | C. |
License | GNU General Public License |
The GNU Readline Library |
GNU readline is a program library created and maintained by the GNU project with functions for editing lines. It is under the GPL and is used in projects such as bash . From version 6.1, readline also supports Unicode characters.
For example, supports readline a program that moved the pressure on Strg+ bthe cursor one character, Strg+ fmoves the cursor forward one character, Strg+ rscans the command buffer. These standard keyboard shortcuts are from one of the first GNU projects, the Emacs text editor . Readline supports a variety of simple functions, such as a so-called "kill ring" (a more flexible variant of a clipboard ) and command line completion . Since it is a cross-platform library, readline users allow the same line processing behavior on different operating systems.
Readline can be adapted using a configuration file that applies to the user ( ~/.inputrc
) or can be program-specific. In this file it is possible to define your own key combinations and to change various other settings.
Example 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(;;) {
// Configure readline to auto-complete paths when the tab key is hit.
rl_bind_key('\t', rl_complete);
// Create prompt string from user name and current working directory.
snprintf(shell_prompt, sizeof(shell_prompt), "%s:%s $ ", getenv("USER"), getcwd(NULL, 1024));
// Display prompt and read input (n.b. input must be freed after use)...
input = readline(shell_prompt);
// Check for EOF.
if (!input)
break;
// Add input to history.
add_history(input);
// Do stuff...
// Free input.
free(input);
}
}
Web links
- GNU readline homepage
- The Tecla command-line editing library - readline replacement with an MIT license
- Editline Library (libedit) - readline replacement with a BSD license
- rlwrap - tools that add readline functionality to running programs
Individual evidence
- ^ In: Free Software Directory .
- ↑ Chet Ramey: Readline-8.0 release available . January 7, 2019 (accessed June 18, 2020).