#include "linenoise.h"
#ifndef NO_COMPLETION
-void completion(const char *buf, linenoiseCompletions *lc) {
+void completion(const char *buf, linenoiseCompletions *lc, void *userdata) {
if (buf[0] == 'h') {
linenoiseAddCompletion(lc,"hello");
linenoiseAddCompletion(lc,"hello there");
#ifndef NO_COMPLETION
/* Set the completion callback. This will be called every time the
* user uses the <tab> key. */
- linenoiseSetCompletionCallback(completion);
+ linenoiseSetCompletionCallback(completion, NULL);
#endif
/* Load history from file. The history file is just a plain text file
#ifndef NO_COMPLETION
static linenoiseCompletionCallback *completionCallback = NULL;
+static void *completionUserdata = NULL;
static void beep() {
#ifdef USE_TERMIOS
linenoiseCompletions lc = { 0, NULL };
int c = 0;
- completionCallback(current->buf,&lc);
+ completionCallback(current->buf,&lc,completionUserdata);
if (lc.len == 0) {
beep();
} else {
/* 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;
}
/*
* The callback type for tab completion handlers.
*/
-typedef void(linenoiseCompletionCallback)(const char *, linenoiseCompletions *);
+typedef void(linenoiseCompletionCallback)(const char *prefix, linenoiseCompletions *comp, void *userdata);
/*
* Sets the current tab completion handler and returns the previous one, or NULL
* if no prior one has been set.
*/
-linenoiseCompletionCallback * linenoiseSetCompletionCallback(linenoiseCompletionCallback *);
+linenoiseCompletionCallback * linenoiseSetCompletionCallback(linenoiseCompletionCallback *comp, void *userdata);
/*
* Adds a copy of the given string to the given completion list. The copy is owned
* by the linenoiseCompletions object.
*/
-void linenoiseAddCompletion(linenoiseCompletions *, const char *);
+void linenoiseAddCompletion(linenoiseCompletions *comp, const char *str);
#endif
/*