GNU Readline - Sample Code

Sample Code

The following code is in C :

#include #include #include #include #include int main { char* input, shell_prompt; // 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 (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); } }

Read more about this topic:  GNU Readline

Famous quotes containing the words sample and/or code:

    The present war having so long cut off all communication with Great-Britain, we are not able to make a fair estimate of the state of science in that country. The spirit in which she wages war is the only sample before our eyes, and that does not seem the legitimate offspring either of science or of civilization.
    Thomas Jefferson (1743–1826)

    ... the self respect of individuals ought to make them demand of their leaders conformity with an agreed-upon code of ethics and moral conduct.
    Mary Barnett Gilson (1877–?)