]> git.lizzy.rs Git - linenoise.git/blobdiff - example.c
Support more HOME/END escape sequences
[linenoise.git] / example.c
index b3f9e9e3517fce46a3a3719b7b3be85e69e4034a..cb51a0af8f9259eca7504261e63bb35627f3cc5c 100644 (file)
--- a/example.c
+++ b/example.c
@@ -2,9 +2,21 @@
 #include <stdlib.h>
 #include "linenoise.h"
 
+#ifndef NO_COMPLETION
+void completion(const char *buf, linenoiseCompletions *lc) {
+    if (buf[0] == 'h') {
+        linenoiseAddCompletion(lc,"hello");
+        linenoiseAddCompletion(lc,"hello there");
+    }
+}
+#endif
+
 int main(void) {
     char *line;
 
+#ifndef NO_COMPLETION
+    linenoiseSetCompletionCallback(completion);
+#endif
     linenoiseHistoryLoad("history.txt"); /* Load the history at startup */
     while((line = linenoise("hello> ")) != NULL) {
         if (line[0] != '\0') {