]> git.lizzy.rs Git - linenoise.git/blob - example.c
Merge pull request #3 from andreas-kupries/void-cast-clarification
[linenoise.git] / example.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "linenoise.h"
4
5 #ifndef NO_COMPLETION
6 void completion(const char *buf, linenoiseCompletions *lc) {
7     if (buf[0] == 'h') {
8         linenoiseAddCompletion(lc,"hello");
9         linenoiseAddCompletion(lc,"hello there");
10     }
11 }
12 #endif
13
14 int main(void) {
15     char *line;
16
17 #ifndef NO_COMPLETION
18     linenoiseSetCompletionCallback(completion);
19 #endif
20     linenoiseHistoryLoad("history.txt"); /* Load the history at startup */
21     while((line = linenoise("hello> ")) != NULL) {
22         if (line[0] != '\0') {
23             printf("echo: '%s'\n", line);
24             linenoiseHistoryAdd(line);
25             linenoiseHistorySave("history.txt"); /* Save every new entry */
26         }
27         free(line);
28     }
29     return 0;
30 }