Difference between revisions of "Applications/Readline"

From HPC
Jump to: navigation , search
m (Pysdlb moved page Readline to Applications/Readline without leaving a redirect)
Line 3: Line 3:
 
*Description: Readline is a software library that provides line-editing and history capabilities for interactive programs with a command-line interface, such as Bash.
 
*Description: Readline is a software library that provides line-editing and history capabilities for interactive programs with a command-line interface, such as Bash.
 
*Version: readline
 
*Version: readline
*Module: readline/6.3
+
*Module: readline/6.3 and readline/7.0
 
*Licence: GNU
 
*Licence: GNU
  
Line 10: Line 10:
 
===Module===
 
===Module===
 
<pre style="background-color: #000000; color: white; border: 2px solid black; font-family: monospace, sans-serif;">
 
<pre style="background-color: #000000; color: white; border: 2px solid black; font-family: monospace, sans-serif;">
[username@login01 ~]$ module add readline/6.3
+
[username@login01 ~]$ module add readline/7.0
 
</pre>
 
</pre>
  
Line 66: Line 66:
  
 
[http://www.boost.org/ http://www.boost.org/]
 
[http://www.boost.org/ http://www.boost.org/]
 +
 +
==Navigation==
 +
 +
* [[Main_Page|Home]]
 +
* [[Applications|Application support]] *
 +
* [[General|General]]
 +
* [[Programming|Programming support]]

Revision as of 13:40, 24 May 2019

Application Details

  • Description: Readline is a software library that provides line-editing and history capabilities for interactive programs with a command-line interface, such as Bash.
  • Version: readline
  • Module: readline/6.3 and readline/7.0
  • Licence: GNU

Usage Examples

Module

[username@login01 ~]$ module add readline/7.0

Compilation

readline is a library for use either with a compiled binary that requires it, or it could be required at compilation time also.

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 <unistd.h>
#include <readline/readline.h>
#include <readline/history.h>

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

    // Configure readline to auto-complete paths when the tab key is hit.
    rl_bind_key('\t', rl_complete);

    for(;;) {
        // 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 (NB: 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);
    }
    return 0;
}

Compilation

Further Information

http://www.boost.org/

Navigation