2010-11-03 16:10:12 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "linenoise.h"
|
|
|
|
|
2010-11-29 18:27:06 +00:00
|
|
|
|
|
|
|
void completion(const char *buf, linenoiseCompletions *lc) {
|
|
|
|
if (buf[0] == 'h') {
|
|
|
|
linenoiseAddCompletion(lc,"hello");
|
|
|
|
linenoiseAddCompletion(lc,"hello there");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-03 16:10:12 +00:00
|
|
|
int main(void) {
|
|
|
|
char *line;
|
|
|
|
|
2010-11-29 18:27:06 +00:00
|
|
|
linenoiseSetCompletionCallback(completion);
|
2010-11-03 16:10:12 +00:00
|
|
|
linenoiseHistoryLoad("history.txt"); /* Load the history at startup */
|
|
|
|
while((line = linenoise("hello> ")) != NULL) {
|
|
|
|
if (line[0] != '\0') {
|
|
|
|
printf("echo: '%s'\n", line);
|
|
|
|
linenoiseHistoryAdd(line);
|
|
|
|
linenoiseHistorySave("history.txt"); /* Save every new entry */
|
|
|
|
}
|
|
|
|
free(line);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|