From 7856a20be8065cadae1fce0c7b33a95a8df8e98e Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Tue, 27 Sep 2011 07:56:26 +0200 Subject: Add readline command completion --- src/commands.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src') diff --git a/src/commands.c b/src/commands.c index 3e4e7aa..d6c12a9 100644 --- a/src/commands.c +++ b/src/commands.c @@ -86,8 +86,30 @@ cmumble_command_complete(const char *text) return found_index >= 0 ? commands[found_index].name : text; } +static char * +complete(const char *in, int n) +{ + static int index = 0, len; + const char *name; + + if (n == 0) { + index = 0; + len = strlen(in); + } + + while (commands[index].name) { + name = commands[index++].name; + if (strncmp(name, in, len) == 0) + return g_strdup(name); + } + + return NULL; +} + void cmumble_commands_init(struct cmumble_context *ctx) { ctx->commands = commands; + + rl_completion_entry_function = complete; } -- cgit