]> git.lizzy.rs Git - linenoise.git/blobdiff - linenoise.c
linenoise: Allow a completion callback user parameter
[linenoise.git] / linenoise.c
index e6f01bc707712dd76f683199ad2b878412ae5d4c..de4f58dcda70c800459de510f96f75779b744e2f 100644 (file)
@@ -1063,6 +1063,7 @@ static int insert_chars(struct current *current, int pos, const char *chars)
 
 #ifndef NO_COMPLETION
 static linenoiseCompletionCallback *completionCallback = NULL;
+static void *completionUserdata = NULL;
 
 static void beep() {
 #ifdef USE_TERMIOS
@@ -1082,7 +1083,7 @@ static int completeLine(struct current *current) {
     linenoiseCompletions lc = { 0, NULL };
     int c = 0;
 
-    completionCallback(current->buf,&lc);
+    completionCallback(current->buf,&lc,completionUserdata);
     if (lc.len == 0) {
         beep();
     } else {
@@ -1135,9 +1136,10 @@ static int completeLine(struct current *current) {
 /* Register a callback function to be called for tab-completion.
    Returns the prior callback so that the caller may (if needed)
    restore it when done. */
-linenoiseCompletionCallback * linenoiseSetCompletionCallback(linenoiseCompletionCallback *fn) {
+linenoiseCompletionCallback * linenoiseSetCompletionCallback(linenoiseCompletionCallback *fn, void *userdata) {
     linenoiseCompletionCallback * old = completionCallback;
     completionCallback = fn;
+    completionUserdata = userdata;
     return old;
 }