]> git.saurik.com Git - redis.git/blame - deps/linenoise/example.c
redis-cli commands description in help.h updated.
[redis.git] / deps / linenoise / example.c
CommitLineData
e902b579
PN
1#include <stdio.h>
2#include <stdlib.h>
3#include "linenoise.h"
4
ff405818
PN
5
6void completion(const char *buf, linenoiseCompletions *lc) {
7 if (buf[0] == 'h') {
8 linenoiseAddCompletion(lc,"hello");
9 linenoiseAddCompletion(lc,"hello there");
10 }
11}
12
e902b579
PN
13int main(void) {
14 char *line;
15
ff405818 16 linenoiseSetCompletionCallback(completion);
e902b579
PN
17 linenoiseHistoryLoad("history.txt"); /* Load the history at startup */
18 while((line = linenoise("hello> ")) != NULL) {
19 if (line[0] != '\0') {
20 printf("echo: '%s'\n", line);
21 linenoiseHistoryAdd(line);
22 linenoiseHistorySave("history.txt"); /* Save every new entry */
23 }
24 free(line);
25 }
26 return 0;
27}